2016-04-07 10:58:03 +02:00
< ? php
/**
* crontab
* 0 22 * * * / home / scores / batch / scripts / rapportsTextes . php - d >> / home / scores / batch / shared / sources / log / rapportsTextesWeb . log
* 0 23 * * * / home / scores / batch / scripts / rapportsTextes . php - f >> / home / scores / batch / shared / sources / log / rapportsTextesFtp . log
*/
error_reporting ( E_ALL & ~ E_STRICT & ~ E_NOTICE & ~ E_WARNING & ~ E_DEPRECATED );
ini_set ( 'auto_detect_line_endings' , true );
// --- Define path to application directory
defined ( 'APPLICATION_PATH' )
|| define ( 'APPLICATION_PATH' , realpath ( __DIR__ . '/../application' ));
// --- Define application environment
defined ( 'APPLICATION_ENV' )
|| define ( 'APPLICATION_ENV' , ( getenv ( 'APPLICATION_ENV' ) ? getenv ( 'APPLICATION_ENV' ) : 'production' ));
// --- Composer autoload
require_once realpath ( __DIR__ . '/../vendor/autoload.php' );
// --- Create application, bootstrap, and run
$application = new Zend_Application ( APPLICATION_ENV , APPLICATION_PATH . '/configs/application.ini' );
$c = new Zend_Config ( $application -> getOptions ());
// Stockage Client => SD
$pathClientSend = '/home/scores/batch/shared/clients/fransbonhomme/send' ;
// Stockage SD => Client
$pathClientRecv = '/home/scores/batch/shared/clients/fransbonhomme/recv' ;
2016-04-11 16:32:24 +02:00
// --- Options
$displayUsage = false ;
2016-04-07 10:58:03 +02:00
try {
$opts = new Zend_Console_Getopt ( array (
'help|?' => " Displays usage information. " ,
'site-s' => " Rapports relatifs aux indiscore 2 et 3 de la journée courante ou depuis le SSAAMMJJ inclus " ,
'ftp-s' => " Traitement des demandes par ftp " ,
'file=s' => " Spécification du fichier de demande " ,
'verbose|v' => " Mode bavard ou debug " ,
));
$opts -> parse ();
} catch ( Zend_Console_Getopt_Exception $e ) {
2016-04-11 16:32:24 +02:00
$displayUsage = true ;
}
// --- Aide / Options
if ( count ( $opts -> getOptions ()) == 0 || isset ( $opts -> help )) {
$displayUsage = true ;
2016-04-07 10:58:03 +02:00
}
2016-04-11 16:32:24 +02:00
// --- Usage
if ( $displayUsage ) {
2016-04-07 10:58:03 +02:00
echo " \n " . " Spécifique FransBonhomme : rapports textes suite à demande fichier. " . " \n \n " ;
echo $opts -> getUsageMessage ();
exit ;
}
2013-06-20 08:21:23 +00:00
$db = Zend_Db :: factory ( $c -> profil -> db -> metier );
2016-04-07 10:58:03 +02:00
Zend_Db_Table :: setDefaultAdapter ( $db );
2016-05-19 20:35:27 +02:00
$execRef = new Scores_Exec_Ref ( 'RAPPORTSTEXTE' );
$execId = $execRef -> start ();
2016-04-07 10:58:03 +02:00
require_once APPLICATION_PATH . '/configs/config.php' ;
$tabCreation = array (
2013-06-20 08:21:23 +00:00
'a' => 'N/D' ,
'a1' => 'Création' ,
'a2' => 'Création suite à déménagement' ,
'a3' => 'Achat' ,
'a4' => 'Apport' ,
'a6' => 'Prise en location gérance' ,
'a7' => 'Partage' ,
'a8' => 'Reprise' ,
'aA' => 'Reprise globale de l\'exploitation agricole' ,
'aB' => 'Poursuite de l\'exploitation agricole par le conjoint' ,
'aC' => 'Transfert de propriété de l\'exploitation agricole' ,
'aD' => 'Apport d\'exploitation(s) agricole(s) individuelle(s)' ,
'aE' => 'Reprise d\'exploitation agricole individuelle' ,
2016-04-07 10:58:03 +02:00
);
$tabTypeExploitation = array (
0 => 'N/D' ,
1 => " Locataire du fond de commerce " ,
2 => " Loueur du fond de commerce " ,
3 => " Prestation de personnel " ,
10 => " Exploitation directe "
);
$tabFichLigneCmd = array ();
$modeDebug = false ;
2016-07-19 10:37:56 +02:00
$iDb = new Metier_Util_Db ();
2016-04-07 10:58:03 +02:00
$iInsee = new Metier_Insee_MInsee ( $iDb );
$message = '' ;
// --- Génération du fichier de demande depuis les logs de consultation indiscore2, indiscore3
if ( $opts -> site ) {
if ( $opts -> site === true ) {
$dateDemandes = date ( 'Ymd' );
} else {
$dateDemandes = $opts -> site ;
}
$fichierJour = 'extranet' . $dateDemandes ;
$strDates = 'AND dateHeure>=' . $dateDemandes . '000000' ;
$tabTmp = $iDb -> select (
'sdv1.logs l, sdv1.utilisateurs u' ,
'LPAD(siren,9,0) AS siren, dateHeure' ,
" l.login=u.login AND u.login<>'fransbonrapports' AND u.idClient=93 AND l.page IN ('indiscore2','indiscore3') $strDates " , false , MYSQL_ASSOC );
echo date ( 'Y/m/d H:i:s' ) . " - Nombre de rapports 1 et 2 sur l'extranet : " . count ( $tabTmp ) . " \n " ;
$strDemandes = '' ;
if ( count ( $tabTmp ) > 0 ) {
foreach ( $tabTmp as $i => $demande ) {
echo date ( 'Y/m/d H:i:s' ) . " - " . $demande [ 'siren' ] . " \n " ;
$strDemandes .= $demande [ 'siren' ] . ' ' . EOL ;
}
file_put_contents ( $pathClientSend . '/' . $fichierJour , $strDemandes );
$tabFichLigneCmd [] = $fichierJour ;
}
}
// --- Fichier de demande par FTP
if ( $opts -> ftp ) {
//client, name, depotType, depotDate, depotFile, nbLines, dateInsert, dateExecute
$fluxinM = new Application_Model_Sdv1FluxFileIn ();
// --- Auto
if ( $opts -> ftp === true ) {
// --- Detecter si la date n'est pas trop ancienne
$dateNow = new Zend_Date ();
$dateIn1 = $dateNow -> toString ( 'yyyy-MM-dd HH:mm:ss' );
2016-04-28 11:11:38 +02:00
$diff = $dateNow -> sub ( 48 , Zend_Date :: HOUR );
2016-04-07 10:58:03 +02:00
$dateIn2 = $diff -> toString ( 'yyyy-MM-dd HH:mm:ss' );
2016-04-28 11:11:38 +02:00
echo " Selection de fichier non traité entre $dateIn2 et $dateIn1\n " ;
2016-04-07 10:58:03 +02:00
$sql = $fluxinM -> select ()
-> where ( 'client=?' , 'fransbonhomme' )
-> where ( 'name=?' , 'RAPPORT' )
-> where ( 'depotType=?' , 'FTP' )
-> where ( 'dateExecute=?' , '0000-00-00 00:00:00' )
-> where ( " dateInsert BETWEEN ' " . $dateIn2 . " ' AND ' " . $dateIn1 . " ' " )
-> order ( 'dateInsert DESC' );
$pitems = $fluxinM -> fetchAll ( $sql );
if ( $pitems -> count () == 0 ) {
2016-05-23 14:58:19 +02:00
echo date ( 'Y-m-d H:i:s' ) . " : Aucun traitement à réaliser. \n " ;
} else {
foreach ( $pitems as $p ) {
$tabFichLigneCmd [] = $p -> depotFile ;
}
2016-04-07 10:58:03 +02:00
}
}
// --- Manuel
else {
$sql = $fluxinM -> select ()
-> where ( 'client=?' , 'fransbonhomme' )
-> where ( 'name=?' , 'RAPPORT' )
-> where ( 'depotType=?' , 'FTP' )
-> where ( 'depotFile=?' , $opts -> ftp )
-> order ( 'dateInsert DESC' );
$p = $fluxinM -> fetchRow ( $sql );
if ( $p !== null ) {
$tabFichLigneCmd [] = $p -> depotFile ;
}
}
}
// --- Fichier de demande manuel
if ( $opts -> file ) {
$tabFichLigneCmd [] = $opts -> file ;
}
// --- Traitement des fichiers en demande
if ( count ( $tabFichLigneCmd ) > 0 ) {
foreach ( $tabFichLigneCmd as $fichierIn ) {
$dateBegin = date ( 'YmdHis' );
if ( ! file_exists ( $pathClientSend . '/' . $fichierIn ) ) {
die ( " Erreur fichier ' $fichierIn ' inexistant ! \n " );
}
$dateIn = date ( " dmy " , filemtime ( $pathClientSend . '/' . $fichierIn ));
$fp = fopen ( $pathClientSend . '/' . $fichierIn , 'r' );
if ( ! $fp ) {
echo date ( 'Y-m-d H:i:s' ) . " - Impossible de lire le fichier ! " . " \n " ;
exit ;
}
// Lecture des lignes pour insertion en surveillance score
$nbLinesTotal = 0 ;
while (( $ligne = fgets ( $fp )) !== false ) {
$nbLinesTotal ++ ;
$siren = substr ( $ligne , 0 , 9 );
if ( ! $iInsee -> valideSiren ( $siren )) {
continue ;
}
$ref = substr ( $ligne , 9 , 10 );
echo " $fichierIn\t $siren\t $ref " ;
// Mise sous surveillances
if ( empty ( $ref )) {
$ref = $siren ;
}
$login = 'fransbonsurvrapports' ;
$survM = new Application_Model_JoSurveillancesSite ();
$survSql = $survM -> select () -> where ( 'source=?' , 'annonces' )
-> where ( 'login=?' , $login )
-> where ( 'siren=?' , $siren );
$survResult = $survM -> fetchRow ( $survSql );
$done = 0 ;
if ( $survResult === null ) {
$data = array (
'source' => 'annonces' ,
'login' => $login ,
'email' => 'contentieux@fransbonhomme.fr' ,
'siren' => $siren ,
'nic' => 0 ,
'ref' => $ref ,
'dateAjout' => date ( 'Y-m-d' ),
'dateSuppr' => '0000-00-00' ,
'encoursClient' => 0 ,
'rs' => '' ,
'cp' => 0 ,
'ville' => '' ,
'dateDerEnvoi' => '0000-00-00 00:00:00' ,
);
try {
$done = $survM -> insert ( $data );
} catch ( Zend_Db_Exception $e ) {}
} else {
try {
$data = array (
'ref' => $ref ,
);
$done = $survM -> update ( $data , array (
" source='annonces' " ,
" login=' " . $login . " ' " ,
2016-03-24 09:04:50 +00:00
" siren= " . $siren
2016-04-07 10:58:03 +02:00
));
} catch ( Zend_Db_Exception $e ) {}
}
echo " - Surv= " . $done ;
echo " \n " ;
if ( ! $iDb -> insert ( 'jo.scores_surveillance' , array ( 'siren' => $siren )))
{
if ( $iDb -> getLastErrorNum () == 1062 ) continue ;
die ( 'Erreur SQL #' . mysql_errno () . ':' . mysql_error () . EOL );
}
}
// --- Ecriture nombre d'entités total du fichier d'entrée
if ( $opts -> ftp ) {
$fluxinM -> update ( array ( 'nbLines' => $nbLinesTotal ), 'id=' . $p -> id );
}
2016-04-28 11:11:38 +02:00
if ( $execId !== null ) {
$execRef -> total ( $execId , $nbLinesTotal );
}
2016-04-07 10:58:03 +02:00
echo date ( 'Y/m/d H:i:s' ) . " - Nombre de lignes du fichier ' $fichierIn ' : " . $nbLinesTotal . " \n " ;
// --- Retour au début du fichier
rewind ( $fp );
// --- Génération du fichier de sortie
$fichierOut = $fichierIn . '.out' ;
echo date ( 'Y/m/d H:i:s' ) . " - Génération du fichier ' $fichierOut '... " . EOL ;
$dateOut = date ( " dmy " );
$nbLines = 0 ;
while (( $ligne = fgets ( $fp )) !== false ) {
$nbLines ++ ;
echo date ( 'Y/m/d H:i:s' ) . " - Ligne " . $nbLines . " / " . $nbLinesTotal . EOL ;
2016-04-28 11:11:38 +02:00
if ( $execId !== null ) {
$execRef -> increment ( $execId , $nbLines );
}
2016-04-07 10:58:03 +02:00
$siren = substr ( $ligne , 0 , 9 );
$ref = trim ( substr ( $ligne , 9 , 10 ));
$rapport = '' ;
//Siren valide
if ( $iInsee -> valideSiren ( $siren )) {
$tabId = $iInsee -> getIdentiteEntreprise ( $siren , 0 , 0 , false , false );
$siretOut = $tabId [ 'SiretSiege' ];
2016-07-19 11:01:23 +02:00
require_once 'Metier/Scores/MScores.php' ;
2016-04-07 10:58:03 +02:00
$tabIndiscore = calculIndiScore ( $siren , 0 , false , 2 , false );
$note = $tabIndiscore [ 'Indiscore20' ];
$encours = round ( $tabIndiscore [ 'encours' ] / 1000 ) * 1000 ;
}
// Siren Faux
else {
$siretOut = $note = $encours = 0 ;
}
$siretIn = $siren . '00000' ;
//Entete
$entete = '02' ;
2016-07-19 11:01:23 +02:00
$entete .= Metier_Util_String :: initstr ( $siretIn , 14 , '0' , ALIGN_RIGHT ); // SIRET demandé
$entete .= Metier_Util_String :: initstr ( $siretOut , 14 , '0' , ALIGN_RIGHT ); // SIRET réponse
$entete .= Metier_Util_String :: initstr ( $ref , 10 ); // Référence FransBonhomme
$entete .= Metier_Util_String :: initstr ( $dateIn , 6 , '0' , ALIGN_RIGHT ); // Date demande
$entete .= Metier_Util_String :: initstr ( $dateOut , 6 , '0' , ALIGN_RIGHT ); // Date réponse
$entete .= Metier_Util_String :: initstr ( $note , 2 , '0' , ALIGN_RIGHT ); // Note
$entete .= Metier_Util_String :: initstr ( '' , 2 ); // Filler 1
$entete .= Metier_Util_String :: initstr ( $encours , 6 , '0' , ALIGN_RIGHT ); // Encours en euros sans décimale
$entete .= Metier_Util_String :: initstr ( '00000004S et D' , 63 ); // 7x0 + 4 (code Sté) + Nom Sté RC
2016-04-07 10:58:03 +02:00
//Fin Entete;
//Rapport
if ( intval ( $siretOut ) != 0 )
{
2016-07-19 11:01:23 +02:00
$rapport = Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( ' ' . $tabId [ 'Nom' ], 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( ' ' . $tabId [ 'Nom2' ] . ' ' . $tabId [ 'Sigle' ] . ' ' . $tabId [ 'Enseigne' ], 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( ' ' . preg_replace ( '/^0+/' , '' , $tabId [ 'Adresse' ]), 50 ) .
Metier_Util_String :: initstr ( ' TEL : ' . preg_replace ( '/[^0-9]/' , '' , $tabId [ 'Tel' ]), 30 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( trim ( $tabId [ 'Adresse2' ]) <> '' )
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' ' . $tabId [ 'Adresse2' ], 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( ' ' . $tabId [ 'CP' ] . ' ' . $tabId [ 'Ville' ], 50 ) .
Metier_Util_String :: initstr ( ' FAX : ' . preg_replace ( '/[^0-9]/' , '' , $tabId [ 'Fax' ]), 30 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( $tabId [ 'PaysIso2' ] <> 'FR' )
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' ' . $tabId [ 'Pays' ], 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( trim ( $tabId [ 'Web' ]) <> '' )
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' WEB : ' . $tabId [ 'Web' ], 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( trim ( $tabId [ 'Mail' ]) <> '' )
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' MEL : ' . $tabId [ 'Mail' ], 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'SIRET : ' . substr ( $tabId [ 'SiretSiege' ], 0 , 3 ) . ' ' .
2016-04-07 10:58:03 +02:00
substr ( $tabId [ 'SiretSiege' ], 3 , 3 ) . ' ' .
substr ( $tabId [ 'SiretSiege' ], 6 , 3 ) . ' ' .
substr ( $tabId [ 'SiretSiege' ], 9 , 5 ) . ' ' .
' RCS : ' . $tabId [ 'numRC' ] . ' ' .
preg_replace ( '/^(TC |TI |TGI |TGIcc )/i' , '' , $tabId [ 'TribunalLib' ]), 80 ) . EOL ;
/** Situation Juridique **/
$dateRadiation = $tabId [ 'dateRad' ];
$situationjuridique = $tabId [ 'SituationJuridique' ];
$libSituation = '' ;
if ( in_array ( substr ( $situationjuridique , 0 , 1 ), array ( 'P' , 'R' )) )
{
if ( isset ( $dateRadiation ) && $dateRadiation != '' && $dateRadiation != '0000-00-00' ){
2016-07-19 11:01:23 +02:00
$dateRad = Metier_Util_Date :: dateT ( 'Ymd' , 'd/m/Y' , str_replace ( '-' , '' , $dateRadiation ));
2016-04-07 10:58:03 +02:00
}
if ( $situationjuridique == 'P' )
{
$libSituation .= 'En procédure collective' ;
if ( $dateRad != '' ){ $libSituation .= 'Radié du RCS le ' . $dateRad ; }
}
//Radiation
if ( $situationjuridique == 'RR' )
{
$libSituation .= 'Radié du RCS' ;
if ( $dateRad != '' ){ $libSituation .= ' le ' . $dateRad ; }
} elseif ( $situationjuridique == 'RP' ){
$libSituation .= 'Radiation publiée' ;
if ( $dateRad != '' ){ $libSituation .= ' le ' . $dateRad ; }
}
}
elseif ( $tabId [ 'EntActiveRCS' ] == 1 ) {
$libSituation .= 'Actif au RCS' ;
}
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'SITUA. JUR.: ' . $libSituation , 80 ) . EOL ; //@todo multiligne
2016-04-07 10:58:03 +02:00
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'FORME JUR. : ' . $tabId [ 'FJ' ] . ' ' . $tabId [ 'FJ_lib' ], 80 ) . EOL ; //@todo multiligne
2016-04-07 10:58:03 +02:00
if ( $tabId [ 'Capital' ] > 0 ) {
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'CAPITAL : ' . number_format ( $tabId [ 'Capital' ], 0 , '.' , ' ' ) . ' ' . $tabId [ 'CapitalDev' ], 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
}
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
$dateImm = str_replace ( '-' , '' , $tabId [ 'dateImmat' ]);
if ( substr ( $dateImm , 0 , 4 ) * 1 == 0 ) $dateImm = $tabId [ 'DateCreaEn' ];
if ( substr ( $dateImm , 0 , 4 ) * 1 == 0 ) $dateImm = $tabId [ 'DateCreaEt' ];
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'CREATION : ' . Metier_Util_Date :: dateT ( 'Ymd' , 'M Y' , $dateImm ), 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'CODE NAF : ' . $tabId [ 'NafEnt' ] . ' ' . $tabId [ 'NafEntLib' ], 80 ) . EOL ; //@todo multiligne
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'ACTIVITE : ' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
$rapport .= wordwrap ( $tabId [ 'Activite' ], 80 , EOL ) . EOL ; //@todo multiligne
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'ORIGINE DU FOND : ' . $tabCreation [ 'a' . $tabId [ 'OrigineCreation' ]], 80 ) . EOL ; //@todo multiligne
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'TYPE D\'EXPLOITATION : ' . $tabTypeExploitation [ $tabId [ 'TypeExploitation' ] * 1 ], 80 ) . EOL ; //@todo multiligne
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
$nbEts = ( $tabId [ 'NbEtab' ] * 1 ) - 1 ;
if ( $nbEts < 0 ) $nbEts = 0 ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'NOMBRE D\'ETABLISSEMENTS SECONDAIRES : ' . $nbEts , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'DIRIGEANT 1: ' . strtoupper ( $tabId [ 'dir1Titre' ]), 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( substr ( $tabId [ 'dir1DateNaiss' ], 0 , 4 ) * 1 == 0 ) $strNaiss = '' ;
2016-07-19 11:01:23 +02:00
else $strNaiss = ' né(e) le ' . Metier_Util_Date :: dateT ( 'Y-m-d' , 'd/m/Y' , $tabId [ 'dir1DateNaiss' ]);
$rapport .= Metier_Util_String :: initstr ( ' ' . $tabId [ 'dir1NomPrenom' ] . $strNaiss , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'DIRIGEANT 2: ' . strtoupper ( $tabId [ 'dir2Titre' ]), 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( substr ( $tabId [ 'dir2DateNaiss' ], 0 , 4 ) * 1 == 0 ) $strNaiss = '' ;
2016-07-19 11:01:23 +02:00
else $strNaiss = ' né(e) le ' . Metier_Util_Date :: dateT ( 'Y-m-d' , 'd/m/Y' , $tabId [ 'dir2DateNaiss' ]);
$rapport .= Metier_Util_String :: initstr ( ' ' . $tabId [ 'dir2NomPrenom' ] . $strNaiss , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'GARANTIES' , 80 ) . EOL ; /**@todo MORE*/
2016-04-07 10:58:03 +02:00
$tabBilans = $tabIndiscore [ 'tabBilan' ];
$devise = $tabBilans [ 0 ][ 'MONNAIE' ];
//print_r($tabIndiscore);die();
if (( $tabIndiscore [ 'NbBilansScore' ] * 1 ) == 0 ) {
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' Néant' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'ELEMENTS FINANCIERS' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( ' Néant' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
} else {
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' Elles sont représentées par la valeur brute au bilan' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( ' du fonds de commerce pour un montant de : ' . sprintf ( " %27s " , number_format ( $tabBilans [ 0 ][ 'AH' ], 0 , ',' , ' ' )) . " $devise " , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( ' des constructions pour un montant de : ' . sprintf ( " %27s " , number_format ( $tabBilans [ 0 ][ 'AP' ], 0 , ',' , ' ' )) . " $devise " , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( " ELEMENTS FINANCIERS (SOMMES EN $devise ) " , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( ' ' . Metier_Util_Date :: dateT ( 'Ymd' , 'd/m/Y' , $tabBilans [ 0 ][ 'DATE_CLOTURE' ])
. ' ' . Metier_Util_Date :: dateT ( 'Ymd' , 'd/m/Y' , $tabBilans [ 1 ][ 'DATE_CLOTURE' ])
. ' ' . Metier_Util_Date :: dateT ( 'Ymd' , 'd/m/Y' , $tabBilans [ 2 ][ 'DATE_CLOTURE' ]), 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( ' ' . $tabBilans [ 0 ][ 'DUREE_MOIS' ] . ' mois'
2016-04-07 10:58:03 +02:00
. ' ' . $tabBilans [ 1 ][ 'DUREE_MOIS' ] . ' mois'
. ' ' . $tabBilans [ 2 ][ 'DUREE_MOIS' ] . ' mois' , 80 ) . EOL ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'CA : ' . sprintf ( " %14s " , number_format ( $tabBilans [ 0 ][ 'FL' ], 0 , ',' , ' ' ))
2016-04-07 10:58:03 +02:00
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 1 ][ 'FL' ], 0 , ',' , ' ' ))
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 2 ][ 'FL' ], 0 , ',' , ' ' )), 80 ) . EOL ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'CA EXPORT : ' . sprintf ( " %14s " , number_format ( $tabBilans [ 0 ][ 'FK' ], 0 , ',' , ' ' ))
2016-04-07 10:58:03 +02:00
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 1 ][ 'FK' ], 0 , ',' , ' ' ))
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 2 ][ 'FK' ], 0 , ',' , ' ' )), 80 ) . EOL ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'RESULTAT COURANT : ' . sprintf ( " %14s " , number_format ( $tabBilans [ 0 ][ 'GW' ], 0 , ',' , ' ' ))
2016-04-07 10:58:03 +02:00
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 1 ][ 'GW' ], 0 , ',' , ' ' ))
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 2 ][ 'GW' ], 0 , ',' , ' ' )), 80 ) . EOL ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'RESULTAT NET : ' . sprintf ( " %14s " , number_format ( $tabBilans [ 0 ][ 'HN' ], 0 , ',' , ' ' ))
2016-04-07 10:58:03 +02:00
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 1 ][ 'HN' ], 0 , ',' , ' ' ))
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 2 ][ 'HN' ], 0 , ',' , ' ' )), 80 ) . EOL ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'FONDS PROPRES : ' . sprintf ( " %14s " , number_format ( $tabBilans [ 0 ][ 'DL' ], 0 , ',' , ' ' ))
2016-04-07 10:58:03 +02:00
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 1 ][ 'DL' ], 0 , ',' , ' ' ))
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 2 ][ 'DL' ], 0 , ',' , ' ' )), 80 ) . EOL ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'FRAIS FINANCIERS : ' . sprintf ( " %14s " , number_format ( $tabBilans [ 0 ][ 'GU' ], 0 , ',' , ' ' ))
2016-04-07 10:58:03 +02:00
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 1 ][ 'GU' ], 0 , ',' , ' ' ))
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 2 ][ 'GU' ], 0 , ',' , ' ' )), 80 ) . EOL ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'TOTAL DETTES : ' . sprintf ( " %14s " , number_format ( $tabBilans [ 0 ][ 'EC' ], 0 , ',' , ' ' ))
2016-04-07 10:58:03 +02:00
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 1 ][ 'EC' ], 0 , ',' , ' ' ))
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 2 ][ 'EC' ], 0 , ',' , ' ' )), 80 ) . EOL ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( 'EFFECTIFS : ' . sprintf ( " %14s " , number_format ( $tabBilans [ 0 ][ 'YP' ], 0 , ',' , ' ' ))
2016-04-07 10:58:03 +02:00
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 1 ][ 'YP' ], 0 , ',' , ' ' ))
. ' ' . sprintf ( " %14s " , number_format ( $tabBilans [ 2 ][ 'YP' ], 0 , ',' , ' ' )), 80 ) . EOL ;
}
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'PARTENAIRES FINANCIERS' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
$mBanque = new Metier_Partenaires_MBanques ( $iDb );
$tabBanque = $mBanque -> getListeBanques ( $siren );
if ( count ( $tabBanque ) == 0 ) {
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' Aucun partenaire n\'est référencé dans notre base.' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
} else {
foreach ( $tabBanque as $i => $lien ) {
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' ' . $lien [ 'libBanque' ], 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( $i >= 3 ) break ;
}
}
/** § ANNONCES **/
$bodc = false ;
$nbAnn = 0 ;
$tabAnn = $iInsee -> getAnnoncesLegales ( $siren );
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'ANNONCES LEGALES' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( count ( $tabAnn ) > 0 ) {
foreach ( $tabAnn as $i => $depot ) {
2016-07-19 11:01:23 +02:00
$annDate = Metier_Util_Date :: dateT ( 'Y-m-d' , 'd/m/Y' , $depot [ 'DateParution' ]);
2016-04-07 10:58:03 +02:00
foreach ( $depot [ 'evenements' ] as $even ) {
$annEve = $even [ 'CodeEven' ];
if ( $annEve >= 3000 && $annEve < 4000 ) {
if ( $bodc ) continue ;
$bodc = true ;
}
$annLib = $even [ 'LibEven' ];
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( " $annDate $annLib " , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
$annDate = ' ' ;
}
$nbAnn ++ ;
if ( $nbAnn >= 6 ) break ;
}
} else
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' Aucune annonce pour cette entreprise.' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
/** § dirigeance **/
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'DIRIGEANCE' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
/** § Liens **/
$mLiens = new SdMetier_Liens_Base ( $siren , 'siren' );
$tabAct = $tabPar = array ();
try {
$tabAct = $mLiens -> getActionnaires ();
} catch ( Exception $e ) {}
try {
$tabPart = $mLiens -> getParticipations ();
} catch ( Exception $e ) {}
if ( count ( $tabAct ) == 0 && count ( $tabPart ) == 0 )
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' A notre connaissance, l\'entreprise est indépendante.' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
else {
foreach ( $tabAct as $i => $lien ) {
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' ACTIONNAIRE à ' . $lien -> PDetention . ' % : ' . $lien -> RS . ' (' . $lien -> siren . ')' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( $i >= 3 ) break ;
}
foreach ( $tabPart as $i => $lien ) {
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( ' FILIALE à ' . $lien -> PDetention . ' % : ' . $lien -> RS . ' (' . $lien -> siren . ')' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
if ( $i >= 3 ) break ;
}
}
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
/** § commentaires **/
$nbLiP = $nbLiM = 0 ;
$startLi = false ;
$startPaiement = 0 ;
foreach ( $tabIndiscore [ 'tabCommentaires' ] as $i => $txt ) {
if ( $i == 5000 ) continue ;
if ( $i == 10001000 || $startPaiement == 1 ) {
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
$startPaiement ++ ;
} else {
$startPaiement = 0 ;
}
if ( $i == 10000700 || $i == 10000800 ) {
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
$startLi = true ;
} else {
$startLi = false ;
}
$ligneLi = false ;
if ( preg_match ( '/LI\+/i' , $txt )) { $ligneLi = true ; $nbLiP ++ ; }
elseif ( preg_match ( '/LI\-/i' , $txt )) { $ligneLi = true ; $nbLiM ++ ; }
if ( ! $startLi && ! $ligneLi && $startPaiement == 0 ) {
continue ;
}
//Plus de 5 LI, on arrete
if ( ( $nbLiP > 5 && $ligneLiP ) || ( $nbLiM > 5 && $ligneLiM ) ) {
continue ;
}
//echo "Ligne : $i => $txt\n";
/* $txt = strtr ( $txt , array (
'<LI+>' => '+' ,
'<LI->' => '-' ,
' ' => ' ' ,
'€' => 'E' ,
'€' => 'E' ,
chr ( 160 ) => ' ' ,
)); */
//$txt = str_replace(array('<LI+>','<LI->',' ','€','€',chr(160)), array('+','-',' ','E','E',' '), $txt);
$txt = str_replace ( array ( '<LI+>' , '<LI->' , '€' ), array ( '+' , '-' , 'E' ), $txt );
//echo ".=> $txt\n";
$txt = html_entity_decode ( $txt , ENT_QUOTES , 'UTF-8' );
//echo ".=> $txt\n";
$txt = wordwrap ( strip_tags ( $txt ), 80 , EOL ) . EOL ;
//echo ".=> $txt\n";
$rapport .= $txt ;
}
/** § scoring **/
if ( $tabIndiscore [ 'Indiscore20' ] == 0 ) $strTendance = '' ;
else $strTendance = ' (Tendance ' . $tabIndiscore [ 'TendanceIndiscore' ] . ')' ;
2016-07-19 11:01:23 +02:00
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'COTATION INDISCORE : ' . $tabIndiscore [ 'Indiscore20' ] . '/20 ' . $strTendance , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( 'LIMITE DE CREDIT : ' . ( round ( $tabIndiscore [ 'encours' ] / 1000 ) * 1000 ) . ' EUR' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
$rapport .= Metier_Util_String :: initstr ( '' , 80 ) . EOL ;
2016-04-07 10:58:03 +02:00
$rapport = utf8_decode ( $rapport );
} //Fin rapport
// --- Ecriture ligne dans le fichier
file_put_contents ( $pathClientRecv . '/' . $fichierOut , $entete . EOL . $rapport , FILE_APPEND );
// --- Insertion log de facturation
if ( $opts -> ftp !== null || $opts -> file !== null ) {
$logsM = new Application_Model_Sdv1Logs ();
try {
$logsM -> insert ( array (
'login' => 'fransbonrapports' ,
'page' => 'indiscore3' ,
'siren' => $siren ,
'nic' => substr ( $siretOut , 9 , 5 ),
'params' => '' ,
2014-11-12 10:06:54 +00:00
'dateHeure' => date ( 'YmdHis' )
2016-04-07 10:58:03 +02:00
));
} catch ( Zend_Db_Exception $e ) {
echo date ( 'Y/m/d H:i:s' ) . " Impossible d'enregistrer le log $siren : " . $e -> getMessage () . " \n " ;
}
}
} // Fin de lecture des lignes du fichier
2016-04-28 11:11:38 +02:00
// Surcharge du nom du fichier pour les traitements manuel
if ( $opts -> file || substr ( $fichierIn , 0 , 7 ) == 'demMail' ) {
2016-04-07 10:58:03 +02:00
$newname = preg_replace ( '/[0-9]{8}/' , date ( 'Ymd' ), basename ( $fichierOut , '.out' ));
if ( rename ( $pathClientRecv . '/' . $fichierOut , $pathClientRecv . '/' . $newname . '.out' ) === true ) {
$fichierOut = $newname . '.out' ;
}
}
2016-04-28 11:11:38 +02:00
// Ecriture dans la table des prestations
2016-04-07 10:58:03 +02:00
$fluxoutM = new Application_Model_Sdv1FluxFileOut ();
$dateEnd = date ( 'YmdHis' );
$fluxoutM -> insert ( array (
'client' => 'fransbonhomme' ,
'name' => 'RAPPORT' ,
'nbLines' => $nbLines ,
'dateBegin' => $dateBegin ,
'dateEnd' => $dateEnd ,
'fileOut' => $fichierOut ,
'depotType' => 'FTP' ,
'depotDate' => '0000-00-00 00:00:00' ,
));
if ( $opts -> ftp ) {
// -- Ecriture date d'exectution
$fluxinM -> update ( array ( 'dateExecute' => $dateEnd ), 'id=' . $p -> id );
}
}
} // Fin de lecture des fichiers de demande
else {
echo date ( 'Y/m/d H:i:s' ) . " Aucun fichier à traiter ! \n " ;
}
2016-05-20 09:16:39 +02:00
if ( $execId !== null ) {
$execRef -> end ( $execId );
}
2016-04-07 10:58:03 +02:00
echo date ( 'Y/m/d H:i:s' ) . " - Fin du traitement ! \n " ;