285 lines
7.6 KiB
PHP
285 lines
7.6 KiB
PHP
<?php
|
|
function bilanSimplifie2Normal($bilanRS) {
|
|
$tabBS2BN=array('AH'=>'010',
|
|
'AI'=>'012',
|
|
'AJ'=>'014',
|
|
'AK'=>'016',
|
|
'AT'=>'028',
|
|
'AU'=>'030',
|
|
'BH'=>'040',
|
|
'BI'=>'042',
|
|
'BJ'=>'044',
|
|
'BK'=>'048',
|
|
'BT'=>'060',
|
|
'BU'=>'062',
|
|
'BV'=>'064',
|
|
'BW'=>'066',
|
|
'BX'=>'068',
|
|
'BY'=>'070',
|
|
'BZ'=>'072',
|
|
'CA'=>'074',
|
|
'CD'=>'080',
|
|
'CE'=>'082',
|
|
'CF'=>'084',
|
|
'CG'=>'086',
|
|
'CH'=>'092',
|
|
'CI'=>'094',
|
|
'CJ'=>'096',
|
|
'CK'=>'098',
|
|
'CO'=>'110',
|
|
'1A'=>'112',
|
|
'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 bilanMonnaie($value, $unite = '')
|
|
{
|
|
switch($unite)
|
|
{
|
|
case 'K':
|
|
$div = 1000;
|
|
break;
|
|
case 'M':
|
|
$div = 1000*1000;
|
|
break;
|
|
default:
|
|
case '':
|
|
$div = 1;
|
|
break;
|
|
}
|
|
if(isset($value) && !empty($value)){
|
|
return number_format($value/$div, 0, '', ' ');
|
|
}else{
|
|
return '-';
|
|
}
|
|
}
|
|
|
|
function dMontant(&$tab, $montant, $unite = '')
|
|
{
|
|
if ($montant == '' || isset($tab[$montant]) == false) {
|
|
return '';
|
|
}
|
|
switch ($unite) {
|
|
case 'K':
|
|
$div = 1000;
|
|
break;
|
|
case 'M':
|
|
$div = 1000000;
|
|
break;
|
|
default:
|
|
$div = 1;
|
|
}
|
|
return number_format($tab[$montant] / $div, 0, '', ' ');
|
|
}
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
// liasse2xml
|
|
// -------------------------------------------------------------------------- //
|
|
function liasse2xml(&$val, &$liasse, &$tableTexteBilan)
|
|
{
|
|
global $tabBilan;
|
|
global $unite;
|
|
|
|
if (is_array($val)) {
|
|
$label = 'Elem';
|
|
foreach ($val as $n => $vniv2) {
|
|
$lniv2 = '';
|
|
if (liasse2xml($vniv2, $lniv2, $tableTexteBilan) == true) {
|
|
if (is_array($lniv2) == false) {
|
|
$lniv2 = strip_tags(str_replace('-<br/>', '', $lniv2));
|
|
if ($label == 'Elem') {
|
|
$label = $lniv2;
|
|
} else {
|
|
$label .= ' '.$lniv2;
|
|
}
|
|
$label = strtr(utf8_decode($label),
|
|
utf8_decode(' .àéèêôÔç(),:\''),
|
|
'__aeeeoOc_____');
|
|
$count = 1;
|
|
while ($count) {
|
|
$label = str_replace('__', '_', $label, $count);
|
|
}
|
|
$label = preg_replace('/_$/', '', $label);
|
|
$label = preg_replace('/^_/', '', $label);
|
|
}
|
|
if ( isset($val[$n + 1]) == true &&
|
|
is_array($val[$n + 1]) == true) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (is_numeric(substr($label, 0, 1)) == true) {
|
|
$label = '_'.$label;
|
|
}
|
|
if ($n == count($val) - 1) {
|
|
$n = 0;
|
|
} else {
|
|
++$n;
|
|
}
|
|
for ($i = $n; $i < count($val); ++$i) {
|
|
$lniv2 = '';
|
|
if (liasse2xml($val[$i], $lniv2, $tableTexteBilan) == true) {
|
|
if (isset($liasse[$label]) == true) {
|
|
if (is_array($liasse[$label]) == true) {
|
|
$liasse[$label] = array_merge($liasse[$label], $lniv2);
|
|
} else if (is_numeric($lniv2) == true) {
|
|
$liasse[$label] = $lniv2;
|
|
}
|
|
} else if (is_array($lniv2) ||
|
|
is_numeric($lniv2) == true) {
|
|
$liasse[$label] = $lniv2;
|
|
}
|
|
}
|
|
}
|
|
return empty($liasse) == false;
|
|
} else {
|
|
if ( empty($val) == false &&
|
|
is_int($val) == false && $val != '#') {
|
|
if (substr($val, 0, 4) == 'text') {
|
|
$val = $tableTexteBilan[intval(substr($val, 4, 4))];
|
|
}
|
|
$val = str_replace(' ', '', $val);
|
|
if (substr($val, 0, 1) != '(') {
|
|
$val = preg_replace('/\(.*\)/', '', $val);
|
|
}
|
|
if (empty($val) == false) {
|
|
if (strlen($val) == 3 && substr($val, 0, 1) != '(') {
|
|
$m = dMontant($tabBilan, $val, $unite);
|
|
if (empty($m) == false) {
|
|
if (is_numeric(substr($val, 0, 1)) == true) {
|
|
$val = '_'.$val;
|
|
}
|
|
$liasse[$val] = $m;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else if (strlen($val) == 2) {
|
|
$m = dMontant($tabBilan, $val, $unite);
|
|
if (empty($m) == false) {
|
|
if (is_numeric(substr($val, 0, 1)) == true) {
|
|
$val = '_'.$val;
|
|
}
|
|
$liasse[$val] = $m;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
$liasse = $val;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|