extranet/library/Finance/Finance.lib.php
Damien LASSERRE bdf5a954db création de la lib de gestion ratiosDatas.
avec les consignes de mickael.

Mise en place de 4 fonctions : 
getRatios..... etc...
2011-06-22 13:00:17 +00:00

239 lines
11 KiB
PHP

<?php
require_once 'common/dates.php';
require_once 'Finance/OtherFunctions.lib.php';
require_once 'Finance/RatiosGraph.lib.php';
require_once 'Scores/WsScores.php';
Class FinanceLib
{
private $dateFunction;
private $siret;
private $idSC;
private $graphique;
public function __construct($siret, $idSC) {
$this->dateFunction = new WDate();
$this->graphique = new Graphique(APPLICATION_PATH . '/../cache/pages/imgcache/');
$this->siret = $siret;
$this->idSC = $idSC;
}
/**
*/
public function getRatiosValeur($date, $id, $type, $ratios)
{
$ratio = self::getRatios($ratios, 'entreprise');
foreach($ratio[$date][$type] as $element) {
if ($element->id == $id)
return ($element->val);
}
}
public function getRatios($ratios, $RatioType)
{
$retour = array();
foreach($ratios->BilansInfos->item as $item) {
if ($RatioType == 'entreprise') {
$retour[$item->dateCloture][$item->typeBilan] = $item->RatiosEntrep->item;
} else if($RatioType == 'secteur') {
echo "";
}
}
return ($retour);
}
public function rsynthese($synthese, $idsReference, &$tabAnnee, &$final)
{
$OtherFunction = new OtherFunction();
foreach ($synthese->BilansInfos->item as $item) {
$annee = substr($item->dateCloture, 0, 4);
if( $annee >= substr($synthese->BilansInfos->item[0]->dateCloture, 0, 4)-2) {
$tabAnnee[$this->dateFunction->dateT('Ymd', 'd/m/Y', $item->dateCloture)] = $item->duree;
foreach ($item->RatiosEntrep->item as $RatiosEntrep) {
foreach($idsReference as $id => $elements) {
if ($RatiosEntrep->id == $id) {
$final[$id.':'.$elements['titre']][$item->dateCloture] =
array('Valeur' => $RatiosEntrep->val/1000,
'percent' => $OtherFunction->getReference($RatiosEntrep->val, $elements['total'], $annee, $synthese), 'id' => $id);
ksort($final[$id.':'.$elements['titre']]);
}
}
}
}
}
ksort($tabAnnee);
}
public function synthese($synthese, $bilanReference, $typeBilan, $RatiosGraph)
{
$OtherFunction = new OtherFunction();
$RatiosGraph = new RatiosGraph($this->siret, $this->idSC);
foreach ($synthese->BilansInfos->item as $item) {
if ($item->typeBilan == $typeBilan) {
foreach ($item->RatiosEntrep->item as $RatiosEntrep) {
foreach ($bilanReference as $id => $params) {
if ($RatiosEntrep->id == $id) {
$bilan[$id]['name'] = $params['name'];
$bilan[$id]['unite'] = $params['unite'];
$bilan[$id]['commentaires'] = $params['commentaires'];
if (count($bilan[$id]['item']) <= 2) {
if (is_numeric($RatiosEntrep->val))
$valeur = number_format(($RatiosEntrep->val / $params['operateur']), 0, '', ' ');
$bilan[$id]['item'][$item->dateCloture]['ValEntrep'] = $valeur;}
$this->graphique->GraphiqueLineXY($RatiosGraph->GraphiqueSyntheseLine($id, $synthese,
$item->typeBilan, $OtherFunction->maskNameImg('synthese', $this->siret, array($id,$item->typeBilan))), true); } } }
foreach ($item->RatiosEntrepEvol->item as $RatiosEntrepEvol) {
foreach ($bilanReference as $id => $params) {
if ($RatiosEntrepEvol->id == $params['evolution']) {
if (array_key_exists($item->dateCloture, $bilan[$id]['item'])) {
$bilan[$id]['item'][$item->dateCloture]['duree'] = $item->duree;
$bilan[$id]['item'][$item->dateCloture]['ValEntrepEvol'] = $RatiosEntrepEvol->val; } } } }
}
}
foreach ($bilan as $id => $val)
ksort($bilan[$id]['item']);
return ($bilan);
}
public function constructElementForBilan($bilan, $tableauDeReference, &$type, &$date, &$duree, $typebilan)
{
foreach($bilan->BilansInfos->item as $element) {
if($element->typeBilan == $typebilan)
{
if($duree == EOF)
$duree = $element->duree;
if (@count($date) < 5) {
if(!in_array($element->dateCloture, $date))
$date[] = $element->dateCloture;
}
foreach($element->RatiosEntrep->item as $item) {
foreach($tableauDeReference as $id => $valeur) {
if ($item->id == $id) {
if (count($type[$id]['item']) < 5) {
if ($item->val > 0) {
$type[$id]['item'][$element->dateCloture] = $item->val / 1000;
}
else
$type[$id]['item'][$element->dateCloture] = 'NS';
}
}
}
}
}
}
foreach ($type as $id => $valeur) {
$type[$id]['item'] = array_reverse($valeur['item']);
}
$date = array_reverse($date);
}
public function specialSIG($id, $element, $partial, $count)
{
$OtherFunction = new OtherFunction();
if($element != 'NS') {
if ($id == 'r101')
return $OtherFunction->Tb($element, $element) - $OtherFunction->Tb($partial['r122']['item'][$count], $partial['r101']['item'][$count]);
else if ($id == 'r122')
return $OtherFunction->Tb($element, $partial['r101']['item'][$count]) - $OtherFunction->Tb($partial['r130']['item'][$count], $partial['r101']['item'][$count]);
else if ($id == 'r130')
return $OtherFunction->Tb($element, $partial['r101']['item'][$count]) - $OtherFunction->Tb($partial['r140']['item'][$count], $partial['r101']['item'][$count]);
else if ($id == 'r140')
return $OtherFunction->Tb($element, $partial['r101']['item'][$count]) - $OtherFunction->Tb($partial['r150']['item'][$count], $partial['r101']['item'][$count]);
else if ($id == 'r150')
return $OtherFunction->Tb($element, $partial['r101']['item'][$count]) - $OtherFunction->Tb($partial['r170']['item'][$count], $partial['r101']['item'][$count]);
else if ($id == 'r170')
return $OtherFunction->Tb($element, $partial['r101']['item'][$count]) - $OtherFunction->Tb($partial['r199']['item'][$count], $partial['r101']['item'][$count]);
else if ($id == 'r199')
return $OtherFunction->Tb($element, $partial['r101']['item'][$count]);
} else
return (null);
}
public function LineBilan(&$tableauBilanGraphique, $helper, $id, $Graphdate, $partial, $reference, $name, $url, $siren, $sig = false)
{
$i = 0;
$this->column = 0;
$GraphLine = array();
$OtherFunction = new OtherFunction();
$RatiosGraph = new RatiosGraph($this->siret, $this->idSC);
/** Ont enregistre les données (premié temps) **/
foreach($partial[$id]['item'] as $element) {
if($element != 'NS'){ $GraphLine[] = $number = $element; }else{$number = 0; $GraphLine[] = 0;};
if($sig) {
$result = self::specialSIG($id, $element, $partial, $i);
if(is_numeric($result))
$gr[] = ($result < 0)?0:$result;
}
else
if($OtherFunction->createlementForGraphique($id))$gr[] = $number;
}
($gr != 0)?$tableauBilanGraphique = $gr:$tableauBilanGraphique = false;
/** Ont affiche les données (deuxiéme temps) **/
$html .= '<tr '.(($OtherFunction->ifIsHead($id))?'class="subhead"':'class="bilanDatas"').'>';
$html .= '<td>'.$name.'</td>';
foreach($partial[$id]['item'] as $element) {
$html .= '<td align="right">' . (($element != 'NS') ? number_format($element, 0, '', ' ') . ' K€':$element).'</td>';
}
$html .= '<td align="right">'.$OtherFunction->Tb(end($partial[$id]['item']), end($partial[$reference]['item'])).'</td>';
$image = $RatiosGraph->GraphiqueLineBilan($GraphLine, $RatiosGraph->maskNameImg('bilan', $this->siret, array($id)), $Graphdate);
$html .= '<td>';
$datas = implode('|', $GraphLine);
$dates = implode('|', $Graphdate);
$html .= '<a name="Actif Immobilisé Net" class="rTip" rel="'.$url.'" href="'.$helper->url(
'onelinebilan','finance', null,
array('data'=> $datas,
'name' => urlencode($name),
'dates' => $dates,
'image' => $image)).'">
<img src="/themes/default/images/finance/char_bar.png" />
</a>';
$html .= '</td>';
$html .= '</tr>';
return ($html);
}
public function compareValeur($valeurEnt, $valeurSec, $compare, $valeur = false)
{
$ecart = 1/100;
if( $valeurSec=='NS' || $valeurEnt == 'NS' || $valeurSec==NULL || $valeurEnt==NULL) {
return ('-');
} else if ($compare == '>') {
if (($valeurEnt + $ecart) > $valeurSec) {
if($valeur)
$return = 'bon';
else $return = '<img src="/themes/default/images/finance/ratios_bon.png" />';
} elseif(($valeurSec - ($valeurSec * $ecart)) < $valeurEnt && ($valeurSec + ($valeurSec * $ecart)) > $valeurEnt) {
if($valeur)
$return = 'neutre';
else $return = '-';
} else {
if($valeur)
$return = 'mauvais';
else $return = '<img src="/themes/default/images/finance/ratios_mauvais.png" />';
}
} else if ($compare == '<') {
if ($valeurEnt < $valeurSec) {
if($valeur)
$return = 'bon';
else $return = '<img src="/themes/default/images/finance/ratios_bon.png" />';
} elseif( ($valeurSec - ($valeurSec * $ecart)) < $valeurEnt && ($valeurSec + ($valeurSec * $ecart)) > $valeurEnt) {
if($valeur)
$return = 'neutre';
else $return = '-';
} else {
if($valeur)
$return = 'mauvais';
else $return = '<img src="/themes/default/images/finance/ratios_mauvais.png" />';
}
}
return ($return);
}
}