diff --git a/library/Finance/Finance.lib.php b/library/Finance/Finance.lib.php
new file mode 100644
index 000000000..5b4f07a06
--- /dev/null
+++ b/library/Finance/Finance.lib.php
@@ -0,0 +1,239 @@
+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 .= '
ifIsHead($id))?'class="subhead"':'class="bilanDatas"').'>';
+ $html .= ''.$name.' | ';
+ foreach($partial[$id]['item'] as $element) {
+ $html .= '' . (($element != 'NS') ? number_format($element, 0, '', ' ') . ' K€':$element).' | ';
+ }
+ $html .= ''.$OtherFunction->Tb(end($partial[$id]['item']), end($partial[$reference]['item'])).' | ';
+ $image = $RatiosGraph->GraphiqueLineBilan($GraphLine, $RatiosGraph->maskNameImg('bilan', $this->siret, array($id)), $Graphdate);
+ $html .= '';
+ $datas = implode('|', $GraphLine);
+ $dates = implode('|', $Graphdate);
+ $html .= '
+
+ ';
+ $html .= ' | ';
+ $html .= '
';
+ 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 = '';
+ } elseif(($valeurSec - ($valeurSec * $ecart)) < $valeurEnt && ($valeurSec + ($valeurSec * $ecart)) > $valeurEnt) {
+ if($valeur)
+ $return = 'neutre';
+ else $return = '-';
+ } else {
+ if($valeur)
+ $return = 'mauvais';
+ else $return = '';
+ }
+ } else if ($compare == '<') {
+ if ($valeurEnt < $valeurSec) {
+ if($valeur)
+ $return = 'bon';
+ else $return = '';
+ } elseif( ($valeurSec - ($valeurSec * $ecart)) < $valeurEnt && ($valeurSec + ($valeurSec * $ecart)) > $valeurEnt) {
+ if($valeur)
+ $return = 'neutre';
+ else $return = '-';
+ } else {
+ if($valeur)
+ $return = 'mauvais';
+ else $return = '';
+ }
+ }
+ return ($return);
+ }
+}
\ No newline at end of file
diff --git a/library/Finance/RatiosData.lib.php b/library/Finance/RatiosData.lib.php
index 8f525eea0..28188ad0e 100644
--- a/library/Finance/RatiosData.lib.php
+++ b/library/Finance/RatiosData.lib.php
@@ -1,239 +1,56 @@
dateFunction = new WDate();
- $this->graphique = new Graphique(APPLICATION_PATH . '/../cache/pages/imgcache/');
- $this->siret = $siret;
- $this->idSC = $idSC;
+ public function __construct($ratios, $typeDelete = array('S'))
+ {
+ foreach ($ratios->RatiosInfos->item as $item) {
+ $this->ratiosInfos[$item->id] = $item;
+ }
+ foreach ($ratios->BilansInfos->item as $item) {
+ if (self::ignoreType($item->type, $typeDelete)) {
+ $this->bilansInfo[$item->type.':'.$item->dateCloture] = $item;
+ foreach ($item->RatiosEntrep->item as $ratios)
+ $this->ratiosEntrep[$item->type.':'.$item->datecloture][$ratios->id] = $ratios->val;
+ foreach ($item->ratiosEntrepEvol->item as $ratios)
+ $this->ratiosEntrepEvol[$item->type.':'.$item->dateCloture][$ratios->id] = $ratios->val;
+ }
+ }
+ foreach ($ratios->RatiosSecteur->item as $item) {
+ foreach ($item->liste->item as $ratios)
+ $this->ratiosSecteur[$item->anneee][$ratios->id] = $ratios->val;
+ }
}
- /**
- */
- 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 getRatiosInfos($id) {
+ return ($this->ratiosInfos[$id]);
+ }
+
+ public function getRatiosEntrep($type, $dateCloture, $id) {
+ return ($this->ratiosEntrep[$type.':'.$dateCloture][$id]);
+ }
+
+ public function getRatiosEntrepEvol($type, $dateCloture, $id) {
+ return ($this->ratiosEntrepEvol[$type.':'.$dateCloture][$id]);
+ }
+
+ public function getRatiosSecteur($annee, $id) {
+ return ($this->ratiosSecteur[$annee][$id]);
+ }
+
+ public function __toString() {
+ return ($this->ratiosEntrep);
+ }
+
+ private function ignoreType($type, $typeDelete) {
+ foreach ($typeDelete as $t) {
+ if ($t == $type) return (false);
}
+ return (true);
}
-
- 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 .= 'ifIsHead($id))?'class="subhead"':'class="bilanDatas"').'>';
- $html .= ''.$name.' | ';
- foreach($partial[$id]['item'] as $element) {
- $html .= '' . (($element != 'NS') ? number_format($element, 0, '', ' ') . ' K€':$element).' | ';
- }
- $html .= ''.$OtherFunction->Tb(end($partial[$id]['item']), end($partial[$reference]['item'])).' | ';
- $image = $RatiosGraph->GraphiqueLineBilan($GraphLine, $RatiosGraph->maskNameImg('bilan', $this->siret, array($id)), $Graphdate);
- $html .= '';
- $datas = implode('|', $GraphLine);
- $dates = implode('|', $Graphdate);
- $html .= '
-
- ';
- $html .= ' | ';
- $html .= '
';
- 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 = '';
- } elseif(($valeurSec - ($valeurSec * $ecart)) < $valeurEnt && ($valeurSec + ($valeurSec * $ecart)) > $valeurEnt) {
- if($valeur)
- $return = 'neutre';
- else $return = '-';
- } else {
- if($valeur)
- $return = 'mauvais';
- else $return = '';
- }
- } else if ($compare == '<') {
- if ($valeurEnt < $valeurSec) {
- if($valeur)
- $return = 'bon';
- else $return = '';
- } elseif( ($valeurSec - ($valeurSec * $ecart)) < $valeurEnt && ($valeurSec + ($valeurSec * $ecart)) > $valeurEnt) {
- if($valeur)
- $return = 'neutre';
- else $return = '-';
- } else {
- if($valeur)
- $return = 'mauvais';
- else $return = '';
- }
- }
- return ($return);
- }
}
\ No newline at end of file