170 lines
8.0 KiB
PHP
170 lines
8.0 KiB
PHP
|
#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
|
||
|
<?php
|
||
|
|
||
|
$tabPostes=array('AA','AA2','AB','AC','AC1','AD','AE','AE1','AF','AG','AG1','AH','AI','AI1','AJ','AK','AK1','AL','AM','AM1','AN','AO','AO1','AP','AQ','AQ1','AR','AS','AS1','AT','AU','AU1','AV','AW','AW1','AX','AY','AY1','CS','CT','CT1','CU','CV','CV1','BB','BC','BC1','BD','BE','BE1','BF','BG','BG1','BH','BI','BI1','BJ','BK','BK1','BL','BM','BM1','BN','BO','BO1','BP','BQ','BQ1','BR','BS','BS1','BT','BU','BU1','BV','BW','BW1','BX','BY','BY1','BZ','CA','CA1','CB','CC','CC1','CD','CE','CE1','CF','CG','CG1','CH','CI','CI1','CJ','CK','CK1','CL','CL2','CM','CM2','CN','CN2','CO','1A','1A1','CP','CR','DA','DB','EK','DC','DD','DE','B1','DF','EJ','DG','DH','DI','DJ','DK','DL','DM','DN','DO','DP','DQ','DR','DS','DT','DU','DV','DW','DX','DY','DZ','EA','EB','EC','ED','EE','EF','EG','EH','EI','FA','FB','FC','FD','FE','FF','FG','FH','FI','FJ','FK','FL','FM','FN','FO','FP','FQ','FR','FS','FT','FU','FV','FW','FX','FY','FZ','GA','GB','GC','GD','GE','GF','GG','GH','GI','GJ','GK','GL','GM','GN','GO','GP','GQ','GR','GS','GT','GU','GV','GW','HA','HB','HC','HD','HE','HF','HG','HH','HI','HJ','HK','HL','HM','HN','HP','HQ','A1','A2','A3','A4','A6','A9','KA','KB','KC','KD','KE','KF','LN','LO','LP','LQ','LR','LS','0G','0H','0J','NL','LT','LU','1W','N0','LV','LW','1X','MY','MZ','NA','NB','NC','ND','NE','NF','NN','NG','NH','NI','I2','2E','2F','2G','NM','NJ','NK','2H','NP','0K','0L','0M','PA','PB','PC','PD','PE','PF','PG','PH','QU','QV','QW','QX','0N','0P','0Q','0R','SM0','SI','SM','SN','SP0','SO','SP','SR','3X','TM','TN','TO','3Z','TS','TT','TU','4A','4B','4C','4D','4E','4F','4G','4H','4J','4K','4L','4M','4N','4P','4R','4S','4T','4U','4V','4W','4X','4Y','4Z','5A','5B','5C','5D','5E','5F','5G','5J','5K','5L','5M','5N','5P','5R','5S','5T','5U','5V','5W','5X','5Y','5Z','TV','TW','TX','6A','6B','6C','6D','6E','6F','6G','6H','02','03','04','05','9U','9V','9W','9X','06','07','08','09','6N','6P','6R','6S','6T','6U','6V','6W','6X','6Y','6Z','7A','7B','TY','TZ','UA','7C','UB','UC','UD','UE','UF','UG','UH','UJ','UK','UL','UM','UN','UP','UR','US','UT','UV','UW','VA','VA1','VA2','UX','UX1','UX2','UQ','U0','UU','UU1','UU2','UY','UY1','UY2','UZ','UZ1','UZ2','VM','VM1','VM2','VB','VB1','VB2','VN','VN1','VN2','VP','VP1','VP2','VC','VC1','VC2','VR','VR1','VR2','VS','VS1','VS2','VT','VU','VV','7Y','7Y1','7Y2','7Y3','7Z','7Z1','7Z2','7Z3','VG','VG1','VG2','VG3','VH','VH1','VH2','VH3','8A','8A1','8A2','8A3','8B','8B1','8B2','8B3','8C','8C1','8C2','8C3','8D','8D1','8D2','8D3','8E','8E1','8E2','8E3','VW','VW1','VW2','VW3','VX','VX1','VX2','VX3','VQ','VQ1','VQ2','VQ3','8J','8J1','8J2','8J3','VI','VI1','VI2','VI3','8K','8K1','8K2','8K3','SZ','SZ1','SZ2','SZ3','8L','8L1','8L2','8L3','VY','VZ','VZ1','VZ2','VJ','VL','VK','ZE','YQ','YR','YS','YT','XQ','YU','SS','YV','ST','ZJ','YW','9Z','YX','YY','YZ','YP','ZR');
|
||
|
|
||
|
/** @todo Faire tourner le premier lundi du mois
|
||
|
**/
|
||
|
|
||
|
function exporte($txt, $lon=-1, $sep="|") {
|
||
|
$txt=strtr(trim($txt),array('''=>"'",'&'=>'&', '²'=>'²', "\r"=>'', "\n"=>'', "\t"=>''));
|
||
|
|
||
|
if ($lon==-1) return $txt.$sep;
|
||
|
elseif ($sep=='') return sprintf("%-".$lon.'.'.$lon."s", $txt);
|
||
|
else return trim(sprintf("%-".$lon.'.'.$lon."s", $txt)).$sep;
|
||
|
}
|
||
|
|
||
|
function choixAdr($bodEtab, $bodSiege, $insee) {
|
||
|
|
||
|
if (strlen(trim($bodSiege))>0) $adr=trim($bodSiege);
|
||
|
elseif (strlen(trim($bodEtab))>0) $adr=trim($bodEtab);
|
||
|
else $adr='';
|
||
|
|
||
|
if (isset($insee) && trim($insee)<>'') return $insee;
|
||
|
else return $adr;
|
||
|
}
|
||
|
|
||
|
|
||
|
error_reporting(E_ALL);
|
||
|
|
||
|
include_once(FWK_PATH.'common/chiffres.php');
|
||
|
include_once(FWK_PATH.'common/dates.php');
|
||
|
include_once(INCLUDE_PATH.'partenaires/classMBilans.php');
|
||
|
include_once(INCLUDE_PATH.'insee/classMInsee.php');
|
||
|
include_once(INCLUDE_PATH.'scores/classMFinancier.php');
|
||
|
include_once(INCLUDE_PATH.'scores/classMScores.php');
|
||
|
include_once(FWK_PATH.'mail/sendMail.php');
|
||
|
include_once(INCLUDE_PATH.'partenaires/classMLiens.php');
|
||
|
|
||
|
$iDb=new WDB('jo');
|
||
|
$iDb2=new WDB('jo');
|
||
|
|
||
|
$iInsee=new MInsee();
|
||
|
$iBilan=new MBilans(0);
|
||
|
|
||
|
$iCotation=new ICotation(array());
|
||
|
|
||
|
$stock=false;
|
||
|
$strReprise='';
|
||
|
$date=date('Ymd');
|
||
|
$tabFichier=array();
|
||
|
|
||
|
$nbSirValides=$nbSirInvalides=0;
|
||
|
$nbNicValides=$nbNicInvalides=0;
|
||
|
$nbInsert=0;
|
||
|
$sirenReprise=false;
|
||
|
|
||
|
$strInfoScript='Usage : '.basename($argv[0]). " [OPTION] [Stock Adecco à charger]
|
||
|
Traitement spécifique Kompass.
|
||
|
|
||
|
Options :
|
||
|
-s Traitement du stock
|
||
|
-m Prestation 5 Mise à disposition de la base Ratios
|
||
|
-r:SIREN Siren pour la reprise
|
||
|
-v Verbosité maximum
|
||
|
";
|
||
|
|
||
|
$argv=$_SERVER['argv'];
|
||
|
if ($_SERVER['argc']>1)
|
||
|
{
|
||
|
for ($i=1; isset($argv[$i]); $i++) {
|
||
|
if (substr($argv[$i],0,1)=='-') {
|
||
|
switch (strtolower(substr($argv[$i],1,1))) {
|
||
|
case 's': $stock=true; break;
|
||
|
case 'm': $presta=5; break;
|
||
|
case 'r': $sirenReprise=substr($argv[$i],3); break;
|
||
|
case '-':
|
||
|
case '?': die($strInfoScript); break;
|
||
|
default: die('Option '. $argv[$i] . " inconnue !\n");
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$strSirenReprise='';
|
||
|
if ($sirenReprise) $strSirenReprise="AND siren>=$sirenReprise";
|
||
|
|
||
|
if ($stock) //A,B,E
|
||
|
$nbRows=$iDb->select('bilans','DISTINCT siren',"1 $strSirenReprise AND typeBilan IN('C','N','S') ORDER BY siren ASC", false, MYSQL_ASSOC, true);
|
||
|
else
|
||
|
$nbRows=$iDb->select('bilans','DISTINCT siren',"dateInsert>='2012-05-30' $strSirenReprise AND typeBilan IN('C','N','S') ORDER BY siren ASC", false, MYSQL_ASSOC, true);
|
||
|
|
||
|
echo date('Y/m/d - H:i:s') ." - Il y a $nbRows siren avec Bilan à mettre à jour...".EOL;
|
||
|
$nbRowsTrt=0;
|
||
|
while($tabTmp=$iDb->fetch(MYSQL_ASSOC)) {
|
||
|
$siren=$tabTmp['siren'];
|
||
|
$tabId=@$iInsee->getIdentiteLight($siren);
|
||
|
$mBil=new MBilans($siren);
|
||
|
$tabBilans=@$mBil->listeBilans();
|
||
|
|
||
|
/** Si Réel Normal ou Simplifié la même année on n'en prend qu'un seul **/
|
||
|
$tabBilans2=array();
|
||
|
foreach ($tabBilans as $idxBilan=>$derBilan) {
|
||
|
if ($derBilan['typeBilan']=='N' || $derBilan['typeBilan']=='S')
|
||
|
$tabBilans2[strtr($idxBilan,'NS','__')]=$derBilan;
|
||
|
if (count($tabBilans2)>=5) break;
|
||
|
}
|
||
|
$tabBilans=$tabBilans2;
|
||
|
|
||
|
$iBil=0;
|
||
|
foreach ($tabBilans as $idxBilan=>$derBilan) {
|
||
|
|
||
|
$iBil++;
|
||
|
$p=@$mBil->getBilan(WDate::dateT('Ymd','d/m/Y',$derBilan['dateExercice']), $derBilan['typeBilan']);
|
||
|
$conso=0;
|
||
|
$liasse=2050;
|
||
|
if ($p['CONSOLIDE']=='C') $conso=1;
|
||
|
elseif ($p['CONSOLIDE']=='S') $liasse=2033;
|
||
|
|
||
|
$tabInsert=array('id'=>$p['ID_BILAN_SD'],
|
||
|
'siren'=>$siren,
|
||
|
'dateProvPartenaire'=>$p['DATE_FRAICHE_BILAN'],
|
||
|
'dateExercice'=>$p['DATE_CLOTURE'],
|
||
|
'consolide'=>$conso,
|
||
|
'liasse'=>$liasse,
|
||
|
'dureeExercice'=>$p['DUREE_MOIS'],
|
||
|
'monnaie'=>$p['MONNAIE'],
|
||
|
'partenaire'=>$p['SOURCE'],
|
||
|
'confidentiel'=>$p['TOP_CONFIDENTIEL'],
|
||
|
'dateInsert'=>$p['DATE_BILAN_SD'],
|
||
|
'apen'=>$tabId['NafEnt'],
|
||
|
'fjur'=>$tabId['FJ'],
|
||
|
'tca'=>$tabId['TrancheCA'],
|
||
|
'teffen'=>$tabId['EffEnTr'],
|
||
|
);
|
||
|
|
||
|
/*switch (strtoupper($p['MONNAIE_LIV_UNITE'])) {
|
||
|
case 'M': $multiple=1000000; break;
|
||
|
case 'K': $multiple=1000; break;
|
||
|
default: $multiple=1; break;
|
||
|
}*/
|
||
|
|
||
|
if ($p['CONSOLIDE']=='S') $p=@$mBil->bilanSimplifie2Normal($p);
|
||
|
|
||
|
foreach ($p as $poste=>$valeur) {
|
||
|
if (in_array($poste, $tabPostes)) {
|
||
|
/* if ($poste<>'YP' && $poste<>'YP1' && // Effectif
|
||
|
$poste<>'M2G' && $poste<>'M2H' && // Autres effectifs
|
||
|
$poste<>'ZK' && $poste<>'ZK1' && // Taux
|
||
|
$poste<>'IJ' && $poste<>'JH' && $poste<>'ZR') // pour holding/ste mere
|
||
|
$valeur=$valeur*$multiple;*/
|
||
|
//echo " ... $poste = $valeur".EOL;
|
||
|
$tabInsert[$poste]=$valeur;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (!$iDb2->insert('bilans_postes', $tabInsert, false) && mysql_errno()<>1062) {
|
||
|
sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', 'ERREUR lors du chargement des postes Bilans', print_r($tabInsert,true).EOL.mysql_error().EOL);
|
||
|
print_r($tabInsert);
|
||
|
echo EOL.mysql_error().EOL;
|
||
|
}
|
||
|
}
|
||
|
$nbRowsTrt++;
|
||
|
if ($nbRowsTrt%1000==0)
|
||
|
echo date('Y/m/d - H:i:s') ." - $nbRowsTrt/$nbRows siren traités ($siren)...".EOL;
|
||
|
}
|
||
|
|
||
|
die();
|
||
|
|
||
|
?>
|