extranet/www/pages/liasse.php

325 lines
9.3 KiB
PHP

<?php
// --------------------------------------------------------------------------- //
// 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('&nbsp;', '', $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;
}
}
if (!page_checkParams()) die('Paramètres incorrects !');
$mil = false;
require_once 'partenaires/classMTva.php';
require_once 'partenaires/classMMap.php';
require_once 'common/dates.php';
require_once 'cache/cache.php';
require_once 'liasse/liasse.php';
if (($siret*1)==0 || ($siren*1)<100){ $fileName = $page.'-'.$idEntreprise;
}else{ $fileName = $page.'-'.$siret; }
if(isset($_REQUEST['mil'])){
$mil = explode(',',$_REQUEST['mil']);
$annee = substr($mil[0],-10);
$annee = str_replace('/', '', $annee);
$indice = str_replace('/', '', substr($mil[0], 0, 11));
$fileName.= '-'.$indice;
}
isset($_REQUEST['unit']) ? $unite = $_REQUEST['unit'] : $unite = '';
$typBil = array(
'C'=>'Consolidé',
'N'=>'',
'S'=>'Réel Simplifié',
'B'=> 'Banque',
'A'=>'Assurance'
);
cache_filename($fileName);
if( cache_exist() && !hasModeEdition() )
{
$tabBilans = cache_get('tabBilans');
$tabBilan = cache_get('tabBilan');
}else{
try {
$O = $client->getListeBilans($siren);
$tabBilans = $O['result'];
//Tri du tableau
if(count($tabBilans)>0)
{
foreach($tabBilans as $key => $bilan)
{
$cle[$key] = $key[0].substr($key, -4);
$dateProvPartenaire[$key] = $bilan['dateProvPartenaire'];
$dateInsert[$key] = $bilan['dateInsert'];
$dureeExercice[$key] = $bilan['dureeExercice'];
$dateExercicePre[$key] = $bilan['dateExercicePre'];
$monnaie[$key] = $bilan['monnaie'];
$source[$key] = $bilan['source'];
}
array_multisort($cle, SORT_DESC, $tabBilans);
}
cache_delete();
cache_add('tabBilans', $tabBilans);
if (isset($_REQUEST['mil']))
{
$O = $client->getBilan($siren, substr($mil[0],-10), substr($mil[0],0,1), $mil[1]);
$tabBilan = $O['result'];
cache_add('tabBilan',$tabBilan);
}
} catch (SoapFault $fault) {
require_once 'soaperror.php';
processSoapFault($client,$fault,$_SESSION['tabInfo']);
die();
}
}
?>
<style type="text/css">
.tabLiasse { font-size:1em;}
</style>
<div id="center">
<h1 class="titre">&Eacute;L&Eacute;MENTS FINANCIERS - BILANS</h1>
<form action="./" method="get">
<table>
<tr>
<td width="30">&nbsp;</td>
<td width="200" class="StyleInfoLib">Num&eacute;ro identifiant Siren</td>
<td width="350" class="StyleInfoData"><?=substr($siren,0,3).' '.substr($siren,3,3).' '.substr($siren,6,3)?></td>
</tr>
<tr>
<td width="30">&nbsp;</td>
<td width="200" class="StyleInfoLib">Raison Sociale</td>
<td width="350" class="StyleInfoData"><?=$raisonSociale?></td>
</tr>
<?php
if (count($tabBilans)>0)
{
$tabUnit = array(
0 => array('lib'=>'€', 'val'=>''),
1 => array('lib'=>'K€', 'val'=>'K'),
2 => array('lib'=>'M€', 'val'=>'M'),
);
?>
<tr>
<td width="30">&nbsp;</td>
<td width="200" class="StyleInfoLib">Valeurs exprimées en</td>
<td width="350" class="StyleInfoData">
<select name="unit">
<?php
foreach($tabUnit as $unit)
{
$select = '';
if($unite == $unit['val']) $select = ' selected';
?><option value="<?=$unit['val']?>"<?=$select?>><?=$unit['lib']?></option><?php
}
?>
</select>
</td>
</tr>
<?php
}
?>
<tr>
<td width="30">&nbsp;</td>
<td width="200" class="StyleInfoLib">Millesime</td>
<td width="350" class="StyleInfoData">
<?
if (count($tabBilans)>0)
{
?>
<input type="hidden" name="page" value="liasse"/>
<input type="hidden" name="siret" value="<?=$siren?>"/>
<select name="mil">
<?php
//Tri de l'affichage des bilans en fonction de leurs types
foreach($typBil as $keyType => $type)
{
$numBil=0;
foreach ($tabBilans as $millesime => $bilan)
{
if($numBil>=5){ break; }
if( $millesime[0] == $keyType )
{
echo '<option value="'.$millesime.','.$bilan['ref'].'"';
if ($mil[0]==$millesime) echo ' selected';
$str=' '. $typBil[substr($millesime,0,1)];
echo '>'. substr($millesime,-10) . $str .'</option>';
$numBil++;
}
}
}
?>
</select>&nbsp;
<input type="submit" value="Ok"/>
<?php
} else {
?>
<b>Aucun bilan disponible pour cette entreprise !</b>
<?php
}
?>
</td>
</tr>
</table>
</form>
<div class="blockh2">
<?php
/** Si un bilan est sélectionné dans la liste, on affiche le bilan **/
if(isset($_REQUEST['mil']) == true) {
$mil = $_REQUEST['mil'];
if ($mil[0] == 'A') {
include 'liasse/bilan_assurance.php';
} else if ($mil[0] == 'B') {
include 'liasse/bilan_banque.php';
} else {
include 'liasse/bilan_normal.php';
// Export
require_once 'export.php';
if (isset($siret) == true) {
$fileName = $page.'-'.$siret;
} else {
$fileName = $page.'-'.$idEntreprise;
}
$liasse['Liasse']['raisonSociale'] = $raisonSociale;
$liasse['Liasse']['type'] = $mil[0];
$liasse['Liasse']['date'] = $annee;
liasse2xml($tabLiasseN, $liasse, $tableTexteBilan);
$parseTab = new tabExport;
$parseTab->tab = array($liasse['Liasse']);
$parseTab->type = array();
$array2csv = new ExportCSV;
$array2csv->records = $parseTab->convertTable();
$array2csv->writeCSV($fileName);
$array2xml = new ExportXML;
$array2xml->rootName = $page;
$array2xml->defaultTagName = 'elem';
$array2xml->records = $liasse['Liasse'];
$array2xml->writeXML($fileName);
} // Fin test bilan banque ou assurance et autres
} // Fin if "pas de bilan choisit"
?>
</div>
<table>
<tr>
<td width="30">&nbsp;</td>
<td colspan="2" width="550" class="StyleInfoData">
<?php
require_once 'surveillance/surveillance.php';
echo getSurveillance('bilans', $siret);
?>
</td>
</tr>
</table>
<p class="confidentiel blockh2">
<?php
require_once 'cgu/cgu.php';
echo afficheCgu();
?>
</p>
</div>