PHP-CS-Fixer

This commit is contained in:
Michael RICOIS 2016-11-29 17:04:46 +01:00
parent ce9b83194a
commit 7744e97ac0

View File

@ -69,21 +69,20 @@ Options :
$nbMois = 0; $nbMois = 0;
$argv=$_SERVER['argv']; $argv=$_SERVER['argv'];
if ($_SERVER['argc']>1) if ($_SERVER['argc']>1) {
{ for ($i=1; isset($argv[$i]); $i++) {
for ($i=1; isset($argv[$i]); $i++) { if (substr($argv[$i], 0, 1)=='-') {
if (substr($argv[$i],0,1)=='-') { switch (strtolower(substr($argv[$i], 1, 1))) {
switch (strtolower(substr($argv[$i],1,1))) { case 's': $stock=true; break;
case 's': $stock=true; break; case 'r': $sirenReprise = substr($argv[$i], 3); break;
case 'r': $sirenReprise = substr($argv[$i],3); break; case 'd': $lastInsert = substr($argv[$i], 3); break;
case 'd': $lastInsert = substr($argv[$i],3); break; case 'm': $nbMois = substr($argv[$i], 3); break;
case 'm': $nbMois = substr($argv[$i],3); break; case '-':
case '-': case '?': die($strInfoScript); break;
case '?': die($strInfoScript); break; default: die('Option '. $argv[$i] . " inconnue !\n"); break;
default: die('Option '. $argv[$i] . " inconnue !\n"); break; }
} }
} }
}
} }
//=> Start //=> Start
@ -101,44 +100,44 @@ if ($stock) {
$unitTotal = count($result); $unitTotal = count($result);
} else { } else {
// --- Dernière execution // --- Dernière execution
if ($lastInsert) { if ($lastInsert) {
$lastInsert = Metier_Util_Date::dateT('Ymd','Y-m-d',$lastInsert); $lastInsert = Metier_Util_Date::dateT('Ymd', 'Y-m-d', $lastInsert);
} else { } else {
$sql = $db->select()->from('bilans_postes', array(new Zend_Db_Expr('MAX(dateInsert) AS lastInsert')), 'jo'); $sql = $db->select()->from('bilans_postes', array(new Zend_Db_Expr('MAX(dateInsert) AS lastInsert')), 'jo');
$result = $db->fetchRow($sql, null, Zend_Db::FETCH_ASSOC); $result = $db->fetchRow($sql, null, Zend_Db::FETCH_ASSOC);
$lastInsert = $result['lastInsert']; $lastInsert = $result['lastInsert'];
} }
echo date('Y/m/d - H:i:s') ." - Derniere MAJ des postes des bilans : $lastInsert\n"; echo date('Y/m/d - H:i:s') ." - Derniere MAJ des postes des bilans : $lastInsert\n";
// --- Date Interval // --- Date Interval
if ( $lastInsert && intval($nbMois)>0 ) { if ($lastInsert && intval($nbMois)>0) {
$date = DateTime::createFromFormat('Ymd', $lastInsert); $date = DateTime::createFromFormat('Ymd', $lastInsert);
$date = new DateTime(); $date = new DateTime();
$date->add(new DateInterval('P'.$nbMois.'M')); $date->add(new DateInterval('P'.$nbMois.'M'));
$date->setTime(0, 0, 0); $date->setTime(0, 0, 0);
$toInsert = $date->format('Y-m-d'); $toInsert = $date->format('Y-m-d');
echo date('Y/m/d - H:i:s') ." - jusqu'au $toInsert\n"; echo date('Y/m/d - H:i:s') ." - jusqu'au $toInsert\n";
} }
// --- A partir d'une date, jusqu'à aujourdhui // --- A partir d'une date, jusqu'à aujourdhui
if ( $toInsert === null ) { if ($toInsert === null) {
$sql = $db->select()->from('bilans', array(new Zend_Db_Expr('DISTINCT siren AS siren')), 'jo') $sql = $db->select()->from('bilans', array(new Zend_Db_Expr('DISTINCT siren AS siren')), 'jo')
->where('dateInsert >= ?', $lastInsert); ->where('dateInsert >= ?', $lastInsert);
if (!empty($sirenReprise)) { if (!empty($sirenReprise)) {
$sql->where('siren >= ?', $sirenReprise); $sql->where('siren >= ?', $sirenReprise);
} }
} }
// --- Date intervalle // --- Date intervalle
else { else {
$sql = $db->select()->from('bilans', array(new Zend_Db_Expr('DISTINCT siren AS siren')), 'jo') $sql = $db->select()->from('bilans', array(new Zend_Db_Expr('DISTINCT siren AS siren')), 'jo')
->where('dateInsert BETWEEN "'.$lastInsert.' 00:00:00" AND "'.$toInsert.' 23:59:59"'); ->where('dateInsert BETWEEN "'.$lastInsert.' 00:00:00" AND "'.$toInsert.' 23:59:59"');
if (!empty($sirenReprise)) { if (!empty($sirenReprise)) {
$sql->where('siren >= ?', $sirenReprise); $sql->where('siren >= ?', $sirenReprise);
} }
} }
$sql->order('siren ASC'); $sql->order('siren ASC');
$result = $db->fetchAll($sql, null, Zend_Db::FETCH_ASSOC); $result = $db->fetchAll($sql, null, Zend_Db::FETCH_ASSOC);
$unitTotal = count($result); $unitTotal = count($result);
} }
echo date('Y/m/d - H:i:s') ." - Il y a $unitTotal siren avec Bilan à mettre à jour...\n"; echo date('Y/m/d - H:i:s') ." - Il y a $unitTotal siren avec Bilan à mettre à jour...\n";
if ($execId !== null) { if ($execId !== null) {
@ -148,51 +147,50 @@ $unitSiren = $unitInc = $unitExec = 0;
// --- Pour chaque siren // --- Pour chaque siren
foreach ($result as $tabTmp) { foreach ($result as $tabTmp) {
$siren = $tabTmp['siren']; $siren = $tabTmp['siren'];
$tabId = $iInsee->getIdentiteLight($siren); $tabId = $iInsee->getIdentiteLight($siren);
$unitSiren++; $unitSiren++;
if (count($tabId) == 0) { if (count($tabId) == 0) {
echo date('Y/m/d - H:i:s') ." - $unitSiren/$unitTotal : $siren sans identite\n"; echo date('Y/m/d - H:i:s') ." - $unitSiren/$unitTotal : $siren sans identite\n";
continue; continue;
} }
$mBil = new Metier_Partenaires_MBilans($siren); $mBil = new Metier_Partenaires_MBilans($siren);
$tabBilans = $mBil->listeBilans(); $tabBilans = $mBil->listeBilans();
// Pour chaque bilans // Pour chaque bilans
if (count($tabBilans) > 0) { if (count($tabBilans) > 0) {
foreach ($tabBilans as $idxBilan => $derBilan) { foreach ($tabBilans as $idxBilan => $derBilan) {
$unitInc++; $unitInc++;
$p = $mBil->getBilan(Metier_Util_Date::dateT('Ymd','d/m/Y', $derBilan['dateExercice']), $derBilan['typeBilan']); $p = $mBil->getBilan(Metier_Util_Date::dateT('Ymd', 'd/m/Y', $derBilan['dateExercice']), $derBilan['typeBilan']);
$conso = 0; $conso = 0;
$liasse = 2050; $liasse = 2050;
if ($p['CONSOLIDE'] == 'C') { if ($p['CONSOLIDE'] == 'C') {
$conso = 1; $conso = 1;
} } elseif ($p['CONSOLIDE'] == 'S') {
elseif ($p['CONSOLIDE'] == 'S') { $liasse = 2033;
$liasse = 2033; }
}
$tabInsert = array( $tabInsert = array(
'siren' => $siren, 'siren' => $siren,
'dateProvPartenaire' => $p['DATE_FRAICHE_BILAN'], 'dateProvPartenaire' => $p['DATE_FRAICHE_BILAN'],
'dateExercice' => $p['DATE_CLOTURE'], 'dateExercice' => $p['DATE_CLOTURE'],
'consolide' => $conso, 'consolide' => $conso,
'liasse' => $liasse, 'liasse' => $liasse,
'dureeExercice' => $p['DUREE_MOIS'], 'dureeExercice' => $p['DUREE_MOIS'],
'monnaie' => $p['MONNAIE'], 'monnaie' => $p['MONNAIE'],
'partenaire' => $p['SOURCE'], 'partenaire' => $p['SOURCE'],
'confidentiel' => $p['TOP_CONFIDENTIEL'], 'confidentiel' => $p['TOP_CONFIDENTIEL'],
'dateInsert' => $p['DATE_BILAN_SD'], 'dateInsert' => $p['DATE_BILAN_SD'],
'apen' => $tabId['NafEnt'], 'apen' => $tabId['NafEnt'],
'fjur' => $tabId['FJ'], 'fjur' => $tabId['FJ'],
'tca' => $tabId['TrancheCA'], 'tca' => $tabId['TrancheCA'],
'teffen' => $tabId['EffEnTr'], 'teffen' => $tabId['EffEnTr'],
); );
if ($liasse == 2033) { if ($liasse == 2033) {
$p = $mBil->bilanSimplifie2Normal($p); $p = $mBil->bilanSimplifie2Normal($p);
} }
// Pour chaque poste // Pour chaque poste
foreach ($tabPostes as $poste) { foreach ($tabPostes as $poste) {
//$tabInsert[$poste] = 'NULL'; //$tabInsert[$poste] = 'NULL';
if (in_array($poste, $p)) { if (in_array($poste, $p)) {
@ -204,51 +202,51 @@ foreach ($result as $tabTmp) {
} }
} }
// Gestion de l'enregistrement // Gestion de l'enregistrement
$error = false; $error = false;
try { try {
$bilanpSql = $db->select()->from('jo.bilans_postes')->where('id=?', $p['ID_BILAN_SD']); $bilanpSql = $db->select()->from('jo.bilans_postes')->where('id=?', $p['ID_BILAN_SD']);
$bilanpResult = $db->fetchRow($bilanpSql, array(), Zend_Db::FETCH_OBJ); $bilanpResult = $db->fetchRow($bilanpSql, array(), Zend_Db::FETCH_OBJ);
// Insert // Insert
if ($bilanpResult === null) { if ($bilanpResult === null) {
$tabInsert['id'] = $p['ID_BILAN_SD']; $tabInsert['id'] = $p['ID_BILAN_SD'];
try { try {
$db->insert('jo.bilans_postes', $tabInsert); $db->insert('jo.bilans_postes', $tabInsert);
} catch (Zend_Db_Exception $e ) { } catch (Zend_Db_Exception $e) {
$error = true; $error = true;
$errMsg = $e->getMessage(); $errMsg = $e->getMessage();
echo date('Y/m/d - H:i:s') . " - $unitSiren/$unitTotal siren $siren - insert : " . $errMsg ."\n"; echo date('Y/m/d - H:i:s') . " - $unitSiren/$unitTotal siren $siren - insert : " . $errMsg ."\n";
} }
} }
// Update // Update
else { else {
try { try {
$db->update('jo.bilans_postes', $tabInsert, 'id='.$p['ID_BILAN_SD']); $db->update('jo.bilans_postes', $tabInsert, 'id='.$p['ID_BILAN_SD']);
} catch (Zend_Db_Exception $e ) { } catch (Zend_Db_Exception $e) {
$error = true; $error = true;
$errMsg = $e->getMessage(); $errMsg = $e->getMessage();
echo date('Y/m/d - H:i:s') . " - $unitSiren/$unitTotal siren $siren - update : " .$errMsg ."\n"; echo date('Y/m/d - H:i:s') . " - $unitSiren/$unitTotal siren $siren - update : " .$errMsg ."\n";
} }
} }
if ($error) { if ($error) {
$mail = new Metier_Util_Mail(); $mail = new Metier_Util_Mail();
$mail->send('production@scores-decisions.com', 'suivi@scores-decisions.com', $mail->send('production@scores-decisions.com', 'suivi@scores-decisions.com',
'Bilan Postes - ERREUR', $errMsg."\n\n".print_r($tabInsert,true)); 'Bilan Postes - ERREUR', $errMsg."\n\n".print_r($tabInsert, true));
} else { } else {
$unitExec++; $unitExec++;
if ($execId !== null) { if ($execId !== null) {
$execRef->increment($execId, $unitExec); $execRef->increment($execId, $unitExec);
} }
} }
} catch (Zend_Db_Exception $e ) { } catch (Zend_Db_Exception $e) {
echo date('Y/m/d - H:i:s') . " - $unitSiren/$unitTotal siren $siren - ".$p['ID_BILAN_SD']." : " . $e->getMessage()."\n"; echo date('Y/m/d - H:i:s') . " - $unitSiren/$unitTotal siren $siren - ".$p['ID_BILAN_SD']." : " . $e->getMessage()."\n";
} }
} }
} }
if ($unitSiren%1000==0) { if ($unitSiren%1000==0) {
echo date('Y/m/d - H:i:s') ." - $unitSiren/$unitTotal siren traités ($siren)...\n"; echo date('Y/m/d - H:i:s') ." - $unitSiren/$unitTotal siren traités ($siren)...\n";
} }
} }
if ($execId !== null) { if ($execId !== null) {