Traitement des bilans

This commit is contained in:
Michael RICOIS 2012-01-27 15:55:25 +00:00
parent 8b34000c85
commit 33ba681ce3

View File

@ -663,22 +663,15 @@ function bilanNData($siren, $nic, $values = false)
require_once 'Metier/partenaires/classMBilans.php';
$tabPostes = explode(',', $values);
$annee = 0;
$tabData = array();
$annee = 0;
$mBil = new MBilans($siren);
$tabBilans = $mBil->listeBilans(false, 3);
if (count($tabBilans)>0) {
$tabBil = array();
foreach ($tabBilans as $typeMil=>$bilan) {
$tabBil[] = $mBil->getBilan(substr($typeMil,1), substr($typeMil,0,1));
}
$tabBi = $tabBil[$annee];
$tabBilans = $mBil->listeBilans(false, 9);
if (count($tabBilans)>0) {
$tabBi = findBilan($tabBilans, $annee);
$tabData['bilanNdateCloture'] = $tabBi['DATE_CLOTURE'];
$tabData['bilanNdureeMois'] = $tabBi['DUREE_MOIS'];
if (count($tabPostes)>0){
$tabData['bilanNdureeMois'] = $tabBi['DUREE_MOIS'];
if (count($tabPostes)>0) {
foreach ($tabPostes as $poste) {
if (isset($tabBi[$poste])){
$tabData['bilanN'.$poste] = $tabBi[$poste];
@ -710,25 +703,18 @@ function bilanN1Data($siren, $nic, $values = false)
require_once 'Metier/partenaires/classMBilans.php';
$tabPostes = explode(',', $values);
$tabData = array();
$annee = 1;
$tabData = array();
$mBil = new MBilans($siren);
$tabBilans = $mBil->listeBilans(false, 3);
if (count($tabBilans)>0) {
$tabBil = array();
foreach ($tabBilans as $typeMil=>$bilan) {
$tabBil[] = $mBil->getBilan(substr($typeMil,1), substr($typeMil,0,1));
}
$tabBi = $tabBil[$annee];
$tabData['bilanN1dateCloture'] = $tabBi['DATE_CLOTURE'];
$tabData['bilanN1dureeMois'] = $tabBi['DUREE_MOIS'];
if (count($tabPostes)>0){
$tabBilans = $mBil->listeBilans(false, 9);
if (count($tabBilans)>0) {
$tabBi = findBilan($tabBilans, $annee);
$tabData['bilanNdateCloture'] = $tabBi['DATE_CLOTURE'];
$tabData['bilanNdureeMois'] = $tabBi['DUREE_MOIS'];
if (count($tabPostes)>0) {
foreach ($tabPostes as $poste) {
if (isset($tabBi[$poste])){
$tabData['bilanN1'.$poste] = $tabBi[$poste];
$tabData['bilanN'.$poste] = $tabBi[$poste];
}
}
}
@ -757,25 +743,18 @@ function bilanN2Data($siren, $nic, $values = false)
require_once 'Metier/partenaires/classMBilans.php';
$tabPostes = explode(',', $values);
$tabData = array();
$annee = 2;
$tabData = array();
$mBil = new MBilans($siren);
$tabBilans = $mBil->listeBilans(false, 3);
if (count($tabBilans)>0) {
$tabBil = array();
foreach ($tabBilans as $typeMil=>$bilan) {
$tabBil[] = $mBil->getBilan(substr($typeMil,1), substr($typeMil,0,1));
}
$tabBi = $tabBil[$annee];
$tabData['bilanN2dateCloture'] = $tabBi['DATE_CLOTURE'];
$tabData['bilanN2dureeMois'] = $tabBi['DUREE_MOIS'];
if (count($tabPostes)>0){
$tabBilans = $mBil->listeBilans(false, 9);
if (count($tabBilans)>0) {
$tabBi = findBilan($tabBilans, $annee);
$tabData['bilanNdateCloture'] = $tabBi['DATE_CLOTURE'];
$tabData['bilanNdureeMois'] = $tabBi['DUREE_MOIS'];
if (count($tabPostes)>0) {
foreach ($tabPostes as $poste) {
if (isset($tabBi[$poste])){
$tabData['bilanN2'.$poste] = $tabBi[$poste];
$tabData['bilanN'.$poste] = $tabBi[$poste];
}
}
}
@ -783,6 +762,196 @@ function bilanN2Data($siren, $nic, $values = false)
return $tabData;
}
function findBilan($tabBilans, $position = 0)
{
//Trier et Supprimer les bilans consolidés
$tabBilN = $tabBilS = array();
foreach ($tabBilans as $typeMil => $bilan) {
$annee = substr($typeMil,1);
if (substr($typeMil,0,1)=='N'){
$tabBilN[$annee] = $mBil->getBilan(substr($typeMil,1), substr($typeMil,0,1));
} elseif (substr($typeMil,0,1)=='S'){
$tabBilS[$annee] = $mBil->getBilan(substr($typeMil,1), substr($typeMil,0,1));
}
}
$tabBil = $tabBilN + $tabBilS; //On comble les trous par des bilans simplifié
krsort($tabBil); // Tri décroissant
$tabBi = array();
$countBilan = 0;
foreach($tabBil as $annee => $bilan){
$tabBi = $bilan;
if ($countBilan == $position) break;
$countBilan++;
}
if ($tabBi['CONSOLIDE'] == 'S'){
$bilanT = bilanSimplifie2Normal($tabBi);
$tabBi = $tabBi + $bilanT;
}
return $tabBi;
}
function bilanSimplifie2Normal($bilanRS)
{
$tabBS2BN = array(
'AH'=>'010',
'AI'=>'012',
'AI1'=>'013',
'AJ'=>'014',
'AK'=>'016',
'AK1'=>'017',
'AT'=>'028',
'AU'=>'030',
'AU1'=>'031',
'BH'=>'040',
'BI'=>'042',
'BI1'=>'043',
'BJ'=>'044',
'BK'=>'048',
'BK1'=>'049',
'BL'=>'050',
'BM'=>'052',
'BM1'=>'053',
'BT'=>'060',
'BU'=>'062',
'BU1'=>'063',
'BV'=>'064',
'BW'=>'066',
'BW1'=>'067',
'BX'=>'068',
'BY'=>'070',
'BY1'=>'071',
'BZ'=>'072',
'CA'=>'074',
'CA1'=>'075',
'CD'=>'080',
'CE'=>'082',
'CE1'=>'083',
'CF'=>'084',
'CG'=>'086',
'CG1'=>'087',
'CH'=>'092',
'CI'=>'094',
'CI1'=>'095',
'CJ'=>'096',
'CK'=>'098',
'CK1'=>'099',
'CO'=>'110',
'1A'=>'112',
'1A1'=>'113',
'DA'=>'120',
'DC'=>'124',
'DD'=>'126',
'DF'=>'130',
'DG'=>'132',
'DH'=>'134',
'DI'=>'136',
'DK'=>'140',
'DL'=>'142',
'DR'=>'154',
'DP'=>'154',
'DU'=>'156',
'DV'=>'169',
'DW'=>'164',
'DX'=>'166',
'EA'=>'172-169',
'EB'=>'174',
'EC'=>'176',
'EE'=>'180',
'EH'=>'156-195',
'FA'=>'210-209',
'FB'=>'209',
'FC'=>'210',
'FD'=>'214-215',
'FE'=>'215',
'FF'=>'214',
'FH'=>'217',
'FI'=>'218',
'FK'=>'209+215+217',
'FL'=>'210+214+218',
'FM'=>'222',
'FN'=>'224',
'FO'=>'226',
'FQ'=>'230',
'FR'=>'232',
'FS'=>'234',
'FT'=>'236',
'FU'=>'238',
'FV'=>'240',
'FW'=>'242',
'FX'=>'244',
'FY'=>'250',
'FZ'=>'252',
'GA'=>'254',
'GE'=>'262',
'GF'=>'264',
'GG'=>'270',
'GP'=>'280',
'GU'=>'294',
'GW'=>'270+280+294',
'HD'=>'290',
'HH'=>'300',
'HI'=>'290-300',
'HK'=>'306',
'HL'=>'232+280+290',
'HM'=>'264+294+300+306',
'HN'=>'310',
'YY'=>'374',
'YZ'=>'378',
'YP'=>'376',
);
$bilanRN=array();
foreach ($tabBS2BN as $posteRN => $formule) {
if (preg_match('/\+|\-/', $formule)) {
$tabTmp=preg_split('/\+|\-/', $formule, -1, PREG_SPLIT_OFFSET_CAPTURE);
//$bilanRN[$posteRN]=0;
$scalc='';
foreach ($tabTmp as $i=>$tab) {
if ($i==0) {
$bilanRN[$posteRN]=$bilanRS[$tab[0]];
$scalc.=$bilanRS[$tab[0]];
}
else {
$signe=$formule[$tab[1]-1];
$scalc.=$signe;
if ($signe=='+') $bilanRN[$posteRN]+=$bilanRS[$tab[0]];
elseif ($signe=='-') $bilanRN[$posteRN]-=$bilanRS[$tab[0]];
$scalc.=$bilanRS[$tab[0]];
}
}
$bilanRN[$posteRN]=$bilanRN[$posteRN];
}
else $bilanRN[$posteRN]=$bilanRS[$formule];
}
if ($bilanRS['240']<>0) {
$bilanRN['BL']=$bilanRS['050'];
$bilanRN['BM']=$bilanRS['052'];
} else {
$bilanRN['BN']=$bilanRS['050'];
$bilanRN['BO']=$bilanRS['052'];
}
if ($bilanRS['070']<>0 || $bilanRS['074']<>0 || $bilanRS['052']<>0 || $bilanRS['062']<>0)
$bilanRN['GC']=$bilanRS['256'];
elseif ($bilanRS['070']==0 && $bilanRS['074']==0 && $bilanRS['052']==0 && $bilanRS['062']==0 && $bilanRS['254']<>0)
$bilanRN['GD']=$bilanRS['256'];
if ($bilanRS['584']<>0) {
$bilanRN['HB']=$bilanRS['584'];
$bilanRN['HA']=$bilanRS['290']-$bilanRS['584'];
} else
$bilanRN['HA']=$bilanRS['290'];
if ($bilanRS['582']<>0) {
$bilanRN['HF']=$bilanRS['582'];
$bilanRN['HE']=$bilanRS['582']-$bilanRS['300'];
} else
$bilanRN['HE']=$bilanRS['300'];
return $bilanRN;
}
function annoncesEntete($values)
{
if ($values!==false) {