2012-10-16 07:44:31 +00:00
#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
< ? php
//error_reporting(E_ALL & ~E_NOTICE);
function wsLog ( $service , $siret = '' , $ref = '' ) {}
function number_format2 ( $nombre , $decimales , $sepDec , $sepMil , $unite = '' , $signe = '' ) {
if ( round ( $nombre , $decimales ) == round ( $nombre )) $decimales = 0 ;
if ( $signe == '+' ) {
if ( $nombre > 0 )
return trim ( '+ ' . number_format ( abs ( $nombre ), $decimales , $sepDec , $sepMil ) . ' ' . $unite );
elseif ( $nombre < 0 )
return trim ( '- ' . number_format ( abs ( $nombre ), $decimales , $sepDec , $sepMil ) . ' ' . $unite );
else
return trim ( number_format ( abs ( $nombre ), $decimales , $sepDec , $sepMil ) . ' ' . $unite );
} elseif ( $signe == '!' ) return trim ( number_format ( abs ( $nombre ), $decimales , $sepDec , $sepMil ) . ' ' . $unite );
else return trim ( number_format ( $nombre , $decimales , $sepDec , $sepMil ) . ' ' . $unite );
}
define ( 'DATE_HEURE_SCRIPT' , date ( 'Ymd_His' ));
2013-06-19 08:24:49 +00:00
$libTypeBilan = array ( 'N' => 'R<> el Normal (2050)' ,
'S' => 'R<> el Simplifi<66> (2033)' ,
'C' => 'Comptes Consolid<69> s' ,
2012-10-16 07:44:31 +00:00
'A' => 'Bilan de Cie d\'Assurance' ,
'B' => 'Bilan de Banque' ,
);
/** @ todo
**/
include_once ( FWK_PATH . 'common/chiffres.php' );
include_once ( FWK_PATH . 'common/dates.php' );
include_once ( INCLUDE_PATH . 'bodacc/classMBodacc.php' );
include_once ( INCLUDE_PATH . 'insee/classMInsee.php' );
include_once ( INCLUDE_PATH . 'partenaires/classMBilans.php' );
//include_once('/var/www/html/ws/WsEntreprise.php');
include_once ( FWK_PATH . 'mail/sendMail.php' );
$repProduction = '/mnt/samba/partage/production/' ;
$modeTest = $envoiGroupe = $envoiGroupePre = false ;
$ignoreDateDerExec = $retroActivite = false ;
$tableSurveillance = 'surveillances_site' ;
//$modeTest=true;
$strInfoScript = 'Usage : ' . basename ( $argv [ 0 ]) . " [OPTION]
Envoi des messages de surveillance Bilan par email ( site et WS uniquement ) .
Options :
2013-06-19 08:24:49 +00:00
- i Ne pas ex<EFBFBD> cuter en r<EFBFBD> el ( pas de MAJ des infos d ' ex<EFBFBD> cution et envoi des mails <EFBFBD> lenaoury @ gmail . com ... )
2012-10-16 07:44:31 +00:00
" ;
$argv = $_SERVER [ 'argv' ];
if ( $_SERVER [ 'argc' ] > 1 )
{
for ( $i = 1 ; isset ( $argv [ $i ]); $i ++ ) {
if ( substr ( $argv [ $i ], 0 , 1 ) == '-' ) {
switch ( substr ( $argv [ $i ], 1 , 1 )) {
case 'i' :
//$envoiGroupe=true;
$modeTest = true ;
$tableSurveillance = 'surveillances_site_old' ;
break ;
case '-' :
case '?' :
die ( $strInfoScript );
break ;
default :
die ( 'Option ' . $argv [ $i ] . " inconnue ! \n " );
break ;
}
}
}
}
$iDb = new WDB ( 'jo' );
$iDb2 = new WDB ( 'sdv1' );
//$iWs=new WsEntreprise();
$mBil = new MBilans ( 0 );
$nbUtilisateurs = $iDb2 -> select ( 'utilisateurs u, clients c' , 'u.id, u.idClient, LOWER(u.login) AS login, u.password, u.email, u.formatMail, u.lienExtranetMail, u.listeEven' , " u.idClient=c.id AND u.actif=1 AND u.deleted=0 AND c.actif='Oui' " , true , MYSQL_ASSOC , true );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d - H:i:s' ) . " - Il y a $nbUtilisateurs utilisateurs habilit<69> s <20> recevoir des surveillances... " . EOL ;
2012-10-16 07:44:31 +00:00
$tabFormat = $tabLienEx = $tabLstEve = $tabHash = array ();
while ( $uti = $iDb2 -> fetch ( MYSQL_ASSOC )) {
switch ( $uti [ 'formatMail' ]) {
case 'txt2' : // MAIL au format texte, 1 mail par envoi
case 'csv' : // MAIL au format CSV, 1 mail par envoi
2013-06-19 08:24:49 +00:00
case 'txt1' : // MAIL au format texte, 1 mail par annonce (format par d<> faut)
2012-10-16 07:44:31 +00:00
case 'pdf1' : // MAIL au format PDF, 1 mail par envoi
$tabFormat [ '_' . $uti [ 'login' ]] = $uti [ 'formatMail' ];
break ;
default :
$tabFormat [ '_' . $uti [ 'login' ]] = 'txt1' ;
break ;
}
$tabLienEx [ '_' . $uti [ 'login' ]] = $uti [ 'lienExtranetMail' ];
$tabLstEve [ '_' . $uti [ 'login' ]] = explode ( ';' , trim ( $uti [ 'listeEven' ]));
sort ( $tabLstEve [ '_' . $uti [ 'login' ]]);
if ( count ( $tabLstEve [ '_' . $uti [ 'login' ]]) == 1 && $tabLstEve [ '_' . $uti [ 'login' ]][ 0 ] == '' )
$tabLstEve [ '_' . $uti [ 'login' ]] = array ();
$tabHash [ '_' . $uti [ 'login' ]] = md5 ( $uti [ 'login' ] . '|' . $uti [ 'password' ]);
}
//sort($tabFormat);
//print_r($tabFormat);die();
$iBodacc = new MBodacc ();
$iInsee = new MInsee ();
global $tva , $tabFormules , $mBil , $tabBilan , $efftr ;
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d - H:i:s' ) . " - D<> but du traitement d'envoi des surveillances Bilans. \n " ;
2012-10-16 07:44:31 +00:00
$message = $strIdAnn = '' ;
$queryParisot = " (SELECT DATE(MAX(dateDerEnvoi)) FROM surveillances_site WHERE source='bilans' AND `login`='parisot1') " ;
//$queryParisot='2011-06-29';
$query = "
( /** Requete SQL pour la collecte **/
SELECT b . id , b . siren , LOWER ( TRIM ( s . login )) AS login , LOWER ( TRIM ( s . email )) AS email , s . ref , s . dateAjout , s . dateDerEnvoi , 'bilans_deposes' AS source , b . dateExercice , b . dureeExercice , b . monnaie , b . chiffreAffaire , b . dateProvPartenaire , 'U' AS unite , b . dateInsert , '' AS typeBilan , '' AS postes
FROM bilans_deposes b , surveillances_site s
WHERE s . source = 'bilans' AND s . siren > 1000 AND s . siren = b . siren AND b . dateInsert > s . dateAjout AND DATE ( b . dateInsert ) > DATE ( s . dateDerEnvoi ) AND s . dateSuppr = '0000-00-00' AND ABS ( DATEDIFF ( b . dateInsert , b . dateExercice )) < 400 AND b . dateInsert > '2010-05-23 00:00:00'
GROUP BY s . login , s . email , s . siren , s . ref , b . dateExercice
ORDER BY s . login ASC , s . email ASC , s . siren ASC , s . ref ASC , b . dateExercice ASC
) UNION (
/** Requete SQL pour le Bodacc **/
SELECT b . id , b . siren , LOWER ( TRIM ( s . login )) AS login , LOWER ( TRIM ( s . email )) AS email , s . ref , s . dateAjout , s . dateDerEnvoi , 'bilans' AS source , b . dateExercice , b . dureeExercice , b . monnaie , '' AS chiffreAffaire , b . dateProvPartenaire , b . unite , b . dateInsert , b . typeBilan , b . postes
FROM bilans b , surveillances_site s
WHERE s . source = 'bilans' AND s . siren > 1000 AND s . siren = b . siren AND b . dateInsert > s . dateAjout AND DATE ( b . dateInsert ) > DATE ( s . dateDerEnvoi ) AND s . dateSuppr = '0000-00-00' AND ABS ( DATEDIFF ( b . dateInsert , b . dateExercice )) < 400 AND b . dateInsert > '2010-05-23 00:00:00'
GROUP BY s . login , s . email , s . siren , s . ref , b . dateExercice
ORDER BY s . login ASC , s . email ASC , s . siren ASC , s . ref ASC , b . dateExercice ASC
) UNION (
SELECT b . id , b . siren , LOWER ( TRIM ( s . login )) AS login , LOWER ( TRIM ( s . email )) AS email , s . ref , s . dateAjout , s . dateDerEnvoi , 'bilans' AS source , b . dateExercice , b . dureeExercice , b . monnaie , '' AS chiffreAffaire , b . dateProvPartenaire , b . unite , b . dateInsert , b . typeBilan , b . postes
FROM bilans b , surveillances_site s
WHERE s . source = 'bilans' AND s . siren > 1000 AND s . siren = b . siren AND s . login = 'parisot1' AND s . dateAjout >= $queryParisot
AND b . dateExercice = ( SELECT MAX ( b2 . dateExercice ) FROM bilans b2 WHERE b2 . siren = b . siren )
GROUP BY s . login , s . email , s . siren , s . ref
ORDER BY s . login ASC , s . email ASC , s . siren ASC , s . ref ASC , b . dateExercice DESC
) ORDER BY login ASC , email ASC , siren ASC , ref ASC , dateExercice ASC " ;
echo date ( 'Y/m/d - H:i:s' ) . " - $query ; " . EOL ;
$res = $iDb -> query ( $query );
$nbAnnonces = mysql_num_rows ( $res );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d - H:i:s' ) . " - Il y a $nbAnnonces surveillances Bilans <20> traiter... " . EOL ;
2012-10-16 07:44:31 +00:00
$emailPre = $loginPre = $sirenPre = false ;
//die();
require_once ( '/var/www/html/tests/pdf/html2pdf.class.php' );
while ( $bilan = $iDb -> fetch ( MYSQL_ASSOC )) {
// if ($emailPre==$bilan[email] && $loginPre==$bilan['login'] && $sirenPre==$bilan['siren']) continue;
$fp2 = fopen ( " /var/www/html/factures/pdf/surv_bilans_ " . date ( 'Y-m-d' ) . '.csv' , 'a' );
fwrite ( $fp2 , implode ( " \" \t \" " , $bilan ));
fclose ( $fp2 );
$tabIdentite = $iInsee -> getIdentiteLight ( $bilan [ 'siren' ]);
$email = $bilan [ 'email' ];
$loginLu = $bilan [ 'login' ];
if ( ! isset ( $tabFormat [ '_' . $loginLu ])) {
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . ' - Bilan n<> ' . $bilan [ 'id' ] . " non trait<69> e pour cause de format ind<6E> fini pour $loginLu , $email ( " . $bilan [ 'siren' ] . ' - ' . $tabIdentite [ 'Nom' ] . " ) \n " ;
/** Avant de faire un continue, on initialise les variables pr<70> c<EFBFBD> dentes obligatoires **/
2012-10-16 07:44:31 +00:00
/* $emailPre = $email ;
$loginPre = $loginLu ;
$envoiGroupePre = $envoiGroupe ;
$conversionPdfPre = $conversionPdf ;
$conversionCsvPre = $conversionCsv ; */
continue ;
}
$conversionPdf = $conversionCsv = false ;
if ( $tabFormat [ '_' . $loginLu ] == 'txt2' ) $envoiGroupe = true ;
elseif ( $tabFormat [ '_' . $loginLu ] == 'csv' ) { $envoiGroupe = true ; $conversionCsv = true ; }
elseif ( $tabFormat [ '_' . $loginLu ] == 'txt1' ) $envoiGroupe = false ;
elseif ( $tabFormat [ '_' . $loginLu ] == 'pdf1' ) { $envoiGroupe = true ; $conversionPdf = true ; }
2013-06-19 08:24:49 +00:00
else die ( date ( 'Y/m/d H:i:s' ) . " - Erreur impossible : Format ' " . $tabFormat [ '_' . $loginLu ] . " ' non g<> r<EFBFBD> pour $loginLu ! " );
2012-10-16 07:44:31 +00:00
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . ' - Bilan n<> ' . $bilan [ 'id' ] . " <20> traiter pour $loginLu , $email ( " . $bilan [ 'siren' ] . ' - ' . $tabIdentite [ 'Nom' ] . " ) \n " ;
2012-10-16 07:44:31 +00:00
/*
2013-06-19 08:24:49 +00:00
if ( count ( $tabLstEve [ '_' . $loginLu ]) > 0 ) { // L'utilisateur filtre ses <20> v<EFBFBD> nements
2012-10-16 07:44:31 +00:00
$even = $bilan [ 'insEVE' ];
switch ( $even ) {
case 'M0C' : $even2 = 0130 ; break ;
case 'M0F' : $even2 = 0430 ; break ;
case 'M0R' : $even2 = 0145 ; break ;
case 'M00' : $even2 = 07 80 ; break ;
case 'MAS' : $even2 = 0661 ; break ;
case 'MAC' : $even2 = 0661 ; break ;
case 'MSA' : $even2 = 07 80 ; break ;
case 'MPF' : $even2 = 0999 ; break ;
default : $even2 = $even * 1 ; break ;
}
$evenTrouve = false ;
if ( in_array ( $even2 , $tabLstEve [ '_' . $loginLu ]))
$evenTrouve = true ;
if ( ! $evenTrouve ) {
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . ' - Annonce n<> ' . $bilan [ 'id' ] . ' - Ev<45> nements hors p<> rim<69> tre client : ' . $even . '/' . $even2 . " \n " ;
2012-10-16 07:44:31 +00:00
if ( ! $modeTest ) {
$where = " login=' $loginLu ' AND source='score' AND siren=' " . $bilan [ 'siren' ] . " ' " ;
if ( ! $iDb -> update ( $tableSurveillance , array ( 'dateDerEnvoi' => date ( 'Ymd' ) . '235959' ), $where , true ))
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Erreur SQL " . mysql_errno () . ' : ' . mysql_error () . ' sur UPDATE pour l\'annonce n<> ' . $bilan [ 'id' ] . " , login= $loginLu , mail= $email , siren= " . $bilan [ 'siren' ] . ', rsoc=' . $tabIdentite [ 'Nom' ] . " ( $where ) ! \n " ;
2012-10-16 07:44:31 +00:00
}
2013-06-19 08:24:49 +00:00
continue ; // Aucun ev<65> nement souhait<69> par l'utilisateur n'est pr<70> sent dans cette annonce
} else echo date ( 'Y/m/d H:i:s' ) . ' - Annonce n<> ' . $bilan [ 'id' ] . " - Evenements ' $even / $even2 ' OK pour $loginLu , $email ( " . $bilan [ 'siren' ] . ' - ' . $tabIdentite [ 'Nom' ] . " ) \n " ;
} else */ echo date ( 'Y/m/d H:i:s' ) . ' - Bilan n<> ' . $bilan [ 'id' ] . " - Pas de filtre evenements pour $loginLu , $email ( " . $bilan [ 'siren' ] . ' - ' . $tabIdentite [ 'Nom' ] . " ) \n " ;
2012-10-16 07:44:31 +00:00
echo " Test $envoiGroupe vs $envoiGroupePre / Login $loginLu vs $loginPre / Email $email vs $emailPre\n " ;
//$saisie = trim(strtoupper(fgets(STDIN)));
2013-06-19 08:24:49 +00:00
if ( ( $envoiGroupe || $envoiGroupePre ) && // Envoi group<75> demand<6E> ET
( ( $loginPre != false && $loginLu != $loginPre ) || // Login diff<66> rent OU
( $emailPre != false && $email != $emailPre ) ) // Email diff<66> rent
2012-10-16 07:44:31 +00:00
) { /** Login souhaitant un seul email pour toutes les annonces **/
$emailEnvoi = $emailPre ;
if ( $modeTest ) $emailEnvoi = 'lenaoury@gmail.com' ;
if ( $conversionPdfPre ) {
$html2pdf = new HTML2PDF ( 'P' , 'A4' , 'fr' );
$messagePdf = '<page>' . str_replace ( " --------------------------------------------------------------------------- " , '</page><page>' , strtr ( $message , array ( " \r \n " => '<br/>' ))) . '</page>' ;
$html2pdf -> WriteHTML ( $messagePdf );
$content = $html2pdf -> Output ( 'annonces.pdf' , true );
$fichierPdf = " /var/www/html/factures/pdf/scores_ $loginPre " . '_' . date ( 'Y-m-d' ) . " .pdf " ;
$fp2 = fopen ( $fichierPdf , 'w' );
fwrite ( $fp2 , $content );
fclose ( $fp2 );
$tabAttached = array ( $fichierPdf );
} elseif ( $conversionCsvPre ) {
$tabAttached = array ( $fichierCsvPre );
} else
$tabAttached = array ();
if ( @ sendMail ( 'infoslegales@scores-decisions.com' , $emailEnvoi , " Surveillance Bilans " , $message , '' , $tabAttached )) {
if ( ! $modeTest ) {
if ( $envoiGroupe ) $where = " login=' $loginPre ' /*AND email=' $emailPre '*/ AND source='bilans' AND siren IN ( " . implode ( ',' , $tabSiren ) . " ) " ;
else $where = " login=' $loginPre ' /*AND email=' $emailPre '*/ AND source='bilans' AND siren=' $siren ' " ;
if ( ! $iDb -> update ( $tableSurveillance , array ( 'dateDerEnvoi' => date ( 'YmdHis' )), $where , true ))
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Erreur SQL " . mysql_errno () . ' : ' . mysql_error () . ' sur UPDATE pour l\'annonce n<> ' . $bilan [ 'id' ] . " , login= $loginPre , mail= $emailPre , siren= $siren , " . implode ( ',' , $tabSiren ) . ', rsoc=' . $tabIdentite [ 'Nom' ] . " ( $where ) ! \n " ;
2012-10-16 07:44:31 +00:00
}
2013-06-19 08:24:49 +00:00
$messageInfo = $message . " \r \n " . date ( 'Y/m/d H:i:s' ) . " - Le bilan n<> $idAnn a <20> t<EFBFBD> envoy<6F> <20> $emailPre . " ;
2012-10-16 07:44:31 +00:00
@ sendMail ( 'infoslegales@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " Surveillance Bilans " , $messageInfo , '' , $tabAttached );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Les bilans n<> $strIdAnn ont <20> t<EFBFBD> envoy<6F> es <20> $emailPre . \n " ;
2012-10-16 07:44:31 +00:00
} else {
2013-06-19 08:24:49 +00:00
$messageInfo = $message . " \r \n " . date ( 'Y/m/d H:i:s' ) . " - Le bilan n<> $idAnn n'a pas <20> t<EFBFBD> envoy<6F> <20> $emailPre !!! " ;
2012-10-16 07:44:31 +00:00
@ sendMail ( 'infoslegales@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " Surveillance Bilans - Echec Envoi ! " , $messageInfo , '' , $tabAttached );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Les bilans n<> $strIdAnn n'ont pas <20> t<EFBFBD> envoy<6F> es <20> $emailPre . \n " ;
2012-10-16 07:44:31 +00:00
}
2013-06-19 08:24:49 +00:00
// Remise <20> banc du message
2012-10-16 07:44:31 +00:00
$message = $strIdAnn = '' ;
$tabSiren = array ();
}
// GESTION DE L'ANNONCE COURANTE
$siren = $bilan [ 'siren' ];
$sirenAff = implode ( ' ' , str_split ( $siren , 3 ));
//$nicAff=$bilan['nicEven'];
$rs = substr ( $tabIdentite [ 'Nom' ], 0 , 30 ) . '...' ;
//$even=$bilan['insEVE'];
$login = $bilan [ 'login' ];
$idAnn = $bilan [ 'id' ];
if ( $envoiGroupe == false )
$message = " Siren : $sirenAff\r\n " . 'Raison Sociale : ' . $tabIdentite [ 'Nom' ] . " \r \n " ;
else {
if ( $emailPre == false && $loginPre == false ) {
2013-06-19 08:24:49 +00:00
// Premi<6D> re annonce du mail
2012-10-16 07:44:31 +00:00
$message = " Siren : $sirenAff\r\n " . 'Raison Sociale : ' . $tabIdentite [ 'Nom' ] . " \r \n " ;
$strIdAnn = " $idAnn " ;
$tabSiren = array ( $siren );
} else {
2013-06-19 08:24:49 +00:00
// Ni<4E> me annonce du mail
2012-10-16 07:44:31 +00:00
$message .= " Siren : $sirenAff\r\n " . 'Raison Sociale : ' . $tabIdentite [ 'Nom' ] . " \r \n " ;
$strIdAnn .= " $idAnn " ;
$tabSiren [] = $siren ;
}
}
if ( trim ( $bilan [ 'ref' ]) <> '' ) {
2013-06-19 08:24:49 +00:00
$message .= 'Votre r<> f<EFBFBD> rence : ' . trim ( $bilan [ 'ref' ]) . " \r \n " ;
2012-10-16 07:44:31 +00:00
$message . " \r \n " ;
$rs = substr ( $tabIdentite [ 'Nom' ], 0 , 30 ) . '... (' . trim ( $bilan [ 'ref' ]) . ')' ;
}
$dateExercice = $bilan [ 'dateExercice' ];
$unite = $bilan [ 'unite' ];
$devise = $bilan [ 'monnaie' ];
$ca = $rcai = $sin = $rn = $fp = $totb = '' ;
$typeBilan = '' ;
if ( $bilan [ 'source' ] == 'bilans_deposes' ) {
$strSource = " AND typeBilan IN ('S','N') " ;
$ca = $bilan [ 'chiffreAffaire' ];
$rcai = $rn = $fp = $totb = '' ;
} else {
$typeBilan = $bilan [ 'typeBilan' ];
$tabPostes = array ();
$tabTmp = explode ( ';' , $bilan [ 'postes' ]);
foreach ( $tabTmp as $strTmp ) {
$tabTmp2 = explode ( '=' , $strTmp );
if ( isset ( $tabTmp2 [ 1 ]))
$tabPostes [ $tabTmp2 [ 0 ]] = $tabTmp2 [ 1 ];
}
if ( $typeBilan == 'S' ) $tabPostes = $mBil -> bilanSimplifie2Normal ( $tabPostes );
if ( $typeBilan == 'S' || $typeBilan == 'N' || $typeBilan == 'C' ) {
$ca = $tabPostes [ 'FL' ]; // Chiffre d'Affaires
2013-06-19 08:24:49 +00:00
$rcai = $tabPostes [ 'GW' ]; // R<> sultat Courant avant Impot
$rn = $tabPostes [ 'HN' ]; // R<> sultat Net
2012-10-16 07:44:31 +00:00
$fp = $tabPostes [ 'DL' ]; // Situation nette Fonds propres
$totb = $tabPostes [ 'EE' ]; // Total bilan
$effb = $tabPostes [ 'YP' ]; // Effectif
} elseif ( $typeBilan == 'A' ) {
$ca = $tabPostes [ 'AR1' ]; // Primes - cotisations acquises
$sin = $tabPostes [ 'AR2' ]; // Charges des sinistres
2013-06-19 08:24:49 +00:00
$rn = $tabPostes [ 'AR4' ]; // R<> sultat Net
2012-10-16 07:44:31 +00:00
$fp = $tabPostes [ 'AP1' ]; // Situation nette Fonds propres
$totb = $tabPostes [ 'AA2' ]; // Total bilan
} elseif ( $typeBilan == 'B' ) {
2013-06-19 08:24:49 +00:00
$ca = $tabPostes [ 'BR1' ]; // Int<6E> r<EFBFBD> ts et produits assimil<69> s
$sin = $tabPostes [ 'BR2' ]; // Int<6E> r<EFBFBD> ts et charges assimil<69> es
$rn = $tabPostes [ 'BR3' ]; // R<> sultat Net
2012-10-16 07:44:31 +00:00
$fp = $tabPostes [ 'BP3' ]; // Capital souscrit (Situation nette Fonds propres)
$totb = $tabPostes [ 'BA3' ]; // Total bilan
}
if ( $typeBilan == 'S' || $typeBilan == 'N' ) $strSource = " AND typeBilan IN ('S','N') " ;
else $strSource = " AND typeBilan=' $typeBilan ' " ;
}
2013-06-19 08:24:49 +00:00
/** Informations du bilan Pr<50> c<EFBFBD> dent **/
2012-10-16 07:44:31 +00:00
$bilanPre = $iDb2 -> select ( 'jo.bilans' ,
'dateExercice, dureeExercice, monnaie, unite, typeBilan, postes' ,
" siren= $siren AND dateExercice< $dateExercice $strSource ORDER BY dateExercice DESC LIMIT 0,1 " , false , MYSQL_ASSOC );
if ( isset ( $bilanPre [ 0 ])) {
$bilanPre = $bilanPre [ 0 ];
$dateExercicePre = $bilanPre [ 'dateExercice' ];
$unitePre = $bilanPre [ 'unite' ];
$devisePre = $bilanPre [ 'monnaie' ];
$caPre = $rcaiPre = $sinPre = $rnPre = $fpPre = $totbPre = '' ;
$typeBilanPre = $bilanPre [ 'typeBilan' ];
$tabPostesPre = array ();
$tabTmp = explode ( ';' , $bilanPre [ 'postes' ]);
foreach ( $tabTmp as $strTmp ) {
$tabTmp2 = explode ( '=' , $strTmp );
if ( isset ( $tabTmp2 [ 1 ]))
$tabPostesPre [ $tabTmp2 [ 0 ]] = $tabTmp2 [ 1 ];
}
if ( $typeBilanPre == 'S' ) $typeBilanPre = $mBil -> bilanSimplifie2Normal ( $typeBilanPre );
if ( $typeBilanPre == 'S' || $typeBilanPre == 'N' || $typeBilanPre == 'C' ) {
$caPre = $tabPostesPre [ 'FL' ]; // Chiffre d'Affaires
2013-06-19 08:24:49 +00:00
$rcaiPre = $tabPostesPre [ 'GW' ]; // R<> sultat Courant avant Impot
$rnPre = $tabPostesPre [ 'HN' ]; // R<> sultat Net
2012-10-16 07:44:31 +00:00
$fpPre = $tabPostesPre [ 'DL' ]; // Situation nette Fonds propres
$totbPre = $tabPostesPre [ 'EE' ]; // Total bilan
$effbPre = $tabPostesPre [ 'YP' ]; // Effectif
} elseif ( $typeBilanPre == 'A' ) {
$caPre = $tabPostesPre [ 'AR1' ]; // Primes - cotisations acquises
$sinPre = $tabPostesPre [ 'AR2' ]; // Charges des sinistres
2013-06-19 08:24:49 +00:00
$rnPre = $tabPostesPre [ 'AR4' ]; // R<> sultat Net
2012-10-16 07:44:31 +00:00
$fpPre = $tabPostesPre [ 'AP1' ]; // Situation nette Fonds propres
$totbPre = $tabPostesPre [ 'AA2' ]; // Total bilan
} elseif ( $typeBilanPre == 'B' ) {
2013-06-19 08:24:49 +00:00
$caPre = $tabPostesPre [ 'BR1' ]; // Int<6E> r<EFBFBD> ts et produits assimil<69> s
$sinPre = $tabPostesPre [ 'BR2' ]; // Int<6E> r<EFBFBD> ts et charges assimil<69> es
$rnPre = $tabPostesPre [ 'BR3' ]; // R<> sultat Net
2012-10-16 07:44:31 +00:00
$fpPre = $tabPostesPre [ 'BP3' ]; // Capital souscrit (Situation nette Fonds propres)
$totbPre = $tabPostesPre [ 'BA3' ]; // Total bilan
}
if ( $unitePre == '' || $unitePre == 'u' || $unitePre == 'U' ) { $strDevisePre = $devisePre ; $coefPre = 1 ; }
elseif ( $unitePre == 'k' || $unitePre == 'K' ) { $strDevisePre = " K $devisePre " ; $coefPre = 1000 ; }
elseif ( $unitePre == 'm' || $unitePre == 'M' ) { $strDevisePre = " M $devisePre " ; $coefPre = 1000000 ; }
else { $strDevisePre = '' ; $coefPre = 0 ; }
if ( $bilanPre [ 'dureeExercice' ] * 1 > 0 )
2013-06-19 08:24:49 +00:00
$strDureePre = ' (dur<75> e : ' . $bilanPre [ 'dureeExercice' ] . ' mois)' ;
2012-10-16 07:44:31 +00:00
else
$strDureePre = '' ;
2013-06-19 08:24:49 +00:00
} // FIN de lecture des infos du bilan pr<70> c<EFBFBD> dent si disponible
2012-10-16 07:44:31 +00:00
2013-06-19 08:24:49 +00:00
// Unit<69> en cours
2012-10-16 07:44:31 +00:00
if ( $unite == '' || $unite == 'u' || $unite == 'U' ) { $strDevise = $devise ; $coef = 1 ; }
elseif ( $unite == 'k' || $unite == 'K' ) { $strDevise = " K $devise " ; $coef = 1000 ; }
elseif ( $unite == 'm' || $unite == 'M' ) { $strDevise = " M $devise " ; $coef = 1000000 ; }
else { $strDevise = '' ; $coef = 0 ; }
2013-06-19 08:24:49 +00:00
// Dur<75> e de l'exercice
2012-10-16 07:44:31 +00:00
if ( $bilan [ 'dureeExercice' ] * 1 > 0 )
2013-06-19 08:24:49 +00:00
$strDuree = ' (dur<75> e : ' . $bilan [ 'dureeExercice' ] . ' mois)' ;
2012-10-16 07:44:31 +00:00
else
$strDuree = '' ;
// Corps du message
$message .= 'Source : Greffe du Tribunal en date du ' . WDate :: dateT ( 'Ymd' , 'd/m/Y' , $bilan [ 'dateProvPartenaire' ]) . " \r \n " ;
2013-06-19 08:24:49 +00:00
$message .= 'Date de cl<63> ture : ' . WDate :: dateT ( 'Ymd' , 'd/m/Y' , $dateExercice ) . " $strDuree\r\n " ;
if ( $typeBilan <> '' ) $message .= 'Format d<> pos<6F> : ' . $libTypeBilan [ $typeBilan ] . " \r \n " ;
2012-10-16 07:44:31 +00:00
$message .= " \r \n " ;
2013-06-19 08:24:49 +00:00
$message .= " Adresse du si<73> ge : " . $tabIdentite [ 'Adresse' ] . ', ' . $tabIdentite [ 'CP' ] . ' ' . $tabIdentite [ 'Ville' ] . " \r \n " ;
2012-10-16 07:44:31 +00:00
$message .= " Forme juridique : " . $tabIdentite [ 'FJ_lib' ] . ' (' . $tabIdentite [ 'FJ' ] . " ) \r \n " ;
2013-06-19 08:24:49 +00:00
$message .= " Activit<EFBFBD> de l'entreprise : " . $tabIdentite [ 'NafEntLib' ] . ' (' . $tabIdentite [ 'NafEnt' ] . " ) \r \n " ;
2012-10-16 07:44:31 +00:00
$message .= " \r \n " ;
$message .= " ELEMENTS FINANCIERS : \r \n " ;
if ( $typeBilan == 'A' ) {
$message .= 'Primes et Cotisations .. ' . sprintf ( " %13s " , number_format ( $ca , 0 , '' , ' ' )) . " $strDevise\r\n " ;
$message .= 'Charge des sinistres ... ' . sprintf ( " %13s " , number_format ( $sin , 0 , '' , ' ' )) . " $strDevise\r\n " ;
} elseif ( $typeBilan == 'B' ) {
2013-06-19 08:24:49 +00:00
$message .= 'Int<6E> r<EFBFBD> ts et produits ... ' . sprintf ( " %13s " , number_format ( $ca , 0 , '' , ' ' )) . " $strDevise\r\n " ;
$message .= 'Int<6E> r<EFBFBD> ts et charges .... ' . sprintf ( " %13s " , number_format ( $sin , 0 , '' , ' ' )) . " $strDevise\r\n " ;
2012-10-16 07:44:31 +00:00
} else $message .= 'Chiffre d\'affaires ..... ' . sprintf ( " %13s " , number_format ( $ca , 0 , '' , ' ' )) . " $strDevise " ;
if ( $ca <> '' && $caPre <> '' ) {
$evol = ((( $ca * $coef ) - ( $caPre * $coefPre )) * 100 ) / abs ( $caPre * $coefPre );
if ( $evol <> 0 )
$message .= ' (' . number_format2 ( $evol , 2 , ',' , ' ' , '%' , '+' ) . ' par rapport au ' . WDate :: dateT ( 'Ymd' , 'd/m/Y' , $dateExercicePre ) . ')' ;
}
$message .= " \r \n " ;
2013-06-19 08:24:49 +00:00
// R<> sultat Net
if ( $rn <> '' ) $message .= 'R<> sultat Net ........... ' . sprintf ( " %13s " , number_format ( $rn , 0 , '' , ' ' )) . " $strDevise " ;
2012-10-16 07:44:31 +00:00
if ( $rn <> '' && $rnPre <> '' ) {
$evol = ((( $rn * $coef ) - ( $rnPre * $coefPre )) * 100 ) / abs ( $rnPre * $coefPre );
$message .= ' (' . number_format2 ( $evol , 2 , ',' , ' ' , '%' , '+' ) . " ) \r \n " ;
} elseif ( $rn <> '' ) $message .= " \r \n " ;
// Fonds Propres
if ( $fp <> '' ) $message .= 'Fonds propres .......... ' . sprintf ( " %13s " , number_format ( $fp , 0 , '' , ' ' )) . " $strDevise " ;
if ( $fp <> '' && $fpPre <> '' ) {
$evol = ((( $fp * $coef ) - ( $fpPre * $coefPre )) * 100 ) / abs ( $fpPre * $coefPre );
$message .= ' (' . number_format2 ( $evol , 2 , ',' , ' ' , '%' , '+' ) . " ) \r \n " ;
} elseif ( $fp <> '' ) $message .= " \r \n " ;
// Total Bilan
if ( $totb <> '' ) $message .= 'Total bilan ............ ' . sprintf ( " %13s " , number_format ( $totb , 0 , '' , ' ' )) . " $strDevise " ;
if ( $totb <> '' && $totbPre <> '' ) {
$evol = ((( $totb * $coef ) - ( $totbPre * $coefPre )) * 100 ) / abs ( $totbPre * $coefPre );
$message .= ' (' . number_format2 ( $evol , 2 , ',' , ' ' , '%' , '+' ) . " ) \r \n " ;
} elseif ( $totb <> '' ) $message .= " \r \n " ;
// Effectif
if ( $effb <> '' ) $message .= 'Effectif bilan ......... ' . sprintf ( " %13s " , number_format ( $effb , 0 , '' , ' ' )) . " pers. " ;
if ( $effb <> '' && $effbPre <> '' ) {
$evol = (( $effb - $effbPre ) * 100 ) / abs ( $effbPre );
$message .= ' (' . number_format2 ( $evol , 1 , ',' , ' ' , '%' , '+' ) . " ) \r \n " ;
} elseif ( $effb <> '' ) $message .= " \r \n " ;
$message .= " \r \n " ;
/*
print_r ( $bilPre );
die ( $message );
*/
if ( $tabLienEx [ " _ $login " ] == 1 ) {
if ( WS_VERSION == 2 )
$url = " http://extranet.scores-decisions.com/finance/liasse/siret/ $siren " ;
else
$url = " http://extranet.scores-decisions.com/?page=liasse&action=logon&login= $login &siret= $siren &hach= " . $tabHash [ " _ $login " ];
2013-06-19 08:24:49 +00:00
$message .= " \r \n Cliquez sur le lien suivant pour une consultation directe du bilan sur le site de Scores & D<> cisions : \r \n <div style= \" font-size: 6pt \" ><a href= \" $url\ " > $url </ a ></ div > \r\n " ;//d6c3f28eda29a2072b36872476a1d37a
2012-10-16 07:44:31 +00:00
}
$message .= " \r \n \r \n --------------------------------------------------------------------------- \r \n \r \n " ;
if ( $conversionCsv ) {
$mel = substr ( md5 ( preg_replace ( '/[^a-z0-9]/i' , '' , $bilan [ 'email' ])), 0 , 8 );
$fichierCsv = '/var/www/html/factures/pdf/bilans_' . $login . '_' . $mel . '_' . DATE_HEURE_SCRIPT . '.csv' ;
$strLigneCsv = '' ;
if ( $login == 'parisot1' ) {
$strOutput = " A1;AA;BK1;BM1;BO1;BQ1;BS1;BU1;BW1;BY1;CA1;CC1;CE1;CG1;CI1;CL1;DI;DL;DL1;DW;DX;EH;FL;FM;FN;FO;FP;FQ;FS;FT;FU;FV;FW;FX;FY;FZ;GA;GB;GC;GD;GE;GQ;GV;HG;HI;HK;HN;UH;UK;VH2;VH3;VI2;YP;YS;YY;YZ;DUREE_MOIS;DATE_CLOTURE;SIREN;GM;HC " ;
$tabOutput = explode ( ';' , $strOutput );
unset ( $mBil2 );
$mBil2 = new MBilans ( $siren );
$tabBilans =@ $mBil2 -> listeBilans ();
$derBilan = current ( $tabBilans );
$p =@ $mBil2 -> getBilan ( WDate :: dateT ( 'Ymd' , 'd/m/Y' , $derBilan [ 'dateExercice' ]), $derBilan [ 'typeBilan' ]);
foreach ( $tabOutput as $poste ) {
if ( preg_match ( '/DATE/' , $poste ))
$strLigneCsv .= WDate :: dateT ( 'Ymd' , 'd/m/Y' , @ $p [ $poste ]) . ';' ;
else
$strLigneCsv .=@ $p [ $poste ] . ';' ;
}
$strLigneCsv .= " \r \n " ;
} else {
if ( ! file_exists ( $fichierCsv )) {
$fp2 = fopen ( $fichierCsv , 'a' );
2013-06-19 08:24:49 +00:00
fwrite ( $fp2 , " Siren;Id Bilan;R<> f<EFBFBD> rence;Raison Sociale;Date source;Date cl<63> ture;Dur<75> e;Devise;Format d<> pos<6F> ;NAF;CA;RCAI;SIN;RN;FP;TOTAL BILAN \r \n " );
2012-10-16 07:44:31 +00:00
fclose ( $fp2 );
}
$strLigneCsv = " $siren ; $idAnn ; " . trim ( $bilan [ 'ref' ]) . ';' . $tabIdentite [ 'Nom' ] . ';' . WDate :: dateT ( 'Ymd' , 'd/m/Y' , $bilan [ 'dateProvPartenaire' ]) . ';' .
WDate :: dateT ( 'Ymd' , 'd/m/Y' , $dateExercice ) . ';' . $bilan [ 'dureeExercice' ] . ';' . $bilan [ 'monnaie' ] . " ; $typeBilan ; " . $tabIdentite [ 'NafEnt' ] .
" ; $ca ; $rcai ; $sin ; $rn ; $fp ; $totb\r\n " ;
}
$fp2 = fopen ( $fichierCsv , 'a' );
fwrite ( $fp2 , $strLigneCsv );
fclose ( $fp2 );
}
if ( $envoiGroupe == false ) {
/** Profil souhaitant un email par annonce **/
$emailEnvoi = $email ;
if ( $modeTest ) $emailEnvoi = 'lenaoury@gmail.com' ;
//$emailEnvoi='lenaoury@gmail.com';
if ( @ sendMail ( 'infoslegales@scores-decisions.com' , $emailEnvoi , " Surveillance Bilans $sirenAff $nicAff : $rs " , $message )) {
if ( ! $modeTest ) {
if ( $envoiGroupe ) $where = " login=' $login ' AND email=' $emailPre ' AND source='bilans' AND siren IN ( " . implode ( ',' , $tabSiren ) . " ) " ;
else $where = " login=' $login ' AND email=' $email ' AND source='bilans' AND siren=' $siren ' " ;
if ( ! $iDb -> update ( $tableSurveillance , array ( 'dateDerEnvoi' => date ( 'YmdHis' )), $where , true ))
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Erreur SQL " . mysql_errno () . ' : ' . mysql_error () . ' sur UPDATE pour le bilan n<> ' . $bilan [ 'id' ] . " , login= $login , mail= $emailPre / $email , siren= $siren , " . implode ( ',' , $tabSiren ) . ', rsoc=' . $tabIdentite [ 'Nom' ] . " ( $where ) ! \n " ;
2012-10-16 07:44:31 +00:00
}
2013-06-19 08:24:49 +00:00
$messageInfo = $message . " \r \n " . date ( 'Y/m/d H:i:s' ) . " - Le bilan n<> $idAnn a <20> t<EFBFBD> envoy<6F> <20> $email . " ;
2012-10-16 07:44:31 +00:00
@ sendMail ( 'infoslegales@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " Surveillance Bilans $sirenAff $nicAff : $rs " , $messageInfo );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Le bilan n<> $idAnn a <20> t<EFBFBD> envoy<6F> <20> $email . \n " ;
2012-10-16 07:44:31 +00:00
} else {
2013-06-19 08:24:49 +00:00
$messageInfo = $message . " \r \n " . date ( 'Y/m/d H:i:s' ) . " - Le bilan n<> $idAnn n'a pas <20> t<EFBFBD> envoy<6F> <20> $email !!! " ;
2012-10-16 07:44:31 +00:00
@ sendMail ( 'infoslegales@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " Surveillance Bilans $sirenAff $nicAff : $rs - Echec Envoi ! " , $messageInfo );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Le bilan n<> $idAnn n'a pas <20> t<EFBFBD> envoy<6F> <20> $email . \n " ;
2012-10-16 07:44:31 +00:00
}
}
$emailPre = $email ;
$loginPre = $login ;
$sirenPre = $siren ;
$envoiGroupePre = $envoiGroupe ;
$conversionPdfPre = $conversionPdf ;
$conversionCsvPre = $conversionCsv ;
$fichierCsvPre = $fichierCsv ;
}
2013-06-19 08:24:49 +00:00
/** Envoi du dernier email pour les envois group<75> s **/
2012-10-16 07:44:31 +00:00
if (( $envoiGroupe || $envoiGroupePre ) && $emailPre <> false && $loginPre <> false ) {
$emailEnvoi = $emailPre ;
if ( $modeTest ) $emailEnvoi = 'lenaoury@gmail.com' ;
if ( $conversionPdf ) {
$html2pdf = new HTML2PDF ( 'P' , 'A4' , 'fr' );
$messagePdf = '<page>' . str_replace ( " --------------------------------------------------------------------------- " , '</page><page>' , strtr ( $message , array ( " \r \n " => '<br/>' ))) . '</page>' ;
$html2pdf -> WriteHTML ( $messagePdf );
$content = $html2pdf -> Output ( 'annonces.pdf' , true );
$fichierPdf = " /var/www/html/factures/pdf/scores_ $login " . '_' . date ( 'Y-m-d' ) . " .pdf " ;
$fp2 = fopen ( $fichierPdf , 'w' );
fwrite ( $fp2 , $content );
fclose ( $fp2 );
$tabAttached = array ( $fichierPdf );
} elseif ( $conversionCsv ) {
$tabAttached = array ( $fichierCsv );
} else $tabAttached = array ();
if ( @ sendMail ( 'infoslegales@scores-decisions.com' , $emailEnvoi , " Surveillance Bilans " , $message , '' , $tabAttached )) {
if ( ! $modeTest ) {
if ( $envoiGroupe ) $where = " login=' $login ' /*AND email=' $emailPre '*/ AND source='bilans' AND siren IN ( " . implode ( ',' , $tabSiren ) . " ) " ;
else $where = " login=' $login ' /*AND email=' $emailPre '*/ AND source='bilans' AND siren=' $siren ' " ;
if ( ! $iDb -> update ( $tableSurveillance , array ( 'dateDerEnvoi' => date ( 'YmdHis' )), $where , true ))
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Erreur SQL " . mysql_errno () . ' : ' . mysql_error () . ' sur UPDATE pour l\'annonce n<> ' . $bilan [ 'id' ] . " , login= $login , mail= $emailPre , siren= $siren , " . implode ( ',' , $tabSiren ) . ', rsoc=' . $tabIdentite [ 'Nom' ] . " ( $where ) ! \n " ;
2012-10-16 07:44:31 +00:00
}
2013-06-19 08:24:49 +00:00
$messageInfo = $message . " \r \n " . date ( 'Y/m/d H:i:s' ) . " - Les bilans n<> $strIdAnn ont <20> t<EFBFBD> envoy<6F> es <20> $emailPre . " ;
2012-10-16 07:44:31 +00:00
@ sendMail ( 'infoslegales@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " Surveillance Bilans " , $messageInfo , '' , $tabAttached );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Les bilans n<> $strIdAnn ont <20> t<EFBFBD> envoy<6F> es <20> $emailPre . \n " ;
2012-10-16 07:44:31 +00:00
} else {
2013-06-19 08:24:49 +00:00
$messageInfo = $message . " \r \n " . date ( 'Y/m/d H:i:s' ) . " - Le bilan n<> $idAnn n'a pas <20> t<EFBFBD> envoy<6F> <20> $emailPre !!! " ;
2012-10-16 07:44:31 +00:00
@ sendMail ( 'infoslegales@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " Surveillance Bilans - Echec Envoi ! " , $messageInfo , '' , $tabAttached );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d H:i:s' ) . " - Les bilans n<> $strIdAnn n'ont pas <20> t<EFBFBD> envoy<6F> es <20> $emailPre . \n " ;
2012-10-16 07:44:31 +00:00
}
}
echo date ( 'Y/m/d - H:i:s' ) . " - Fin du traitement d'envoi des surveillances Bilans. \n " ;
die ();
?>