siret = $siret;
$this->SCid = $SCid;
$this->imageCachePath = APPLICATION_PATH . '/../cache/pages/imgcache/';
$this->graphique = new Graphique($this->imageCachePath);
}
public function maskNameImg($action, $siret, $others = EOF)
{
$name = $action.'-'.$siret;
if($others != EOF) {
foreach($others as $other) {
$name .= '-'.$other;
}
}
$name .= '.png';
return ($name);
}
public function getValFromKey($stdClass, $key)
{
foreach($stdClass as $element) {
if ($element->id == $key)
return ($element->val/1000);
}
}
public function trieType($data, $idType)
{
$type = array();
foreach($data as $item)
{
if($item->typeBilan == 'N')
$type['N'][] = $item;
else if($item->typeBilan == 'C')
$type['C'][] = $item;
}
return ($type[$idType]);
}
public function createAbscisseSynthese($synthese, $id, &$labelX, $type)
{
$dataX1 = array();
foreach ($synthese->BilansInfos->item as $item) {
if ($item->typeBilan == $type) {
$labelX[] = substr($item->dateCloture, 0, 4);
foreach ($item->RatiosEntrep->item as $RatiosEntrep) {
if ($RatiosEntrep->id == $id) {
if (is_numeric($RatiosEntrep->val))
$dataX1[] = ($RatiosEntrep->val / 1000);
}
}
}
}
$labelX = array_reverse($labelX);
$dataX1 = array_reverse($dataX1);
return ($dataX1);
}
public function GraphiqueSyntheseLine($id, $synthese, $type, $name)
{
$labelX = array();
$parametres = new stdClass();
$parametres->nom = $name;
$parametres->datas = array(self::createAbscisseSynthese($synthese,$id, $labelX, $type));
$parametres->TitlesY = array(array("Keuros"));
$parametres->TitlesX = array(array("Années"));
$parametres->LineLayer = array("Entreprise");
$parametres->labelsY = array();
$parametres->labelsX = $labelX;
return ($parametres);
}
public function GraphiqueSyntheseAnalyse($data, $type, $siret)
{
//Définition des valeurs pour le graph
$dataBFR = array();
$dataFR = array();
$dataCA = array();
$BFR = array();
$i = 0;
$nbAnnees = 0;
$data = self::trieType($data, $type);
//Tri des données par date et par ordre croissant
foreach ($data as $key => $row) { $date[$key] = $row->dateCloture; }
array_multisort($date, SORT_ASC, $data);
if(count($data)>5)
$data = array_slice($data, count($data)-5, null, true);
//Parcourir les années
foreach($data as $item) {
$anneeFin = substr($item->dateCloture,0,4);
$moisFin = substr($item->dateCloture,4,2);
$jourFin = substr($item->dateCloture,6,2);
//Calcul de la date de début
$dateDebut = date("Ymd", mktime(0, 0, 0, $moisFin-$item->duree, $jourFin, $anneeFin));
$anneeDebut = substr($dateDebut,0,4);
$moisDebut = substr($dateDebut,4,2);
$jourDebut = substr($dateDebut,6,2);
//Affectation des abscisses
$dataBFR['x'][$i] = $dataFR['x'][$i] = $dataCA['x'][$i] = $dataEBE['x'][$i] = chartTime((int)$anneeDebut, (int)$moisDebut, (int)$jourDebut);
$dataBFR['x'][$i+1] = $dataFR['x'][$i+1] = $dataCA['x'][$i+1] = $dataEBE['x'][$i+1] = chartTime((int)$anneeFin, (int)$moisFin, (int)$jourFin);
//Affectation des ordonnées
$dataBFR['y'][$i] = $dataBFR['y'][$i+1] = self::getValFromKey($item->RatiosEntrep->item, 'r236');
$dataFR['y'][$i] = $dataFR['y'][$i+1] = self::getValFromKey($item->RatiosEntrep->item, 'r235');
$dataCA['y'][$i] = $dataCA['y'][$i+1] = self::getValFromKey($item->RatiosEntrep->item, 'r6');
$dataEBE['y'][$i] = $dataEBE['y'][$i+1] = self::getValFromKey($item->RatiosEntrep->item, 'r146');
$i+=2;
}
$parametres = new stdClass();
$parametres->nom = self::maskNameImg('synthese', $this->siret, array('graphiqueSynthses', $type));
$parametres->width = 660;
$parametres->height = 350;
$parametres->bgColor = 0xcccccc;
$parametres->edgeColor = 0x000000;
$parametres->raisedEffect = 1;
$parametres->addTitle = array("Synthèse *", "timesbi.ttf", 15, 0x000000);
$parametres->addText = array(array(60, 320, "* Elements financier rapportés à 12 mois"));
$parametres->setPlotArea = array(100, 80, 500, 200, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
$parametres->TitlesY = array(array("KEUROS","timesbi.ttf", 10));
$parametres->TitlesX = array(array("<*block,valign=absmiddle*>Années<*/*>"));
$parametres->yAxisWidth = 2;
$parametres->xAxisWidth = 2;
$parametres->legendeParams = array(55, 30, false, "times.ttf", 9);
$parametres->addStepLineLayer = array('layer1' => array($dataFR['y'], 0x0000ff, "FONDS DE ROULEMENT", $dataFR['x']),
'layer0' => array($dataBFR['y'], 0xff0000, "BESOIN EN FONDS DE ROULEMENT", $dataBFR['x']),
'layer2' => array($dataCA['y'], 0x00ff00, "CHIFFRE D'AFFAIRES", $dataCA['x']),
'layer3' => array($dataEBE['y'], 0x000000, "EXCEDENT BRUT D'EXPLOITATION", $dataEBE['x'])
);
$parametres->dashLineColor = 'layer3';
$parametres->addInterLineLayer = array('layer0:layer1' => array(0xff0000, Transparent),
'layer0:layer1' => array(Transparent, 0x8044ff44)
);
return ($parametres);
}
public function selectTitleGraphique($type)
{
switch($type) {
case 'actif' :
return ('Composition de l\'actif au : ');
case 'passif':
return ('Composition du passif au : ');
case 'sig' :
return ('Sole Intermédiaire de Gestion au : ');
}
}
public function GraphiqueBilan($type, $data, $i, $filename, $date, $count, $labels)
{
$parametres = new stdClass();
$parametres->nom = self::maskNameImg('bilan', $this->siret, array($i, 'graph', $type));
$parametres->title->texte = self::selectTitleGraphique($type).' '.$date;
$parametres->datas = $data;
$parametres->labels = $labels;
$parametres->makeSession = 'chart_'.$type.$i;
$retour = $this->graphique->GraphiquePieChart($parametres, true);
$parametres->retour->file = $parametres->nom;
$parametres->retour->chartID = $retour->chartId;
$parametres->retour->imageMap = $retour->imageMap;
$parametres->retour->i = $type.$i;
$parametres->retour->hide = $i;
($i == $count)?$parametres->retour->hide = false : $parametres->retour->hide = true;
return ($parametres->retour);
}
public function GraphiqueLineBilan($data, $name, $date)
{
$parametres = new stdClass();
$parametres->nom = $name;
$parametres->datas = array($data);
$parametres->TitlesY = array(array("Keuros"));
$parametres->TitlesX = array(array("Années"));
$parametres->LineLayer = array("Entreprise");
$parametres->labelsY = array();
$parametres->labelsX = $date;
$this->graphique->GraphiqueLineXY($parametres, true);
return($parametres->nom);
}
public function initTableau($tableau)
{
$i = 0;
foreach($tableau as $date => $valeur){
$tableau[$i] = $valeur;
unset($tableau[$date]);
$i++;
}
return ($tableau);
}
public function countTypeBilan($ratios, $typeBilan)
{
$type = 0;
foreach($ratios->BilansInfos->item as $item) {
if($item->typeBilan == $typeBilan)
$type++;
}
return ($type);
}
protected function setUnite($valeur, $unite)
{
switch ($unite) {
case 'EUR':
return ($valeur = $valeur / 1000);
default:
return ($valeur);
}
}
public function createAbscisse($type, $unite, $ratio, $id, $typeBilan = 'N', &$labelX = null, $nbResult = 5)
{
$i = 0;
$dataX = array();
if ($type == 'RatiosEntrep') {
foreach ($ratio->BilansInfos->item as $element) {
if($element->typeBilan == $typeBilan) {
if ($i >= self::countTypeBilan($ratio, $typeBilan))
break;
if (is_array($labelX))
$labelX[] = substr($element->dateCloture, 0, 4);
foreach ($element->RatiosEntrep->item as $ratioEntre) {
if ($ratioEntre->id == $id) {
$dataX[substr($element->dateCloture, 0, 4)] = self::setUnite($ratioEntre->val, $unite);$i++;} } } } }
if ($type == 'RatiosSecteur') {
foreach ($ratio->RatiosSecteur->item as $element) {
if($i >= self::countTypeBilan($ratio, $typeBilan))
break;
foreach($element->liste->item as $item) {
if ($item->id == $id) {
$dataX[$element->annee] = self::setUnite($item->val, $unite);$i++; } } } }
if (is_array($labelX)) sort($labelX);
ksort($dataX);
$dataX = self::initTableau($dataX);
return ($dataX);
}
public function createGraphique($ratio, $id, $unite, $type)
{
$Annees = array();
$parametres = new stdClass();
$parametres->nom = self::maskNameImg('ratios', substr($this->siret, 0, 9), array($id,$type));
$parametres->datas = array(self::createAbscisse('RatiosEntrep', $unite, $ratio, $id, $type, $Annees),
self::createAbscisse('RatiosSecteur', $unite, $ratio, $id, $type));
$parametres->TitlesY = array(array($unite));
$parametres->TitlesX = array(array("Années"));
$parametres->colorLegende->Secteur = 0x008C00;
$parametres->colorLegende->Entreprise = 0x0000ff;
$parametres->LineLayer = array("Entreprise", "Secteur");
$parametres->labelsY = array();
$parametres->labelsX = $Annees;
return ($this->graphique->GraphiqueLineXY($parametres, true));
}
public function bourseGraphique($filename)
{
$file = $filename.'.png';
$noOfDays = 30;
$extraDays = 30;
$rantable = new RanTable(9, 6, $noOfDays + $extraDays);
$rantable->setDateCol(0, chartTime(2002, 9, 4), 86400, true);
$rantable->setHLOCCols(1, 100, -5, 5);
$rantable->setCol(5, 50000000, 250000000);
$timeStamps = $rantable->getCol(0); // Les date
$highData = $rantable->getCol(1); // les données les plus hautes
$lowData = $rantable->getCol(2); // Les données les plus basses
$openData = $rantable->getCol(3); // Les donnée d'ouverture
$closeData = $rantable->getCol(4); // Les donnée de fermeture
$volData = $rantable->getCol(5); // Volume de data
$parametres = new stdClass();
$parametres->nom = $file;
$parametres->makeSession = "chart1";
$parametres->timeStamps = $timeStamps;
$parametres->highData = $highData;
$parametres->lowData = $lowData;
$parametres->openData = $openData;
$parametres->closeData = $closeData;
$parametres->volData = $volData;
$parametres->extraDays = $extraDays;
$retour = $this->graphique->GraphiqueFinance($parametres, true);
return ('');
}
}