Michael RICOIS e3faf6cf8f Merge 2.4
2013-11-05 10:02:24 +00:00

993 lines
65 KiB
PHP

<?php
require_once 'framework/common/curl.php';
require_once 'framework/common/dates.php';
//require_once 'Metier/partenaires/classMEuridile.php';
//require_once 'Metier/partenaires/classMRncsFlux.php';
require_once 'Metier/partenaires/classMGreffes.php';
define ('ECART_CTRL_MAX', 5); // Ecart maximal acceptable dans la saisie +/-5 entre les calculs et la saisie !
global $tabCtrl;
$tabCtrl=array(
/** Bilans Réel Normal **/
'S'=>array(
// Actif Simplifié
'010-012=013'=>'Fonds commercial (Brut,Amor/Prov et Net incohérents)',
'014-016=017'=>'Immos incorpo. autres (Brut,Amor/Prov et Net incohérents)',
'028-030=031'=>'Immos corpo. (Brut,Amor/Prov et Net incohérents)',
'040-042=043'=>'Immos finan. (Brut,Amor/Prov et Net incohérents)',
'044-048=049'=>'Total (I) Actif Immos (Brut,Amor/Prov et Net incohérents)',
'010+014+028+040=044'=>'Total Actif immobilisé Brut',
'012+016+030+042=048'=>'Total Actif immobilisé Amor/Prov',
'013+017+031+043=049'=>'Total Actif immobilisé Net',
'050-052=053'=>'Stocks MP (Brut,Amor/Prov et Net incohérents)',
'060-062=063'=>'Stocks Marchandises (Brut,Amor/Prov et Net incohérents)',
'064-066=067'=>'Avances et acomptes/cmds (Brut,Amor/Prov et Net incohérents)',
'068-070=071'=>'Créances clients et CR (Brut,Amor/Prov et Net incohérents)',
'072-074=075'=>'Autres créances (Brut,Amor/Prov et Net incohérents)',
'080-082=083'=>'VMP (Brut,Amor/Prov et Net incohérents)',
'084-086=087'=>'Disponibilités (Brut,Amor/Prov et Net incohérents)',
'088-090=091'=>' (Brut,Amor/Prov et Net incohérents)',
'092-094=095'=>'Ch. constatées d\'avance (Brut,Amor/Prov et Net incohérents)',
'096-098=099'=>'Total (II) Actif Circulant (Brut,Amor/Prov et Net incohérents)',
'110-112=113'=>'Total ACTIF (Brut,Amor/Prov et Net incohérents)',
'050+060+064+068+072+080+084+088+092=096'=>'Total Actif circulant Brut',
'052+062+066+070+074+082+086+090+094=098'=>'Total Actif circulant Amor/Prov',
'053+063+067+071+075+083+087+091+092=099'=>'Total Actif circulant Net',
'044+096=110'=>'Total ACTIF Brut',
'048+098=112'=>'Total ACTIF Amor/Prov',
'049+099=113'=>'Total ACTIF Net',
// Passif Simplifié
'120+124+126+130+132+134+136+140=142'=>'Total Capitaux Propres',
'156+164+166+172+174=176'=>'Total Dettes',
'142+154+176=180'=>'Total Passif',
'113=180'=>'Actif=Passif',
// CDR Simplifié
'210+214+218+222+224+226+230=232'=>'Total des produits d\'exploitation',
'234+236+238+240+242+244+250+252+254+256+262=264'=>'Total des charges d\'exploitation',
'210+214+218+222+224+226+230=232'=>'Total des produits d\'exploitation',
'232-264=270'=>'Résultat d\'exploitation',
'232+280+290-264-294-300-306=310'=>'Résultat d\'exploitation',
),
'N'=>array(
// Actif immobilisé
'AA=AA2'=>'Capital souscrit non appelé',
'AB-AC=AC1'=>'Frais d\'étab. (Brut,Amor/Prov et Net incohérents)',
'AD-AE=AE1'=>'Frais de R&D (Brut,Amor/Prov et Net incohérents)',
'AF-AG=AG1'=>'Brevets (Brut,Amor/Prov et Net incohérents)',
'AH-AI=AI1'=>'Fonds commercial (Brut,Amor/Prov et Net incohérents)',
'AJ-AK=AK1'=>'Autres immo inc. (Brut,Amor/Prov et Net incohérents)',
'AL-AM=AM1'=>'Acomptes immo inc. (Brut,Amor/Prov et Net incohérents)',
'AN-AO=AO1'=>'Terrains (Brut,Amor/Prov et Net incohérents)',
'AP-AQ=AQ1'=>'Constructions (Brut,Amor/Prov et Net incohérents)',
'AR-AS=AS1'=>'Installations (Brut,Amor/Prov et Net incohérents)',
'AT-AU=AU1'=>'Autres immo corp. (Brut,Amor/Prov et Net incohérents)',
'AV-AW=AW1'=>'Immos en cours (Brut,Amor/Prov et Net incohérents)',
'AX-AY=AY1'=>'Acomptes immo corp. (Brut,Amor/Prov et Net incohérents)',
'CS-CT=CT1'=>'Immo Fi participations/équiv. (Brut,Amor/Prov et Net incohérents)',
'CU-CV=CV1'=>'Autres participations (Brut,Amor/Prov et Net incohérents)',
'BB-BC=BC1'=>'Créances rattachées à des particip. (Brut,Amor/Prov et Net incohérents)',
'BD-BE=BE1'=>'Autres titres immo. (Brut,Amor/Prov et Net incohérents)',
'BF-BG=BG1'=>'Prêts (Brut,Amor/Prov et Net incohérents)',
'BH-BI=BI1'=>'Autres Immo Financières (Brut,Amor/Prov et Net incohérents)',
'BJ-BK=BK1'=>'Total de l\'Actif Immobilisé (Brut,Amor/Prov et Net incohérents)',
'AB+AD+AF+AH+AJ+AL+AN+AP+AR+AT+AV+AX+CS+CU+BB+BD+BF+BH=BJ'=>'Total des Immobilisations (Brut)',
'AC+AE+AG+AI+AK+AM+AO+AQ+AS+AU+AW+AY+CT+CV+BC+BE+BG+BI=BK'=>'Total des Immobilisations (Amor.)',
'AC1+AE1+AG1+AI1+AK1+AM1+AO1+AQ1+AS1+AU1+AW1+AY1+CT1+CV1+BC1+BE1+BG1+BI1=BK1'=>'Total des Immobilisations (Net)',
// Actif circulant
'BL-BM=BM1'=>'Stocks de MP (Brut,Amor/Prov et Net incohérents)',
'BN-BO=BO1'=>'Stocks en cours de prod. biens (Brut,Amor/Prov et Net incohérents)',
'BP-BQ=BQ1'=>'Stocks en cours de prod. services (Brut,Amor/Prov et Net incohérents)',
'BR-BS=BS1'=>'Stocks produits finis (Brut,Amor/Prov et Net incohérents)',
'BT-BU=BU1'=>'Stocks de marchandises (Brut,Amor/Prov et Net incohérents)',
'BV-BW=BW1'=>'Avances et acomptes/cmds (Brut,Amor/Prov et Net incohérents)',
'BX-BY=BY1'=>'Créances clients (Brut,Amor/Prov et Net incohérents)',
'BZ-CA=CA1'=>'Autres créances (Brut,Amor/Prov et Net incohérents)',
'CB-CC=CC1'=>'Capital souscrit appelé non versé (Brut,Amor/Prov et Net incohérents)',
'CD-CE=CE1'=>'VMP (Brut,Amor/Prov et Net incohérents)',
'CF-CG=CG1'=>'Disponibilités (Brut,Amor/Prov et Net incohérents)',
'CH-CI=CI1'=>'Charges Const. d\'avance(Brut,Amor/Prov et Net incohérents)',
'CJ-CK=CK1'=>'Total de l\'Actif Circulant (Brut,Amor/Prov et Net incohérents)',
'BL+BN+BP+BR+BT+BV+BX+BZ+CB+CD+CF+CH=CJ'=>'Total l\'Actif Circulant (Brut)',
'BM+BO+BQ+BS+BU+BW+BY+CA+CC+CE+CG+CI=CK'=>'Total l\'Actif Circulant (Amor.)',
'BM1+BO1+BQ1+BS1+BU1+BW1+BY1+CA1+CC1+CE1+CG1+CI1=CK1'=>'Total l\'Actif Circulant (Net)',
'CL=CL2'=>'Charges / plus. ex. (Brut<>Net)',
'CM=CM2'=>'Primes de Rbt obligations (Brut<>Net)',
'CN=CN2'=>'Ecarts de conversion d\'actif (Brut<>Net)',
'CO-1A=1A1'=>'Total Actif (Brut,Amor/Prov et Net incohérents)',
'AA+BJ+CJ+CL+CM+CN=CO'=>'Total Actif Brut',
'BK+CK=1A'=>'Total Actif (Amor.)',
'AA2+BK1+CK1+CL2+CM2+CN2=1A1'=>'Total Actif Net',
// PASSIF
'DA+DB+DC+DD+DE+DF+DG+DH+DI+DJ+DK=DL'=>'Passif : s/total I (Capitaux Propres)',
'DM+DN=DO'=>'Passif : s/total II (Autres fonds propres)',
'DP+DQ=DR'=>'Passif : s/total III (Provisions)',
'DS+DT+DU+DV+DW+DX+DY+DZ+EA+EB=EC'=>'Passif : s/total IV (Dettes+Cpt régul. PCA)',
'DL+DO+DR+EC+ED=EE'=>'Total Passif',
'EE=1A1'=>'Total Actif=Total Passif',
// CDR
'FA+FB=FC'=>'Total Ventes de marchandises',
'FD+FE=FF'=>'Total Production vendue de biens',
'FG+FH=FI'=>'Total Production vendue de services',
'FJ+FK=FL'=>'Total Chiffe d\'Affaires France+Export',
'FA+FD+FG=FJ'=>'Total C.A. France',
'FB+FE+FH=FK'=>'Total C.A. Export',
'FC+FF+FI=FL'=>'Total C.A. Total (Vtes+Biens+Services)',
'FL+FM+FN+FO+FP+FQ=FR'=>'Total I : Produits d\'Exploitation',
'FS+FT+FU+FV+FW+FX+FY+FZ+GA+GB+GC+GD+GE=GF'=>'Total II :Charges d\'Exploitation',
'FR-GF=GG'=>'1 - Résultat d\'Exploitation',
'GJ+GK+GL+GM+GN+GO=GP'=>'Total V : Produits Financiers',
'GQ+GR+GS+GT=GU'=>'Total VI : Charges Financières',
'GP-GU=GV'=>'2 - Résultat Financier',
'GG+GH-GI+GV=GW'=>'3 - R.C.A.I.',
'HA+HB+HC=HD'=>'Total VII : Produits Exceptionnels',
'HE+HF+HG=HH'=>'Total VIII : Charges Exceptionnels',
'HD-HH=HI'=>'4 - Résultat Exceptionnel',
'FR+GH+GP+HD=HL'=>'CDR : Total des Produits',
'GF+GI+GU+HH+HJ+HK=HM'=>'CDR : Total des Charges',
'HL-HM=HN'=>'5 - Résultat de l\'exercice',
// Immobilisations
/* 'LY+MB+ME+MH+MK+MN+MQ+MT+MW+NA+NE=NH'=>'2054: Immos Total III Brut fin ex. incohérent',
'0V+0Y+2C+2F=NK'=>'2054: Immos Total IV Brut fin ex. incohérent',
'LU+LW+NH+NK=0L'=>'2054: Immos Total Général Brut fin ex. incohérent',
'0L=BJ'=>'Immos Total Général Brut du 2054 <> BJ du 2050',*/
),
);
$tabLibCodeCtrl=array(
'_0'=>'-',
'_1'=>'Corrigé',
'_3'=>'Capital',
'_5'=>'Calculs', // Anciennement 2 mais maintenant >=5 correspond à une erreur grave
'_7'=>'Effectif',
'_9'=>'Unité',
);
$tabLibCodeSaisie=array(
// Code Saisie Bilans par Infogreffe
'_00'=>'Bilan saisi sans anomalie',
'_01'=>'Bilan saisi avec des incohérences comptables à la source du document (issues du remettant)',
'_02'=>'Bilan avec Actif, Passif ou Compte de Résultat nul',
'_03'=>'Bilan incomplet (des pages manquent)',
'_04'=>'Bilan complet non détaillé (seuls les totaux et sous totaux sont renseignés)',
'_05'=>'Bilan reçu en double exemplaire',
'_06'=>'Bilan intermédiaire - Situation provisoire',
'_07'=>'Bilan illisible',
'_A7'=>'Bilan illisible, présentant un cadre gris très foncés (dans lesquels sont inscrits en général les totaux)',
'_B7'=>'Bilan manuscrits',
'_C7'=>'Bilan illisible, présentant des caractères trop gras',
'_D7'=>'Bilan scanné en biais ou qui présentent des pages rognées',
'_E7'=>'Bilan numérisés trop clairement (comme une imprimante dont la cartouche est presque vide)',
'_F7'=>'Bilan illisible',
'_08'=>'Bilan consolidé',
'_09'=>'Déclaration d\'impôts',
'_10'=>'Document autre que bilan',
'_11'=>'Bilan de clôture de liquidation',
'_12'=>'Bilan de Société financière',
'_13'=>'Bilan de Société d\'assurance',
'_14'=>'Bilan de Société immobilière',
'_15'=>'Bilan de Société étrangère',
// Codes saisie de Bilans spécifique às S&D
'_70'=>'Document relatif à une autre société',
);
class MBilans {
public $siren;
public $dernierExerciceDepose=0;
public $dernierExerciceDeposeLe=0;
// public $rncs;
public $igreffe;
private $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',
);
function __construct($siren) {
$this->siren=$siren;
//$this->rncs=new MRncsFlux();
$this->igreffe=new MGreffes();
}
function __destruct() {}
/** Liste les bilans disponibles au format numérique (et non PDF image) pour une entreprise
**
** @param $accesPartenaire bool Accès autorisé aux partenaires distant si le bilan est absenr
** @param $nbMaxBilans int Nombre de bilans maximums retournés
**/
function listeBilans($accesPartenaire=false, $nbMaxBilans=0) {
$iDb2=new WDB();
if ($nbMaxBilans>0) $limit="LIMIT 0, $nbMaxBilans";
else $limit='';
$ret=$iDb2->select( 'bilans',
'typeBilan, dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaieOrigine, dateInsert, partenaire',
"siren='$this->siren' ORDER BY dateExercice DESC $limit",false, MYSQL_ASSOC);
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren en base", print_r($ret, true));
$tabRet=array();
$iDb=new WDB('jo');
$ret2=$iDb->select( 'bodacc_detail',
'Bodacc_Date_Parution, dateEffet, typeEven',
"siren='$this->siren' AND Rubrique='comptes' ORDER BY dateEffet DESC",false, MYSQL_ASSOC);
$dateDerDepot=WDate::dateT('Y-m-d','Ymd',@$ret2[0]['dateEffet'])*1;
$dateDerExercice=$ret[0]['dateExercice']*1;
if ($dateDerDepot<>0) {
$this->dernierExerciceDepose = WDate::dateT('Y-m-d','d/m/Y',@$ret2[0]['dateEffet']);
$this->dernierExerciceDeposeLe = WDate::dateT('Y-m-d','d/m/Y',@$ret2[0]['Bodacc_Date_Parution']);
}
if ($accesPartenaire)
$tabRet=$tabRet2=$this->igreffe->getListeBilans($this->siren);
else
$tabRet=$tabRet2=array();
if ($ENV=='PRD') { // A supprimer le jour ou on vire l'ancien serveur car curl plantait sur Infogreffe !!!
$tabRefXml=$tabRefPdf=array();
// Tableau des références de bilans XML Infogreffe
foreach ($tabRet as $idxTmp=>$bilanTmp) {
if ((substr($idxTmp,-4)*1)>(date(Y)-4))
$tabRefXml[]=$bilanTmp['ref'];
}
$tabImg=$this->igreffe->getBilansImages($this->siren);
// Tableau des références de bilans PDF Infogreffe
foreach ($tabImg as $idxTmp=>$bilanTmp) {
if ($bilanTmp['annee']>(date(Y)-4))
$tabRefPdf[]=$bilanTmp['ref'];
}
$tabDiff=array_diff($tabRefPdf, $tabRefXml);
if (count($tabDiff)>0) {
$strMillesimes='';
foreach ($tabDiff as $value) {
$tabTmp=explode('-',$value);
$strMillesimes.=$tabTmp[0].', ';
}
@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "Bilans non saisit sur $this->siren pour $strMillesimes",
'Différence :'.EOL.print_r($tabDiff,true) .EOL.
'Liste XML:'.EOL.print_r($tabRefXml, true) .EOL.
'Liste PDF:'.EOL.print_r($tabRefPdf,true) .EOL
);
}
}
$tabTri=array();
foreach ($tabRet as $millesime=>$bil) {
$typeBilan=substr($millesime,0,1);
$dateExercice=WDate::dateT('d/m/Y','Ymd',substr($millesime,1,10));
$tabTri[''.$dateExercice.'-'.$typeBilan]=$millesime;
}
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren après accès partenaire", print_r($tabRet2, true));
foreach ($ret as $i=>$bil) {
$millesime=WDate::dateT('Ymd','d/m/Y',$bil['dateExercice']);
$tabRet[''.$bil['typeBilan'].$millesime]=array(
'dateProvPartenaire'=>$bil['dateProvPartenaire'],
'dateInsert' =>strtr($bil['dateInsert'],
array(' '=>'',':'=>'','-'=>'')),
'typeBilan' =>$bil['typeBilan'], // NEW
'dureeExercice' =>$bil['dureeExercice'],// NEW
'dateExercice' =>$bil['dateExercice'],
'millesime' =>substr($bil['dateExercice'],0,4),
'dateExercicePre' =>$bil['dateExercicePre'],
'dureeExercicePre' =>$bil['dureeExercicePre'],
'monnaie' =>$bil['monnaieOrigine'],
'source' =>$bil['partenaire'],
);
$tabTri[''.$bil['dateExercice'].'-'.$bil['typeBilan']]=$bil['typeBilan'].$millesime;
}
krsort($tabTri);
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren avant le tri", print_r($tabTri, true));
$exercicePre=$typePre=$tmpPre=false;
$refPre='';
$strInfos='';
foreach ($tabTri as $tmp=>$typeMillesime) {
$exercice=substr($tmp,0,8);
$type=substr($tmp,9,1);
$ref=$tabRet[''.$typeMillesime]['ref'];
if ($exercice==$exercicePre && $type=='N' && $typePre=='S' && $refPre=='') {
// Suppression du bilan RN de la liste si Réel Normal et Réel Simplifiés présents en base
unset($tabTri[$tmp]);
$strInfos.="Suppression de '$tmp'".EOL;
}
elseif ($exercice==$exercicePre && $type=='N' && $typePre=='S' && $refPre<>'') {
// Suppression du bilan RS de la liste si Réel Normal Présent en base et réel simplifié non encore en base
if ($tmpPre<>false) {
unset($tabTri[$tmpPre]);
$strInfos.="Suppression de '$tmpPre'".EOL;
}
}
$exercicePre=$exercice;
$typePre=$type;
$refPre=@trim($ref);
$tmpPre=$tmp;
}
krsort($tabTri);
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren après le tri", print_r($tabTri, true).EOL.$strInfos.EOL);
$tabRet3=array();
foreach ($tabTri as $tmp=>$typeMillesime)
$tabRet3[''.$typeMillesime]=$tabRet[''.$typeMillesime];
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "listeBilans sur $this->siren après le tri / retour", print_r($tabRet3, true));
return $tabRet3;
}
/** Retourne un bilan disponible au format numérique pour une entreprise
**
** @param $millesime date Date de cloture du bilan au format d/m/Y
** @param $typeBilan enum Type de bilan (N=Réel Normal, S=Réel Simplifié, C=Consolidé, A=Assurance, B=Banque)
** @param $refPart string Référence du bilan chez le partenaire (si $accesPartenaire=true)
** @param $accesPartenaire bool Accès autorisé aux partenaires distant si le bilan est absenr
**/
function getBilan($millesime='', $typeBilan='N', $refPart=0, $accesPartenaire=false) {
$millesimeDB=WDate::dateT('d/m/Y','Ymd',$millesime);
$iDb2=new WDB();
if ($accesPartenaire)
// On ne veut pas de bilans "Téléchargés" directement sur Internet
$strSansBilansWeb=' AND partenaire<>7 ';
else
$strSansBilansWeb='';
$ret=$iDb2->select('bilans', 'dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaie, typeBilan, monnaieOrigine, unite, postes, partenaire, id, confidentiel, dateInsert', "siren='$this->siren' AND typeBilan='$typeBilan' AND dateExercice='$millesimeDB' $strSansBilansWeb", true, MYSQL_ASSOC);
$bilan=$ret[0];
if (count($ret)==0 && $accesPartenaire) {
if ($refPart=='' || $refPart==0) {
$tabTmp=$this->igreffe->getListeBilans($this->siren);
foreach ($tabTmp as $idx=>$bil) {
$typeBil=substr($idx,0,1);
$millBil=substr($idx,1,10);
if ($typeBil==$typeBilan && $millBil==$millesime) {
$refPart=$bil['ref'];
break;
}
}
}
// $rncs=new MEuridile($this->siren);
// $tabBilan=$rncs->getBilan($refPart);
$tabBilan=$this->igreffe->getBilan($this->siren, $refPart);
//getBilan(479974115,'2008_sociaux-20081231-7803-04-B-03876-0013849'));
// print_r($tabBilan);
// die ("On veut le bilan $millesime $typeBilan $refPart");
$fp=fopen(LOG_PATH.'/bilans.log', 'a');
fwrite($fp, "Bilan pour ".$this->siren." :\n".print_r($tabBilan,true)."\n\n\n");
fclose($fp);
if ($tabBilan) {
$strPostes='';
foreach ($tabBilan['POSTES'] as $poste=>$valeur)
$strPostes.="$poste=$valeur;";
$tabInsert=array( 'siren' =>$this->siren,
'dateProvPartenaire'=>$tabBilan['DATE_FRAICHE_BILAN'],
'dateExercice' =>WDate::dateT('d/m/Y','Ymd',$tabBilan['DATE_CLOTURE']),
'dateExercicePre' =>WDate::dateT('d/m/Y','Ymd',$tabBilan['DATE_CLOTURE_PRE']),
'dureeExercice' =>$tabBilan['DUREE_MOIS'],
'dureeExercicePre' =>$tabBilan['DUREE_MOIS_PRE'],
'monnaie' =>$tabBilan['MONNAIE'],
'typeBilan' =>$tabBilan['TYPE_BILAN'],
'monnaieOrigine' =>$tabBilan['MONNAIE_ORI'],
'unite' =>$tabBilan['MONNAIE_LIV_UNITE'],
'postes' =>$strPostes,
'partenaire' =>$tabBilan['SOURCE'],
);
if (!$iDb2->insert('bilans', $tabInsert, true))
$iDb2->update('bilans', $tabInsert, "siren='$this->siren' AND typeBilan='$typeBilan' AND dateExercice='$millesimeDB'");
$ret=$iDb2->select('bilans', 'dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaie, typeBilan, monnaieOrigine, unite, postes, partenaire, id, confidentiel, dateInsert', "siren='$this->siren' AND typeBilan='$typeBilan' AND dateExercice='$millesimeDB'", true);
$bilan=$ret[0];
}
}
$tabBilan=$tabBilanPre=$bilanPre=array();
$tabBilan['SIREN'] = $this->siren;
$tabBilan['DATE_FRAICHE_BILAN'] = $bilan['dateProvPartenaire']; // SSAAMMJJ
$tabBilan['DATE_CLOTURE'] = $bilan['dateExercice']; // SSAAMMJJ
$tabBilan['DATE_CLOTURE_PRE'] = $bilan['dateExercicePre']; // SSAAMMJJ
$tabBilan['DUREE_MOIS'] = $bilan['dureeExercice'];
$tabBilan['DUREE_MOIS_PRE'] = $bilan['dureeExercicePre'];
$tabBilan['MONNAIE'] = $bilan['monnaie'];
$tabBilan['CONSOLIDE'] = $bilan['typeBilan']; // C = Bilan consolidé
$tabBilan['MONNAIE_ORI'] = $bilan['monnaieOrigine'];
$tabBilan['MONNAIE_LIV_UNITE'] = $bilan['unite'];
$tabBilan['SOURCE'] = $bilan['partenaire'];
$tabBilan['ID_BILAN_SD'] = $bilan['id'];
$tabBilan['DATE_BILAN_SD'] = $bilan['dateInsert'];
$tabBilan['TOP_CONFIDENTIEL'] = $bilan['confidentiel'];
// Devise et Unité
if ($bilan['monnaie']=='EUR') $monnaie='&euro;'; else $monnaie=$bilan['monnaie'];
switch (strtoupper($bilan['unite'])) {
case 'K': $unite='K'; break;
case 'U':
case ' ':
case '' : $unite=''; break;
case 'M': $unite='M'; break;
default: die('Unite Bilan ('. $bilan['unite'] .') non prise en charge !'); break;
}
$tabBilan['devise'] = /*$unite.*/$monnaie;
/** Remplissage du tableau des postes du Bilan avec prise en compte de l'unité de la monnaie
**/
$tabTmp=explode(';', $bilan['postes']);
foreach ($tabTmp as $i=>$strTmp) {
$tabTmp2=explode('=', $strTmp);
if (isset($tabTmp2[1]))
if ($unite=='K' && $tabTmp2[0]<>'YP' && $tabTmp2[0]<>'YP1' && $tabTmp2[0]<>'376' // Effectifs 2033 et 2050
&& $tabTmp2[0]<>'M2G' && $tabTmp2[0]<>'M2H' // Autres effectifs
&& $tabTmp2[0]<>'ZK' && $tabTmp2[0]<>'ZK1' // Taux
&& $tabTmp2[0]<>'IJ' && $tabTmp2[0]<>'JH' && $tabTmp2[0]<>'ZR' // pour holding/ste mere
)
$tabBilan[$tabTmp2[0]]=$tabTmp2[1]*1000;
elseif ($unite=='M' && $tabTmp2[0]<>'YP' && $tabTmp2[0]<>'YP1' && $tabTmp2[0]<>'376' // Effectifs 2033 et 2050
&& $tabTmp2[0]<>'M2G' && $tabTmp2[0]<>'M2H' // Autres effectifs
&& $tabTmp2[0]<>'ZK' && $tabTmp2[0]<>'ZK1' // Taux
&& $tabTmp2[0]<>'IJ' && $tabTmp2[0]<>'JH' && $tabTmp2[0]<>'ZR' // pour holding/ste mere
)
$tabBilan[$tabTmp2[0]]=$tabTmp2[1]*1000000;
else $tabBilan[$tabTmp2[0]]=$tabTmp2[1];
}
/** Calcul des valeures NET si l'information est absente en base
**/
if ($tabBilan['CONSOLIDE']=='N' || $tabBilan['CONSOLIDE']=='C') {
if (!isset($tabBilan['AA2']) && isset($tabBilan['AA'])) $tabBilan['AA2']=$tabBilan['AA'];
if (!isset($tabBilan['AC1']) && (isset($tabBilan['AB'])||isset($tabBilan['AC']))) $tabBilan['AC1']=$tabBilan['AB']-$tabBilan['AC'];
if (!isset($tabBilan['AE1']) && (isset($tabBilan['AD'])||isset($tabBilan['AE']))) $tabBilan['AE1']=$tabBilan['AD']-$tabBilan['AE'];
if (!isset($tabBilan['AG1']) && (isset($tabBilan['AF'])||isset($tabBilan['AG']))) $tabBilan['AG1']=$tabBilan['AF']-$tabBilan['AG'];
if (!isset($tabBilan['AI1']) && (isset($tabBilan['AH'])||isset($tabBilan['AI']))) $tabBilan['AI1']=$tabBilan['AH']-$tabBilan['AI'];
if (!isset($tabBilan['AK1']) && (isset($tabBilan['AJ'])||isset($tabBilan['AK']))) $tabBilan['AK1']=$tabBilan['AJ']-$tabBilan['AK'];
if (!isset($tabBilan['AM1']) && (isset($tabBilan['AL'])||isset($tabBilan['AM']))) $tabBilan['AM1']=$tabBilan['AL']-$tabBilan['AM'];
if (!isset($tabBilan['AO1']) && (isset($tabBilan['AN'])||isset($tabBilan['AO']))) $tabBilan['AO1']=$tabBilan['AN']-$tabBilan['AO'];
if (!isset($tabBilan['AQ1']) && (isset($tabBilan['AP'])||isset($tabBilan['AQ']))) $tabBilan['AQ1']=$tabBilan['AP']-$tabBilan['AQ'];
if (!isset($tabBilan['AS1']) && (isset($tabBilan['AR'])||isset($tabBilan['AS']))) $tabBilan['AS1']=$tabBilan['AR']-$tabBilan['AS'];
if (!isset($tabBilan['AU1']) && (isset($tabBilan['AT'])||isset($tabBilan['AU']))) $tabBilan['AU1']=$tabBilan['AT']-$tabBilan['AU'];
if (!isset($tabBilan['AW1']) && (isset($tabBilan['AV'])||isset($tabBilan['AW']))) $tabBilan['AW1']=$tabBilan['AV']-$tabBilan['AW'];
if (!isset($tabBilan['AY1']) && (isset($tabBilan['AX'])||isset($tabBilan['AY']))) $tabBilan['AY1']=$tabBilan['AX']-$tabBilan['AY'];
if (!isset($tabBilan['CT1']) && (isset($tabBilan['CS'])||isset($tabBilan['CT']))) $tabBilan['CT1']=$tabBilan['CS']-$tabBilan['CT'];
if (!isset($tabBilan['CV1']) && (isset($tabBilan['CU'])||isset($tabBilan['CV']))) $tabBilan['CV1']=$tabBilan['CU']-$tabBilan['CV'];
if (!isset($tabBilan['BC1']) && (isset($tabBilan['BB'])||isset($tabBilan['BC']))) $tabBilan['BC1']=$tabBilan['BB']-$tabBilan['BC'];
if (!isset($tabBilan['BE1']) && (isset($tabBilan['BD'])||isset($tabBilan['BE']))) $tabBilan['BE1']=$tabBilan['BD']-$tabBilan['BE'];
if (!isset($tabBilan['BG1']) && (isset($tabBilan['BF'])||isset($tabBilan['BG']))) $tabBilan['BG1']=$tabBilan['BF']-$tabBilan['BG'];
if (!isset($tabBilan['BI1']) && (isset($tabBilan['BH'])||isset($tabBilan['BI']))) $tabBilan['BI1']=$tabBilan['BH']-$tabBilan['BI'];
if (!isset($tabBilan['BK1']) && (isset($tabBilan['BJ'])||isset($tabBilan['BK']))) $tabBilan['BK1']=$tabBilan['BJ']-$tabBilan['BK'];
if (!isset($tabBilan['BM1']) && (isset($tabBilan['BL'])||isset($tabBilan['BM']))) $tabBilan['BM1']=$tabBilan['BL']-$tabBilan['BM'];
if (!isset($tabBilan['BO1']) && (isset($tabBilan['BN'])||isset($tabBilan['BO']))) $tabBilan['BO1']=$tabBilan['BN']-$tabBilan['BO'];
if (!isset($tabBilan['BQ1']) && (isset($tabBilan['BP'])||isset($tabBilan['BQ']))) $tabBilan['BQ1']=$tabBilan['BP']-$tabBilan['BQ'];
if (!isset($tabBilan['BS1']) && (isset($tabBilan['BR'])||isset($tabBilan['BS']))) $tabBilan['BS1']=$tabBilan['BR']-$tabBilan['BS'];
if (!isset($tabBilan['BU1']) && (isset($tabBilan['BT'])||isset($tabBilan['BU']))) $tabBilan['BU1']=$tabBilan['BT']-$tabBilan['BU'];
if (!isset($tabBilan['BW1']) && (isset($tabBilan['BV'])||isset($tabBilan['BW']))) $tabBilan['BW1']=$tabBilan['BV']-$tabBilan['BW'];
if (!isset($tabBilan['BY1']) && (isset($tabBilan['BX'])||isset($tabBilan['BY']))) $tabBilan['BY1']=$tabBilan['BX']-$tabBilan['BY'];
if (!isset($tabBilan['CA1']) && (isset($tabBilan['BZ'])||isset($tabBilan['CA']))) $tabBilan['CA1']=$tabBilan['BZ']-$tabBilan['CA'];
if (!isset($tabBilan['CC1']) && (isset($tabBilan['CB'])||isset($tabBilan['CC']))) $tabBilan['CC1']=$tabBilan['CB']-$tabBilan['CC'];
if (!isset($tabBilan['CE1']) && (isset($tabBilan['CD'])||isset($tabBilan['CE']))) $tabBilan['CE1']=$tabBilan['CD']-$tabBilan['CE'];
if (!isset($tabBilan['CG1']) && (isset($tabBilan['CF'])||isset($tabBilan['CG']))) $tabBilan['CG1']=$tabBilan['CF']-$tabBilan['CG'];
if (!isset($tabBilan['CI1']) && (isset($tabBilan['CH'])||isset($tabBilan['CI']))) $tabBilan['CI1']=$tabBilan['CH']-$tabBilan['CI'];
if (!isset($tabBilan['CK1']) && (isset($tabBilan['CJ'])||isset($tabBilan['CK']))) $tabBilan['CK1']=$tabBilan['CJ']-$tabBilan['CK'];
if (!isset($tabBilan['CL2']) && isset($tabBilan['CL'])) $tabBilan['CL2']=$tabBilan['CL'];
if (!isset($tabBilan['CM2']) && isset($tabBilan['CM'])) $tabBilan['CM2']=$tabBilan['CM'];
if (!isset($tabBilan['CN2']) && isset($tabBilan['CN'])) $tabBilan['CN2']=$tabBilan['CN'];
if (!isset($tabBilan['1A1']) && (isset($tabBilan['CO'])||isset($tabBilan['1A']))) $tabBilan['1A1']=$tabBilan['CO']-$tabBilan['1A'];
} elseif ($tabBilan['CONSOLIDE']=='S') {
//if (!isset($tabBilan['AC1']) && (isset($tabBilan['AB'])||isset($tabBilan['AC']))) $tabBilan['AC1']=$tabBilan['AB']-$tabBilan['AC'];
if (!isset($tabBilan['013']) && (isset($tabBilan['010'])||isset($tabBilan['012']))) $tabBilan['013']=$tabBilan['010']-$tabBilan['012'];
if (!isset($tabBilan['017']) && (isset($tabBilan['014'])||isset($tabBilan['016']))) $tabBilan['017']=$tabBilan['014']-$tabBilan['016'];
if (!isset($tabBilan['031']) && (isset($tabBilan['028'])||isset($tabBilan['030']))) $tabBilan['031']=$tabBilan['028']-$tabBilan['030'];
if (!isset($tabBilan['043']) && (isset($tabBilan['040'])||isset($tabBilan['042']))) $tabBilan['043']=$tabBilan['040']-$tabBilan['042'];
if (!isset($tabBilan['049']) && (isset($tabBilan['044'])||isset($tabBilan['048']))) $tabBilan['049']=$tabBilan['044']-$tabBilan['048'];
if (!isset($tabBilan['053']) && (isset($tabBilan['050'])||isset($tabBilan['052']))) $tabBilan['053']=$tabBilan['050']-$tabBilan['052'];
if (!isset($tabBilan['063']) && (isset($tabBilan['060'])||isset($tabBilan['062']))) $tabBilan['063']=$tabBilan['060']-$tabBilan['062'];
if (!isset($tabBilan['067']) && (isset($tabBilan['064'])||isset($tabBilan['066']))) $tabBilan['067']=$tabBilan['064']-$tabBilan['066'];
if (!isset($tabBilan['071']) && (isset($tabBilan['068'])||isset($tabBilan['070']))) $tabBilan['071']=$tabBilan['068']-$tabBilan['070'];
if (!isset($tabBilan['075']) && (isset($tabBilan['072'])||isset($tabBilan['074']))) $tabBilan['075']=$tabBilan['072']-$tabBilan['074'];
if (!isset($tabBilan['083']) && (isset($tabBilan['080'])||isset($tabBilan['082']))) $tabBilan['083']=$tabBilan['080']-$tabBilan['082'];
if (!isset($tabBilan['087']) && (isset($tabBilan['084'])||isset($tabBilan['086']))) $tabBilan['087']=$tabBilan['084']-$tabBilan['086'];
if (!isset($tabBilan['091']) && (isset($tabBilan['088'])||isset($tabBilan['090']))) $tabBilan['091']=$tabBilan['088']-$tabBilan['090'];
if (!isset($tabBilan['095']) && (isset($tabBilan['092'])||isset($tabBilan['094']))) $tabBilan['095']=$tabBilan['092']-$tabBilan['094'];
if (!isset($tabBilan['099']) && (isset($tabBilan['096'])||isset($tabBilan['098']))) $tabBilan['099']=$tabBilan['096']-$tabBilan['098'];
if (!isset($tabBilan['113']) && (isset($tabBilan['110'])||isset($tabBilan['112']))) $tabBilan['113']=$tabBilan['110']-$tabBilan['112'];
}
/** Y a t'il suffisament d'informations sur le bilan précédent
**/
if ($bilan['dateExercicePre']*1==0 || $bilan['dureeExercicePre']*1==0 ||
(($tabBilan['FL1']*1==0 || $tabBilan['EE1']*1==0) && ($tabBilan['CONSOLIDE']=='N' || $tabBilan['CONSOLIDE']=='C')) || // Réel Normal ou Consolidé
(($tabBilan['NA3']*1==0 || $tabBilan['NP3']*1==0) && ($tabBilan['CONSOLIDE']=='A' || $tabBilan['CONSOLIDE']=='B')) || // Banque ou Assurance
(($tabBilan['N15']*1==0 || $tabBilan['N32']*1==0) && $tabBilan['CONSOLIDE']=='S') // Réel Simplifié
) {
/** Il n'y a aucune information sur le bilan précédent
**/
$ret=$iDb2->select('bilans', 'dateProvPartenaire, dateExercice, dateExercicePre, dureeExercice, dureeExercicePre, monnaie, typeBilan, monnaieOrigine, unite, postes', "siren='$this->siren' AND typeBilan='$typeBilan' AND dateExercice<'$millesimeDB' ORDER BY dateExercice DESC LIMIT 0,1", true);
$bilanPre=$ret[0];
$tabBilan['DATE_CLOTURE_PRE'] = $bilanPre['dateExercice']; // SSAAMMJJ
$tabBilan['DUREE_MOIS_PRE'] = $bilanPre['dureeExercice'];
if ($bilanPre['monnaie']=='EUR') $monnaiePre='&euro;'; else $monnaiePre=$bilanPre['monnaie'];
switch (strtoupper($bilanPre['unite'])) {
case 'K': $unitePre='K'; break;
case 'U':
case ' ':
case '' : $unitePre=''; break;
case 'M': $unitePre='M'; break;
default: die('Unite Bilan ('. $bilanPre['unite'] .') non prise en charge !'); break;
}
$tabBilanPre['devise'] = /*$unite.*/$monnaiePre;
$tabTmp=explode(';', $bilanPre['postes']);
/* foreach ($tabTmp as $i=>$strTmp) {
$tabTmp2=explode('=', $strTmp);
if (isset($tabTmp2[1]))
if ($unitePre=='K' && $tabTmp2[0]<>'YP' && $tabTmp2[0]<>'YP1' && $tabTmp2[0]<>'376')
$tabBilanPre[$tabTmp2[0]]=$tabTmp2[1]*1000;
elseif ($unitePre=='M' && $tabTmp2[0]<>'YP' && $tabTmp2[0]<>'YP1' && $tabTmp2[0]<>'376')
$tabBilanPre[$tabTmp2[0]]=$tabTmp2[1]*1000000;
else $tabBilanPre[$tabTmp2[0]]=$tabTmp2[1];
}*/
foreach ($tabTmp as $i=>$strTmp) {
$tabTmp2=explode('=', $strTmp);
if (isset($tabTmp2[1]))
if ($unite=='K' && $tabTmp2[0]<>'YP' && $tabTmp2[0]<>'YP1' && $tabTmp2[0]<>'376' // Effectifs 2033 et 2050
&& $tabTmp2[0]<>'M2G' && $tabTmp2[0]<>'M2H' // Autres effectifs
&& $tabTmp2[0]<>'ZK' && $tabTmp2[0]<>'ZK1' && $tabTmp2[0]<>'ZR' // Taux et infos Filliales
)
$tabBilanPre[$tabTmp2[0]]=$tabTmp2[1]*1000;
elseif ($unite=='M' && $tabTmp2[0]<>'YP' && $tabTmp2[0]<>'YP1' && $tabTmp2[0]<>'376' // Effectifs 2033 et 2050
&& $tabTmp2[0]<>'M2G' && $tabTmp2[0]<>'M2H' // Autres effectifs
&& $tabTmp2[0]<>'ZK' && $tabTmp2[0]<>'ZK1' && $tabTmp2[0]<>'ZR' // Taux et infos Filliales
)
$tabBilanPre[$tabTmp2[0]]=$tabTmp2[1]*1000000;
else $tabBilanPre[$tabTmp2[0]]=$tabTmp2[1];
}
/** Calcul des valeures NET N-1 si l'information est absente du bilan N-1 en base **/
if ($tabBilan['CONSOLIDE']=='N' || $tabBilan['CONSOLIDE']=='C') {
if (!isset($tabBilanPre['AA2']) && isset($tabBilanPre['AA'])) $tabBilanPre['AA2']=$tabBilanPre['AA'];
if (!isset($tabBilanPre['AC1']) && (isset($tabBilanPre['AB'])||isset($tabBilanPre['AC']))) $tabBilanPre['AC1']=$tabBilanPre['AB']-$tabBilanPre['AC'];
if (!isset($tabBilanPre['AE1']) && (isset($tabBilanPre['AD'])||isset($tabBilanPre['AE']))) $tabBilanPre['AE1']=$tabBilanPre['AD']-$tabBilanPre['AE'];
if (!isset($tabBilanPre['AG1']) && (isset($tabBilanPre['AF'])||isset($tabBilanPre['AG']))) $tabBilanPre['AG1']=$tabBilanPre['AF']-$tabBilanPre['AG'];
if (!isset($tabBilanPre['AI1']) && (isset($tabBilanPre['AH'])||isset($tabBilanPre['AI']))) $tabBilanPre['AI1']=$tabBilanPre['AH']-$tabBilanPre['AI'];
if (!isset($tabBilanPre['AK1']) && (isset($tabBilanPre['AJ'])||isset($tabBilanPre['AK']))) $tabBilanPre['AK1']=$tabBilanPre['AJ']-$tabBilanPre['AK'];
if (!isset($tabBilanPre['AM1']) && (isset($tabBilanPre['AL'])||isset($tabBilanPre['AM']))) $tabBilanPre['AM1']=$tabBilanPre['AL']-$tabBilanPre['AM'];
if (!isset($tabBilanPre['AO1']) && (isset($tabBilanPre['AN'])||isset($tabBilanPre['AO']))) $tabBilanPre['AO1']=$tabBilanPre['AN']-$tabBilanPre['AO'];
if (!isset($tabBilanPre['AQ1']) && (isset($tabBilanPre['AP'])||isset($tabBilanPre['AQ']))) $tabBilanPre['AQ1']=$tabBilanPre['AP']-$tabBilanPre['AQ'];
if (!isset($tabBilanPre['AS1']) && (isset($tabBilanPre['AR'])||isset($tabBilanPre['AS']))) $tabBilanPre['AS1']=$tabBilanPre['AR']-$tabBilanPre['AS'];
if (!isset($tabBilanPre['AU1']) && (isset($tabBilanPre['AT'])||isset($tabBilanPre['AU']))) $tabBilanPre['AU1']=$tabBilanPre['AT']-$tabBilanPre['AU'];
if (!isset($tabBilanPre['AW1']) && (isset($tabBilanPre['AV'])||isset($tabBilanPre['AW']))) $tabBilanPre['AW1']=$tabBilanPre['AV']-$tabBilanPre['AW'];
if (!isset($tabBilanPre['AY1']) && (isset($tabBilanPre['AX'])||isset($tabBilanPre['AY']))) $tabBilanPre['AY1']=$tabBilanPre['AX']-$tabBilanPre['AY'];
if (!isset($tabBilanPre['CT1']) && (isset($tabBilanPre['CS'])||isset($tabBilanPre['CT']))) $tabBilanPre['CT1']=$tabBilanPre['CS']-$tabBilanPre['CT'];
if (!isset($tabBilanPre['CV1']) && (isset($tabBilanPre['CU'])||isset($tabBilanPre['CV']))) $tabBilanPre['CV1']=$tabBilanPre['CU']-$tabBilanPre['CV'];
if (!isset($tabBilanPre['BC1']) && (isset($tabBilanPre['BB'])||isset($tabBilanPre['BC']))) $tabBilanPre['BC1']=$tabBilanPre['BB']-$tabBilanPre['BC'];
if (!isset($tabBilanPre['BE1']) && (isset($tabBilanPre['BD'])||isset($tabBilanPre['BE']))) $tabBilanPre['BE1']=$tabBilanPre['BD']-$tabBilanPre['BE'];
if (!isset($tabBilanPre['BG1']) && (isset($tabBilanPre['BF'])||isset($tabBilanPre['BG']))) $tabBilanPre['BG1']=$tabBilanPre['BF']-$tabBilanPre['BG'];
if (!isset($tabBilanPre['BI1']) && (isset($tabBilanPre['BH'])||isset($tabBilanPre['BI']))) $tabBilanPre['BI1']=$tabBilanPre['BH']-$tabBilanPre['BI'];
if (!isset($tabBilanPre['BK1']) && (isset($tabBilanPre['BJ'])||isset($tabBilanPre['BK']))) $tabBilanPre['BK1']=$tabBilanPre['BJ']-$tabBilanPre['BK'];
if (!isset($tabBilanPre['BM1']) && (isset($tabBilanPre['BL'])||isset($tabBilanPre['BM']))) $tabBilanPre['BM1']=$tabBilanPre['BL']-$tabBilanPre['BM'];
if (!isset($tabBilanPre['BO1']) && (isset($tabBilanPre['BN'])||isset($tabBilanPre['BO']))) $tabBilanPre['BO1']=$tabBilanPre['BN']-$tabBilanPre['BO'];
if (!isset($tabBilanPre['BQ1']) && (isset($tabBilanPre['BP'])||isset($tabBilanPre['BQ']))) $tabBilanPre['BQ1']=$tabBilanPre['BP']-$tabBilanPre['BQ'];
if (!isset($tabBilanPre['BS1']) && (isset($tabBilanPre['BR'])||isset($tabBilanPre['BS']))) $tabBilanPre['BS1']=$tabBilanPre['BR']-$tabBilanPre['BS'];
if (!isset($tabBilanPre['BU1']) && (isset($tabBilanPre['BT'])||isset($tabBilanPre['BU']))) $tabBilanPre['BU1']=$tabBilanPre['BT']-$tabBilanPre['BU'];
if (!isset($tabBilanPre['BW1']) && (isset($tabBilanPre['BV'])||isset($tabBilanPre['BW']))) $tabBilanPre['BW1']=$tabBilanPre['BV']-$tabBilanPre['BW'];
if (!isset($tabBilanPre['BY1']) && (isset($tabBilanPre['BX'])||isset($tabBilanPre['BY']))) $tabBilanPre['BY1']=$tabBilanPre['BX']-$tabBilanPre['BY'];
if (!isset($tabBilanPre['CA1']) && (isset($tabBilanPre['BZ'])||isset($tabBilanPre['CA']))) $tabBilanPre['CA1']=$tabBilanPre['BZ']-$tabBilanPre['CA'];
if (!isset($tabBilanPre['CC1']) && (isset($tabBilanPre['CB'])||isset($tabBilanPre['CC']))) $tabBilanPre['CC1']=$tabBilanPre['CB']-$tabBilanPre['CC'];
if (!isset($tabBilanPre['CE1']) && (isset($tabBilanPre['CD'])||isset($tabBilanPre['CE']))) $tabBilanPre['CE1']=$tabBilanPre['CD']-$tabBilanPre['CE'];
if (!isset($tabBilanPre['CG1']) && (isset($tabBilanPre['CF'])||isset($tabBilanPre['CG']))) $tabBilanPre['CG1']=$tabBilanPre['CF']-$tabBilanPre['CG'];
if (!isset($tabBilanPre['CI1']) && (isset($tabBilanPre['CH'])||isset($tabBilanPre['CI']))) $tabBilanPre['CI1']=$tabBilanPre['CH']-$tabBilanPre['CI'];
if (!isset($tabBilanPre['CK1']) && (isset($tabBilanPre['CJ'])||isset($tabBilanPre['CK']))) $tabBilanPre['CK1']=$tabBilanPre['CJ']-$tabBilanPre['CK'];
if (!isset($tabBilanPre['CL2']) && isset($tabBilanPre['CL'])) $tabBilanPre['CL2']=$tabBilanPre['CL'];
if (!isset($tabBilanPre['CM2']) && isset($tabBilanPre['CM'])) $tabBilanPre['CM2']=$tabBilanPre['CM'];
if (!isset($tabBilanPre['CN2']) && isset($tabBilanPre['CN'])) $tabBilanPre['CN2']=$tabBilanPre['CN'];
if (!isset($tabBilanPre['1A1']) && (isset($tabBilanPre['CO'])||isset($tabBilanPre['1A']))) $tabBilanPre['1A1']=$tabBilanPre['CO']-$tabBilanPre['1A'];
/** Reprises des valeures N-1 si l'information est absente en base
**/
// Actif
if (!isset($tabBilan['AA3']) && isset($tabBilanPre['AA2'])) $tabBilan['AA3']=$tabBilanPre['AA2'];
if (!isset($tabBilan['AC2']) && isset($tabBilanPre['AC1'])) $tabBilan['AC2']=$tabBilanPre['AC1'];
if (!isset($tabBilan['AE2']) && isset($tabBilanPre['AE1'])) $tabBilan['AE2']=$tabBilanPre['AE1'];
if (!isset($tabBilan['AG2']) && isset($tabBilanPre['AG1'])) $tabBilan['AG2']=$tabBilanPre['AG1'];
if (!isset($tabBilan['AI2']) && isset($tabBilanPre['AI1'])) $tabBilan['AI2']=$tabBilanPre['AI1'];
if (!isset($tabBilan['AK2']) && isset($tabBilanPre['AK1'])) $tabBilan['AK2']=$tabBilanPre['AK1'];
if (!isset($tabBilan['AM2']) && isset($tabBilanPre['AM1'])) $tabBilan['AM2']=$tabBilanPre['AM1'];
if (!isset($tabBilan['AO2']) && isset($tabBilanPre['AO1'])) $tabBilan['AO2']=$tabBilanPre['AO1'];
if (!isset($tabBilan['AQ2']) && isset($tabBilanPre['AQ1'])) $tabBilan['AQ2']=$tabBilanPre['AQ1'];
if (!isset($tabBilan['AS2']) && isset($tabBilanPre['AS1'])) $tabBilan['AS2']=$tabBilanPre['AS1'];
if (!isset($tabBilan['AU2']) && isset($tabBilanPre['AU1'])) $tabBilan['AU2']=$tabBilanPre['AU1'];
if (!isset($tabBilan['AW2']) && isset($tabBilanPre['AW1'])) $tabBilan['AW2']=$tabBilanPre['AW1'];
if (!isset($tabBilan['AY2']) && isset($tabBilanPre['AY1'])) $tabBilan['AY2']=$tabBilanPre['AY1'];
if (!isset($tabBilan['CT2']) && isset($tabBilanPre['CT1'])) $tabBilan['CT2']=$tabBilanPre['CT1'];
if (!isset($tabBilan['CV2']) && isset($tabBilanPre['CV1'])) $tabBilan['CV2']=$tabBilanPre['CV1'];
if (!isset($tabBilan['BC2']) && isset($tabBilanPre['BC1'])) $tabBilan['BC2']=$tabBilanPre['BC1'];
if (!isset($tabBilan['BE2']) && isset($tabBilanPre['BE1'])) $tabBilan['BE2']=$tabBilanPre['BE1'];
if (!isset($tabBilan['BG2']) && isset($tabBilanPre['BG1'])) $tabBilan['BG2']=$tabBilanPre['BG1'];
if (!isset($tabBilan['BI2']) && isset($tabBilanPre['BI1'])) $tabBilan['BI2']=$tabBilanPre['BI1'];
if (!isset($tabBilan['BK2']) && isset($tabBilanPre['BK1'])) $tabBilan['BK2']=$tabBilanPre['BK1'];
if (!isset($tabBilan['BM2']) && isset($tabBilanPre['BM1'])) $tabBilan['BM2']=$tabBilanPre['BM1'];
if (!isset($tabBilan['BO2']) && isset($tabBilanPre['BO1'])) $tabBilan['BO2']=$tabBilanPre['BO1'];
if (!isset($tabBilan['BQ2']) && isset($tabBilanPre['BQ1'])) $tabBilan['BQ2']=$tabBilanPre['BQ1'];
if (!isset($tabBilan['BS2']) && isset($tabBilanPre['BS1'])) $tabBilan['BS2']=$tabBilanPre['BS1'];
if (!isset($tabBilan['BU2']) && isset($tabBilanPre['BU1'])) $tabBilan['BU2']=$tabBilanPre['BU1'];
if (!isset($tabBilan['BW2']) && isset($tabBilanPre['BW1'])) $tabBilan['BW2']=$tabBilanPre['BW1'];
if (!isset($tabBilan['BY2']) && isset($tabBilanPre['BY1'])) $tabBilan['BY2']=$tabBilanPre['BY1'];
if (!isset($tabBilan['CA2']) && isset($tabBilanPre['CA1'])) $tabBilan['CA2']=$tabBilanPre['CA1'];
if (!isset($tabBilan['CC2']) && isset($tabBilanPre['CC1'])) $tabBilan['CC2']=$tabBilanPre['CC1'];
if (!isset($tabBilan['CE2']) && isset($tabBilanPre['CE1'])) $tabBilan['CE2']=$tabBilanPre['CE1'];
if (!isset($tabBilan['CG2']) && isset($tabBilanPre['CG1'])) $tabBilan['CG2']=$tabBilanPre['CG1'];
if (!isset($tabBilan['CI2']) && isset($tabBilanPre['CI1'])) $tabBilan['CI2']=$tabBilanPre['CI1'];
if (!isset($tabBilan['CK2']) && isset($tabBilanPre['CK1'])) $tabBilan['CK2']=$tabBilanPre['CK1'];
if (!isset($tabBilan['CL3']) && isset($tabBilanPre['CL2'])) $tabBilan['CL3']=$tabBilanPre['CL2'];
if (!isset($tabBilan['CM3']) && isset($tabBilanPre['CM2'])) $tabBilan['CM3']=$tabBilanPre['CM2'];
if (!isset($tabBilan['CN3']) && isset($tabBilanPre['CN2'])) $tabBilan['CN3']=$tabBilanPre['CN2'];
if (!isset($tabBilan['1A2']) && isset($tabBilanPre['1A1'])) $tabBilan['1A2']=$tabBilanPre['1A1'];
// Passif
if (!isset($tabBilan['DA1']) && isset($tabBilanPre['DA'])) $tabBilan['DA1']=$tabBilanPre['DA'];
if (!isset($tabBilan['DB1']) && isset($tabBilanPre['DB'])) $tabBilan['DB1']=$tabBilanPre['DB'];
if (!isset($tabBilan['DC1']) && isset($tabBilanPre['DC'])) $tabBilan['DC1']=$tabBilanPre['DC'];
if (!isset($tabBilan['DD1']) && isset($tabBilanPre['DD'])) $tabBilan['DD1']=$tabBilanPre['DD'];
if (!isset($tabBilan['DE1']) && isset($tabBilanPre['DE'])) $tabBilan['DE1']=$tabBilanPre['DE'];
if (!isset($tabBilan['DF1']) && isset($tabBilanPre['DF'])) $tabBilan['DF1']=$tabBilanPre['DF'];
if (!isset($tabBilan['DG1']) && isset($tabBilanPre['DG'])) $tabBilan['DG1']=$tabBilanPre['DG'];
if (!isset($tabBilan['DH1']) && isset($tabBilanPre['DH'])) $tabBilan['DH1']=$tabBilanPre['DH'];
if (!isset($tabBilan['DI1']) && isset($tabBilanPre['DI'])) $tabBilan['DI1']=$tabBilanPre['DI'];
if (!isset($tabBilan['DJ1']) && isset($tabBilanPre['DJ'])) $tabBilan['DJ1']=$tabBilanPre['DJ'];
if (!isset($tabBilan['DK1']) && isset($tabBilanPre['DK'])) $tabBilan['DK1']=$tabBilanPre['DK'];
if (!isset($tabBilan['DL1']) && isset($tabBilanPre['DL'])) $tabBilan['DL1']=$tabBilanPre['DL'];
if (!isset($tabBilan['DM1']) && isset($tabBilanPre['DM'])) $tabBilan['DM1']=$tabBilanPre['DM'];
if (!isset($tabBilan['DN1']) && isset($tabBilanPre['DN'])) $tabBilan['DN1']=$tabBilanPre['DN'];
if (!isset($tabBilan['DO1']) && isset($tabBilanPre['DO'])) $tabBilan['DO1']=$tabBilanPre['DO'];
if (!isset($tabBilan['DP1']) && isset($tabBilanPre['DP'])) $tabBilan['DP1']=$tabBilanPre['DP'];
if (!isset($tabBilan['DQ1']) && isset($tabBilanPre['DQ'])) $tabBilan['DQ1']=$tabBilanPre['DQ'];
if (!isset($tabBilan['DR1']) && isset($tabBilanPre['DR'])) $tabBilan['DR1']=$tabBilanPre['DR'];
if (!isset($tabBilan['DS1']) && isset($tabBilanPre['DS'])) $tabBilan['DS1']=$tabBilanPre['DS'];
if (!isset($tabBilan['DT1']) && isset($tabBilanPre['DT'])) $tabBilan['DT1']=$tabBilanPre['DT'];
if (!isset($tabBilan['DU1']) && isset($tabBilanPre['DU'])) $tabBilan['DU1']=$tabBilanPre['DU'];
if (!isset($tabBilan['DV1']) && isset($tabBilanPre['DV'])) $tabBilan['DV1']=$tabBilanPre['DV'];
if (!isset($tabBilan['DW1']) && isset($tabBilanPre['DW'])) $tabBilan['DW1']=$tabBilanPre['DW'];
if (!isset($tabBilan['DX1']) && isset($tabBilanPre['DX'])) $tabBilan['DX1']=$tabBilanPre['DX'];
if (!isset($tabBilan['DY1']) && isset($tabBilanPre['DY'])) $tabBilan['DY1']=$tabBilanPre['DY'];
if (!isset($tabBilan['DZ1']) && isset($tabBilanPre['DZ'])) $tabBilan['DZ1']=$tabBilanPre['DZ'];
if (!isset($tabBilan['EA1']) && isset($tabBilanPre['EA'])) $tabBilan['EA1']=$tabBilanPre['EA'];
if (!isset($tabBilan['EB1']) && isset($tabBilanPre['EB'])) $tabBilan['EB1']=$tabBilanPre['EB'];
if (!isset($tabBilan['EC1']) && isset($tabBilanPre['EC'])) $tabBilan['EC1']=$tabBilanPre['EC'];
if (!isset($tabBilan['ED1']) && isset($tabBilanPre['ED'])) $tabBilan['ED1']=$tabBilanPre['ED'];
if (!isset($tabBilan['EE1']) && isset($tabBilanPre['EE'])) $tabBilan['EE1']=$tabBilanPre['EE'];
if (!isset($tabBilan['1B1']) && isset($tabBilanPre['1B'])) $tabBilan['1B1']=$tabBilanPre['1B'];
if (!isset($tabBilan['1C1']) && isset($tabBilanPre['1C'])) $tabBilan['1C1']=$tabBilanPre['1C'];
if (!isset($tabBilan['1D1']) && isset($tabBilanPre['1D'])) $tabBilan['1D1']=$tabBilanPre['1D'];
if (!isset($tabBilan['1E1']) && isset($tabBilanPre['1E'])) $tabBilan['1E1']=$tabBilanPre['1E'];
if (!isset($tabBilan['EF1']) && isset($tabBilanPre['EF'])) $tabBilan['EF1']=$tabBilanPre['EF'];
if (!isset($tabBilan['EG1']) && isset($tabBilanPre['EG'])) $tabBilan['EG1']=$tabBilanPre['EG'];
if (!isset($tabBilan['EH1']) && isset($tabBilanPre['EH'])) $tabBilan['EH1']=$tabBilanPre['EH'];
// Compte de Résultats
if (!isset($tabBilan['FC1']) && isset($tabBilanPre['FC'])) $tabBilan['FC1']=$tabBilanPre['FC'];
if (!isset($tabBilan['FF1']) && isset($tabBilanPre['FF'])) $tabBilan['FF1']=$tabBilanPre['FF'];
if (!isset($tabBilan['FI1']) && isset($tabBilanPre['FI'])) $tabBilan['FI1']=$tabBilanPre['FI'];
if (!isset($tabBilan['FL1']) && isset($tabBilanPre['FL'])) $tabBilan['FL1']=$tabBilanPre['FL'];
if (!isset($tabBilan['FM1']) && isset($tabBilanPre['FM'])) $tabBilan['FM1']=$tabBilanPre['FM'];
if (!isset($tabBilan['FN1']) && isset($tabBilanPre['FN'])) $tabBilan['FN1']=$tabBilanPre['FN'];
if (!isset($tabBilan['FO1']) && isset($tabBilanPre['FO'])) $tabBilan['FO1']=$tabBilanPre['FO'];
if (!isset($tabBilan['FP1']) && isset($tabBilanPre['FP'])) $tabBilan['FP1']=$tabBilanPre['FP'];
if (!isset($tabBilan['FQ1']) && isset($tabBilanPre['FQ'])) $tabBilan['FQ1']=$tabBilanPre['FQ'];
if (!isset($tabBilan['FR1']) && isset($tabBilanPre['FR'])) $tabBilan['FR1']=$tabBilanPre['FR'];
if (!isset($tabBilan['FS1']) && isset($tabBilanPre['FS'])) $tabBilan['FS1']=$tabBilanPre['FS'];
if (!isset($tabBilan['FT1']) && isset($tabBilanPre['FT'])) $tabBilan['FT1']=$tabBilanPre['FT'];
if (!isset($tabBilan['FU1']) && isset($tabBilanPre['FU'])) $tabBilan['FU1']=$tabBilanPre['FU'];
if (!isset($tabBilan['FV1']) && isset($tabBilanPre['FV'])) $tabBilan['FV1']=$tabBilanPre['FV'];
if (!isset($tabBilan['FW1']) && isset($tabBilanPre['FW'])) $tabBilan['FW1']=$tabBilanPre['FW'];
if (!isset($tabBilan['FX1']) && isset($tabBilanPre['FX'])) $tabBilan['FX1']=$tabBilanPre['FX'];
if (!isset($tabBilan['FY1']) && isset($tabBilanPre['FY'])) $tabBilan['FY1']=$tabBilanPre['FY'];
if (!isset($tabBilan['FZ1']) && isset($tabBilanPre['FZ'])) $tabBilan['FZ1']=$tabBilanPre['FZ'];
if (!isset($tabBilan['GA1']) && isset($tabBilanPre['GA'])) $tabBilan['GA1']=$tabBilanPre['GA'];
if (!isset($tabBilan['GB1']) && isset($tabBilanPre['GB'])) $tabBilan['GB1']=$tabBilanPre['GB'];
if (!isset($tabBilan['GC1']) && isset($tabBilanPre['GC'])) $tabBilan['GC1']=$tabBilanPre['GC'];
if (!isset($tabBilan['GD1']) && isset($tabBilanPre['GD'])) $tabBilan['GD1']=$tabBilanPre['GD'];
if (!isset($tabBilan['GE1']) && isset($tabBilanPre['GE'])) $tabBilan['GE1']=$tabBilanPre['GE'];
if (!isset($tabBilan['GF1']) && isset($tabBilanPre['GF'])) $tabBilan['GF1']=$tabBilanPre['GF'];
if (!isset($tabBilan['GG1']) && isset($tabBilanPre['GG'])) $tabBilan['GG1']=$tabBilanPre['GG'];
if (!isset($tabBilan['GH1']) && isset($tabBilanPre['GH'])) $tabBilan['GH1']=$tabBilanPre['GH'];
if (!isset($tabBilan['GI1']) && isset($tabBilanPre['GI'])) $tabBilan['GI1']=$tabBilanPre['GI'];
if (!isset($tabBilan['GJ1']) && isset($tabBilanPre['GJ'])) $tabBilan['GJ1']=$tabBilanPre['GJ'];
if (!isset($tabBilan['GK1']) && isset($tabBilanPre['GK'])) $tabBilan['GK1']=$tabBilanPre['GK'];
if (!isset($tabBilan['GL1']) && isset($tabBilanPre['GL'])) $tabBilan['GL1']=$tabBilanPre['GL'];
if (!isset($tabBilan['GM1']) && isset($tabBilanPre['GM'])) $tabBilan['GM1']=$tabBilanPre['GM'];
if (!isset($tabBilan['GN1']) && isset($tabBilanPre['GN'])) $tabBilan['GN1']=$tabBilanPre['GN'];
if (!isset($tabBilan['GO1']) && isset($tabBilanPre['GO'])) $tabBilan['GO1']=$tabBilanPre['GO'];
if (!isset($tabBilan['GP1']) && isset($tabBilanPre['GP'])) $tabBilan['GP1']=$tabBilanPre['GP'];
if (!isset($tabBilan['GQ1']) && isset($tabBilanPre['GQ'])) $tabBilan['GQ1']=$tabBilanPre['GQ'];
if (!isset($tabBilan['GR1']) && isset($tabBilanPre['GR'])) $tabBilan['GR1']=$tabBilanPre['GR'];
if (!isset($tabBilan['GS1']) && isset($tabBilanPre['GS'])) $tabBilan['GS1']=$tabBilanPre['GS'];
if (!isset($tabBilan['GT1']) && isset($tabBilanPre['GT'])) $tabBilan['GT1']=$tabBilanPre['GT'];
if (!isset($tabBilan['GU1']) && isset($tabBilanPre['GU'])) $tabBilan['GU1']=$tabBilanPre['GU'];
if (!isset($tabBilan['GV1']) && isset($tabBilanPre['GV'])) $tabBilan['GV1']=$tabBilanPre['GV'];
if (!isset($tabBilan['GW1']) && isset($tabBilanPre['GW'])) $tabBilan['GW1']=$tabBilanPre['GW'];
if (!isset($tabBilan['HA1']) && isset($tabBilanPre['HA'])) $tabBilan['HA1']=$tabBilanPre['HA'];
if (!isset($tabBilan['HB1']) && isset($tabBilanPre['HB'])) $tabBilan['HB1']=$tabBilanPre['HB'];
if (!isset($tabBilan['HC1']) && isset($tabBilanPre['HC'])) $tabBilan['HC1']=$tabBilanPre['HC'];
if (!isset($tabBilan['HD1']) && isset($tabBilanPre['HD'])) $tabBilan['HD1']=$tabBilanPre['HD'];
if (!isset($tabBilan['HE1']) && isset($tabBilanPre['HE'])) $tabBilan['HE1']=$tabBilanPre['HE'];
if (!isset($tabBilan['HF1']) && isset($tabBilanPre['HF'])) $tabBilan['HF1']=$tabBilanPre['HF'];
if (!isset($tabBilan['HG1']) && isset($tabBilanPre['HG'])) $tabBilan['HG1']=$tabBilanPre['HG'];
if (!isset($tabBilan['HH1']) && isset($tabBilanPre['HH'])) $tabBilan['HH1']=$tabBilanPre['HH'];
if (!isset($tabBilan['HI1']) && isset($tabBilanPre['HI'])) $tabBilan['HI1']=$tabBilanPre['HI'];
if (!isset($tabBilan['HJ1']) && isset($tabBilanPre['HJ'])) $tabBilan['HJ1']=$tabBilanPre['HJ'];
if (!isset($tabBilan['HK1']) && isset($tabBilanPre['HK'])) $tabBilan['HK1']=$tabBilanPre['HK'];
if (!isset($tabBilan['HL1']) && isset($tabBilanPre['HL'])) $tabBilan['HL1']=$tabBilanPre['HL'];
if (!isset($tabBilan['HM1']) && isset($tabBilanPre['HM'])) $tabBilan['HM1']=$tabBilanPre['HM'];
if (!isset($tabBilan['HN1']) && isset($tabBilanPre['HN'])) $tabBilan['HN1']=$tabBilanPre['HN'];
if (!isset($tabBilan['HO1']) && isset($tabBilanPre['HO'])) $tabBilan['HO1']=$tabBilanPre['HO'];
if (!isset($tabBilan['HY1']) && isset($tabBilanPre['HY'])) $tabBilan['HY1']=$tabBilanPre['HY'];
if (!isset($tabBilan['1G1']) && isset($tabBilanPre['1G'])) $tabBilan['1G1']=$tabBilanPre['1G'];
if (!isset($tabBilan['HP1']) && isset($tabBilanPre['HP'])) $tabBilan['HP1']=$tabBilanPre['HP'];
if (!isset($tabBilan['HQ1']) && isset($tabBilanPre['HQ'])) $tabBilan['HQ1']=$tabBilanPre['HQ'];
if (!isset($tabBilan['1H1']) && isset($tabBilanPre['1H'])) $tabBilan['1H1']=$tabBilanPre['1H'];
if (!isset($tabBilan['1J1']) && isset($tabBilanPre['1J'])) $tabBilan['1J1']=$tabBilanPre['1J'];
if (!isset($tabBilan['1K1']) && isset($tabBilanPre['1K'])) $tabBilan['1K1']=$tabBilanPre['1K'];
if (!isset($tabBilan['HX1']) && isset($tabBilanPre['HX'])) $tabBilan['HX1']=$tabBilanPre['HX'];
if (!isset($tabBilan['A11']) && isset($tabBilanPre['A1'])) $tabBilan['A11']=$tabBilanPre['A1'];
if (!isset($tabBilan['A21']) && isset($tabBilanPre['A2'])) $tabBilan['A21']=$tabBilanPre['A2'];
if (!isset($tabBilan['A31']) && isset($tabBilanPre['A3'])) $tabBilan['A31']=$tabBilanPre['A3'];
if (!isset($tabBilan['A41']) && isset($tabBilanPre['A4'])) $tabBilan['A41']=$tabBilanPre['A4'];
} elseif ($tabBilan['CONSOLIDE']=='S') {
// Calcul des chiffres net N-1 si absent 2033
if (!isset($tabBilanPre['013']) && (isset($tabBilanPre['010'])||isset($tabBilanPre['012'])))$tabBilanPre['013']=$tabBilanPre['010']-$tabBilanPre['012'];
if (!isset($tabBilanPre['017']) && (isset($tabBilanPre['014'])||isset($tabBilanPre['016'])))$tabBilanPre['017']=$tabBilanPre['014']-$tabBilanPre['016'];
if (!isset($tabBilanPre['031']) && (isset($tabBilanPre['028'])||isset($tabBilanPre['030'])))$tabBilanPre['031']=$tabBilanPre['028']-$tabBilanPre['030'];
if (!isset($tabBilanPre['043']) && (isset($tabBilanPre['040'])||isset($tabBilanPre['042'])))$tabBilanPre['043']=$tabBilanPre['040']-$tabBilanPre['042'];
if (!isset($tabBilanPre['049']) && (isset($tabBilanPre['044'])||isset($tabBilanPre['048'])))$tabBilanPre['049']=$tabBilanPre['044']-$tabBilanPre['048'];
if (!isset($tabBilanPre['053']) && (isset($tabBilanPre['050'])||isset($tabBilanPre['052'])))$tabBilanPre['053']=$tabBilanPre['050']-$tabBilanPre['052'];
if (!isset($tabBilanPre['063']) && (isset($tabBilanPre['060'])||isset($tabBilanPre['062'])))$tabBilanPre['063']=$tabBilanPre['060']-$tabBilanPre['062'];
if (!isset($tabBilanPre['067']) && (isset($tabBilanPre['064'])||isset($tabBilanPre['066'])))$tabBilanPre['067']=$tabBilanPre['064']-$tabBilanPre['066'];
if (!isset($tabBilanPre['071']) && (isset($tabBilanPre['068'])||isset($tabBilanPre['070'])))$tabBilanPre['071']=$tabBilanPre['068']-$tabBilanPre['070'];
if (!isset($tabBilanPre['075']) && (isset($tabBilanPre['072'])||isset($tabBilanPre['074'])))$tabBilanPre['075']=$tabBilanPre['072']-$tabBilanPre['074'];
if (!isset($tabBilanPre['083']) && (isset($tabBilanPre['080'])||isset($tabBilanPre['082'])))$tabBilanPre['083']=$tabBilanPre['080']-$tabBilanPre['082'];
if (!isset($tabBilanPre['087']) && (isset($tabBilanPre['084'])||isset($tabBilanPre['086'])))$tabBilanPre['087']=$tabBilanPre['084']-$tabBilanPre['086'];
if (!isset($tabBilanPre['091']) && (isset($tabBilanPre['088'])||isset($tabBilanPre['090'])))$tabBilanPre['091']=$tabBilanPre['088']-$tabBilanPre['090'];
if (!isset($tabBilanPre['095']) && (isset($tabBilanPre['092'])||isset($tabBilanPre['094'])))$tabBilanPre['095']=$tabBilanPre['092']-$tabBilanPre['094'];
if (!isset($tabBilanPre['099']) && (isset($tabBilanPre['096'])||isset($tabBilanPre['098'])))$tabBilanPre['099']=$tabBilanPre['096']-$tabBilanPre['098'];
if (!isset($tabBilanPre['113']) && (isset($tabBilanPre['110'])||isset($tabBilanPre['112'])))$tabBilanPre['113']=$tabBilanPre['110']-$tabBilanPre['112'];
// Récupération des chiffres N-1 si absent du bilan N
// ACTIF 2033
if (!isset($tabBilan['N00']) && isset($tabBilanPre['013'])) $tabBilan['N00']=$tabBilanPre['013'];
if (!isset($tabBilan['N01']) && isset($tabBilanPre['017'])) $tabBilan['N01']=$tabBilanPre['017'];
if (!isset($tabBilan['N02']) && isset($tabBilanPre['031'])) $tabBilan['N02']=$tabBilanPre['031'];
if (!isset($tabBilan['N03']) && isset($tabBilanPre['043'])) $tabBilan['N03']=$tabBilanPre['043'];
if (!isset($tabBilan['N04']) && isset($tabBilanPre['049'])) $tabBilan['N04']=$tabBilanPre['049'];
if (!isset($tabBilan['N05']) && isset($tabBilanPre['053'])) $tabBilan['N05']=$tabBilanPre['053'];
if (!isset($tabBilan['N06']) && isset($tabBilanPre['063'])) $tabBilan['N06']=$tabBilanPre['063'];
if (!isset($tabBilan['N07']) && isset($tabBilanPre['067'])) $tabBilan['N07']=$tabBilanPre['067'];
if (!isset($tabBilan['N08']) && isset($tabBilanPre['071'])) $tabBilan['N08']=$tabBilanPre['071'];
if (!isset($tabBilan['N09']) && isset($tabBilanPre['075'])) $tabBilan['N09']=$tabBilanPre['075'];
if (!isset($tabBilan['N10']) && isset($tabBilanPre['083'])) $tabBilan['N10']=$tabBilanPre['083'];
if (!isset($tabBilan['N11']) && isset($tabBilanPre['087'])) $tabBilan['N11']=$tabBilanPre['087'];
if (!isset($tabBilan['N12']) && isset($tabBilanPre['091'])) $tabBilan['N12']=$tabBilanPre['091'];
if (!isset($tabBilan['N13']) && isset($tabBilanPre['095'])) $tabBilan['N13']=$tabBilanPre['095'];
if (!isset($tabBilan['N14']) && isset($tabBilanPre['099'])) $tabBilan['N14']=$tabBilanPre['099'];
if (!isset($tabBilan['N15']) && isset($tabBilanPre['113'])) $tabBilan['N15']=$tabBilanPre['113'];
// PASSIF 2033
if (!isset($tabBilan['N16']) && isset($tabBilanPre['120'])) $tabBilan['N16']=$tabBilanPre['120'];
if (!isset($tabBilan['N17']) && isset($tabBilanPre['124'])) $tabBilan['N17']=$tabBilanPre['124'];
if (!isset($tabBilan['N18']) && isset($tabBilanPre['126'])) $tabBilan['N18']=$tabBilanPre['126'];
if (!isset($tabBilan['N19']) && isset($tabBilanPre['130'])) $tabBilan['N19']=$tabBilanPre['130'];
if (!isset($tabBilan['N20']) && isset($tabBilanPre['132'])) $tabBilan['N20']=$tabBilanPre['132'];
if (!isset($tabBilan['N21']) && isset($tabBilanPre['134'])) $tabBilan['N21']=$tabBilanPre['134'];
if (!isset($tabBilan['N22']) && isset($tabBilanPre['136'])) $tabBilan['N22']=$tabBilanPre['136'];
if (!isset($tabBilan['N23']) && isset($tabBilanPre['140'])) $tabBilan['N23']=$tabBilanPre['140'];
if (!isset($tabBilan['N24']) && isset($tabBilanPre['142'])) $tabBilan['N24']=$tabBilanPre['142'];
if (!isset($tabBilan['N25']) && isset($tabBilanPre['154'])) $tabBilan['N25']=$tabBilanPre['154'];
if (!isset($tabBilan['N26']) && isset($tabBilanPre['156'])) $tabBilan['N26']=$tabBilanPre['156'];
if (!isset($tabBilan['N27']) && isset($tabBilanPre['164'])) $tabBilan['N27']=$tabBilanPre['164'];
if (!isset($tabBilan['N28']) && isset($tabBilanPre['166'])) $tabBilan['N28']=$tabBilanPre['166'];
if (!isset($tabBilan['N29']) && isset($tabBilanPre['172'])) $tabBilan['N29']=$tabBilanPre['172'];
if (!isset($tabBilan['N30']) && isset($tabBilanPre['174'])) $tabBilan['N30']=$tabBilanPre['174'];
if (!isset($tabBilan['N31']) && isset($tabBilanPre['176'])) $tabBilan['N31']=$tabBilanPre['176'];
if (!isset($tabBilan['N32']) && isset($tabBilanPre['180'])) $tabBilan['N32']=$tabBilanPre['180'];
// COMPTE DE RESULTAT 2033
if (!isset($tabBilan['N33']) && isset($tabBilanPre['210'])) $tabBilan['N33']=$tabBilanPre['210'];
if (!isset($tabBilan['N34']) && isset($tabBilanPre['214'])) $tabBilan['N34']=$tabBilanPre['214'];
if (!isset($tabBilan['N35']) && isset($tabBilanPre['218'])) $tabBilan['N35']=$tabBilanPre['218'];
if (!isset($tabBilan['N36']) && isset($tabBilanPre['222'])) $tabBilan['N36']=$tabBilanPre['222'];
if (!isset($tabBilan['N37']) && isset($tabBilanPre['224'])) $tabBilan['N37']=$tabBilanPre['224'];
if (!isset($tabBilan['N38']) && isset($tabBilanPre['226'])) $tabBilan['N38']=$tabBilanPre['226'];
if (!isset($tabBilan['N39']) && isset($tabBilanPre['230'])) $tabBilan['N39']=$tabBilanPre['230'];
if (!isset($tabBilan['N40']) && isset($tabBilanPre['232'])) $tabBilan['N40']=$tabBilanPre['232'];
if (!isset($tabBilan['N41']) && isset($tabBilanPre['234'])) $tabBilan['N41']=$tabBilanPre['234'];
if (!isset($tabBilan['N42']) && isset($tabBilanPre['236'])) $tabBilan['N42']=$tabBilanPre['236'];
if (!isset($tabBilan['N43']) && isset($tabBilanPre['238'])) $tabBilan['N43']=$tabBilanPre['238'];
if (!isset($tabBilan['N44']) && isset($tabBilanPre['240'])) $tabBilan['N44']=$tabBilanPre['240'];
if (!isset($tabBilan['N45']) && isset($tabBilanPre['242'])) $tabBilan['N45']=$tabBilanPre['242'];
if (!isset($tabBilan['N46']) && isset($tabBilanPre['244'])) $tabBilan['N46']=$tabBilanPre['244'];
if (!isset($tabBilan['N47']) && isset($tabBilanPre['250'])) $tabBilan['N47']=$tabBilanPre['250'];
if (!isset($tabBilan['N48']) && isset($tabBilanPre['252'])) $tabBilan['N48']=$tabBilanPre['252'];
if (!isset($tabBilan['N49']) && isset($tabBilanPre['254'])) $tabBilan['N49']=$tabBilanPre['254'];
if (!isset($tabBilan['N50']) && isset($tabBilanPre['256'])) $tabBilan['N50']=$tabBilanPre['256'];
if (!isset($tabBilan['N51']) && isset($tabBilanPre['262'])) $tabBilan['N51']=$tabBilanPre['262'];
if (!isset($tabBilan['N52']) && isset($tabBilanPre['264'])) $tabBilan['N52']=$tabBilanPre['264'];
if (!isset($tabBilan['N53']) && isset($tabBilanPre['270'])) $tabBilan['N53']=$tabBilanPre['270'];
if (!isset($tabBilan['N54']) && isset($tabBilanPre['280'])) $tabBilan['N54']=$tabBilanPre['280'];
if (!isset($tabBilan['N55']) && isset($tabBilanPre['290'])) $tabBilan['N55']=$tabBilanPre['290'];
if (!isset($tabBilan['N56']) && isset($tabBilanPre['294'])) $tabBilan['N56']=$tabBilanPre['294'];
if (!isset($tabBilan['N57']) && isset($tabBilanPre['300'])) $tabBilan['N57']=$tabBilanPre['300'];
if (!isset($tabBilan['N58']) && isset($tabBilanPre['306'])) $tabBilan['N58']=$tabBilanPre['306'];
if (!isset($tabBilan['N59']) && isset($tabBilanPre['310'])) $tabBilan['N59']=$tabBilanPre['310'];
} elseif ($tabBilan['CONSOLIDE']=='A' || $tabBilan['CONSOLIDE']=='B') {
// BANQUES
if (!isset($tabBilan['NA1']) && isset($tabBilanPre['AA1'])) $tabBilan['NA1']=$tabBilanPre['AA1'];
if (!isset($tabBilan['NA2']) && isset($tabBilanPre['AA2'])) $tabBilan['NA2']=$tabBilanPre['AA2'];
if (!isset($tabBilan['NA3']) && isset($tabBilanPre['AA3'])) $tabBilan['NA3']=$tabBilanPre['AA3'];
if (!isset($tabBilan['NP1']) && isset($tabBilanPre['AP1'])) $tabBilan['NP1']=$tabBilanPre['AP1'];
if (!isset($tabBilan['NP2']) && isset($tabBilanPre['AP2'])) $tabBilan['NP2']=$tabBilanPre['AP2'];
if (!isset($tabBilan['NP3']) && isset($tabBilanPre['AP3'])) $tabBilan['NP3']=$tabBilanPre['AP3'];
if (!isset($tabBilan['NP4']) && isset($tabBilanPre['AP4'])) $tabBilan['NP4']=$tabBilanPre['AP4'];
if (!isset($tabBilan['NP5']) && isset($tabBilanPre['AP5'])) $tabBilan['NP5']=$tabBilanPre['AP5'];
if (!isset($tabBilan['NP6']) && isset($tabBilanPre['AP6'])) $tabBilan['NP6']=$tabBilanPre['AP6'];
if (!isset($tabBilan['NP7']) && isset($tabBilanPre['AP7'])) $tabBilan['NP7']=$tabBilanPre['AP7'];
if (!isset($tabBilan['NP8']) && isset($tabBilanPre['AP8'])) $tabBilan['NP8']=$tabBilanPre['AP8'];
if (!isset($tabBilan['NP9']) && isset($tabBilanPre['AP9'])) $tabBilan['NP9']=$tabBilanPre['AP9'];
if (!isset($tabBilan['NR1']) && isset($tabBilanPre['AR1'])) $tabBilan['NR1']=$tabBilanPre['AR1'];
if (!isset($tabBilan['NR2']) && isset($tabBilanPre['AR2'])) $tabBilan['NR2']=$tabBilanPre['AR2'];
if (!isset($tabBilan['NR3']) && isset($tabBilanPre['AR3'])) $tabBilan['NR3']=$tabBilanPre['AR3'];
// ASSURANCE
if (!isset($tabBilan['NR4']) && isset($tabBilanPre['AR4'])) $tabBilan['AR4']=$tabBilanPre['AR4'];
}
}
return $tabBilan;
}
/** Conversion des bilans Simplifiés en Réels Normal
** @param $bilanRS array Bilan au format réel simplifé (2033)
** @return array Bilan au format réel Normal (2050)
*/
function bilanSimplifie2Normal($bilanRS) {
$bilanRN=array();
foreach ($this->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;
}
}
?>