2013-10-17 13:58:43 +00:00

236 lines
5.0 KiB
PHP

<?php
class Scores_Finance_Liasse
{
protected $postes = array();
protected $info = array();
protected $div;
protected $unit = array (
'E' => 1,
'K' => 1000,
'M' => 1000000,
);
public function __construct($liasse, $unit = 'K')
{
$this->div = $this->unit[$unit];
$this->setData($liasse);
}
protected function setData($data)
{
$this->info = array(
'dateFraicheBilan' => $data->DATE_FRAICHE_BILAN,
'dateCloture' => $data->DATE_CLOTURE,
'dateCloturePre' => $data->DATE_CLOTURE_PRE,
'dureeMois' => $data->DUREE_MOIS,
'dureeMoisPre' => $data->DUREE_MOIS_PRE,
'monnaie' => $data->MONNAIE,
'monnaieOri' => $data->MONNAIE_ORI,
'monnaieLivUnite' => $data->MONNAIE_LIV_UNITE,
'consolide' => $data->CONSOLIDE,
'source' => $data->SOURCE,
);
//Affectaction des postes
foreach ($data->POSTES->item as $element){
if (in_array($element->id, array(
'YP', 'YP1', '376', // Effectifs 2033 et 2050
'M2G', 'M2H', // Autres effectifs
'ZK', 'ZK1', // Taux
'IJ', 'JG', 'JH', 'JJ', 'ZR', // pour holding/ste mere
'XP' //numero de centre de gestion agréé
)))
{
$this->postes[$element->id] = number_format($element->val, 0, '', ' ');
} else {
$this->postes[$element->id] = $this->dMontant($element->val);
}
}
//Transformation Simplifié en Normal
if ( $data->CONSOLIDE == 'S'){
$this->postes = $this->bilanSimplifie2Normal($this->postes);
}
}
public function getInfo($key)
{
return $this->info[$key];
}
public function getPostes()
{
return $this->postes;
}
protected function dMontant($montant)
{
return number_format($montant/$this->div, 0, '', ' ');
}
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',
//@todo : Traiter N-1
);
$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;
}
}