extranet/includes/ratios/ratios.php

484 lines
16 KiB
PHP
Raw Normal View History

<?php
require_once realpath(dirname(__FILE__)).'/functions.php';
2009-06-12 16:48:50 +00:00
/**
* Retourne un tableau de donn<EFBFBD>es format<EFBFBD>s pour les graphiques.
* @param array $bilansInfo
* Le tableau des bilans
* @param array $ratiosEntrep
* Le tableau des ratios entreprise
* @param array $tabRatioGraph
* Un tableau des ratios <EFBFBD> utiliser pour le graphique g<EFBFBD>n<EFBFBD>ral
* @param array $tabRatioGraphEvol
* Un tableau des ratios <EFBFBD> utiliser pour les graphiques d'<EFBFBD>volution
* @return array
* Retourne un tableau structur<EFBFBD> compos<EFBFBD> de dataGraph, et de dataEvol.
*/
function synthese_datagraph($bilansInfos, $ratiosEntrep, $tabRatioGraph, $tabRatioGraphEvol){
2009-06-16 07:47:53 +00:00
global $firephp;
$dataGraph = array();
$dataEvol = array();
$nbrAnnees = count($bilansInfos)-1;
$i=0;
foreach($bilansInfos as $dateCloture){
//Donn<6E>es pour le graphique
if(isset($dateCloture['dateCloture'])){
$dataGraph[$i]['date'] = $dateCloture['dateCloture'];
2009-08-20 16:54:17 +00:00
$dataGraph[$i]['duree'] = $dateCloture['duree'];
foreach($tabRatioGraph as $item){
$dataGraph[$i][$item['ratio']] = $ratiosEntrep[$i][$item['ratio']]/$item['op'];
}
}
//Donn<6E>es pour les graphiques <20>volutions
if(isset($bilansInfos[$nbrAnnees-$i]['dateCloture'])){
2009-06-16 07:47:53 +00:00
foreach($tabRatioGraphEvol as $ratio => $info){
$dataEvol[$ratio][] = array(
'date'=>$bilansInfos[$nbrAnnees-$i]['dateCloture'],
2009-06-16 07:47:53 +00:00
'value'=>(($ratiosEntrep[$nbrAnnees-$i][$ratio]!='NS') ? $ratiosEntrep[$nbrAnnees-$i][$ratio]/$info['op'] : 0 )
);
}
}
$i++;
}
return array("graph" => $dataGraph, "evol" => $dataEvol);
}
/**
* Formatte cha<EFBFBD>ne contenant la date format<EFBFBD>.
* @param array $bilansInfo
* Le tableau des bilans
* @param array $nAnnee
* Le num<EFBFBD>ro de l'ann<EFBFBD>e
* @return string
* Retourne la date format<EFBFBD>.
*/
function synthese_formatdateCloture($bilansInfos, $nAnnee){
if(isset($bilansInfos[$nAnnee]['dateCloture'])) {
print substr($bilansInfos[$nAnnee]['dateCloture'],6,2).'/'.substr($bilansInfos[$nAnnee]['dateCloture'],4,2).'/'.substr($bilansInfos[$nAnnee]['dateCloture'],0,4).'<br/>'.$bilansInfos[$nAnnee]['duree'].' mois';
}else{ print '-'; }
}
/**
* Retourne une cha<EFBFBD>ne contenant les ligne d'un tableau html.
* @param array $ratiosInfos
* Le tableau des informations ratios
* @param array $dataEvol
* Le tableau des donn<EFBFBD>es <EFBFBD>volution
* @param array $tabRatio
* Un tableau des ratios <EFBFBD> utiliser pour g<EFBFBD>n<EFBFBD>rer les lignes
* @return string
* Retourne une cha<EFBFBD>ne.
*/
function synthese_tablerow($ratiosInfos, $dataEvol, $tabRatio){
global $fileName;
$row = '';
foreach($tabRatio as $ratio => $info){
$row.= '<tr>'."\n".
' <td class="head"><a tooltip="'.wrapComment($ratiosInfos[$ratio]['commentaires']).'">'.$info['titre'].'</a></td>'."\n".
' <td class="right">'.dRatio(2,$ratio).'</td>'."\n".
' <td class="right">'.dRatio(1,$ratio).'</td>'."\n".
' <td class="right">'.dEvol(1,$info['evol']).'</td>'."\n".
' <td class="right">'.dRatio(0,$ratio).'</td>'."\n".
' <td class="right">'.dEvol(0,$info['evol']).'</td>'."\n";
if(count($tabRatio)!=1){
$class = 'class="sTip"';
$href='/?page=synthese&siret='.$_REQUEST['siret'].'&idEntreprise='.$_REQUEST['idEntreprise'].'&ratio='.$ratio;
$unite = '';
if(isset($info['unite']) && $info['unite']==1){
$unite = $ratiosInfos[$info['evol']]['unite'];
}
$rel='./pages/synthese_dgraph.php?widht=375&f='.synthese_graphEvol($dataEvol[$ratio], $unite, $ratio, $fileName);
}else{
$class = '';
$href='#';
$ref='';
}
$row.= ' <td><a '.$class.' href="'.$href.'" rel="'.$rel;
$row.= '" name="'.$info['titre'].'"><img src="./img/synthese/chart_bar.png" alt="Visionner le graphique"></a></td>'."\n";
$row.= '</tr>'."\n";
}
return $row;
}
/**
* Retourne l'url de la page d'appel du graphique avec tous ces param<EFBFBD>tres.
* @param array $data
* Les donn<EFBFBD>es du tableau
* @return string
* Retourne une cha<EFBFBD>ne.
*/
function synthese_graphEvol($data, $unite, $ratio, $filename){
require_once 'phpchartdir/phpchartdir.php';
$unite = ( $_REQUEST['unite']!='' ? $unite : 'KEUROS' );
if(count($data)<=1){
$return = 0;
}else{
foreach($data as $value){
$dataX[] = $value['value'];
$labelsX[] = substr($value['date'],0,4);
}
$i=-100;
while($i>100){ $labelsY[] = $i;}
# Create a XYChart object of size 250 x 250 pixels
$c = new XYChart(350, 250);
$c->setPlotArea(55, 10, 280, 200);
$c->yAxis->setTitle($unite);
$c->xAxis->setTitle("Ann<EFBFBD>es");
$c->xAxis->setWidth(2);
$c->yAxis->setWidth(2);
$c->addLineLayer($dataX);
# Set the labels.
$c->yAxis->setLabels($labelsY);
$c->yAxis->setLabelStep(10);
$c->xAxis->setLabels($labelsX);
$path = PATH_SITE.'/cache/imgcache/';
$file = $filename.'-'.$ratio.'.png';
if($c->makeChart($path.$file) === TRUE){ $return = $file; }
else{ $return = FALSE; }
}
return $return;
}
function synthese_graph_linecompare($data, $filename){
global $firephp;
//Graphique style linecompare / CA / FR / BFR
require_once 'phpchartdir/phpchartdir.php';
//Tri des donn<6E>es par date et par ordre croissant
foreach ($data as $key => $row) { $date[$key] = $row['date']; }
array_multisort($date, SORT_ASC, $data);
$firephp->log($data, 'data');
//D<>finition des valeurs pour le graph
$dataBFR = array();
$dataFR = array();
$dataCA = array();
$i=0;
//Parcourir les ann<6E>es
foreach($data as $item){
2009-08-20 16:54:17 +00:00
$anneeFin = substr($item['date'],0,4);
$moisFin = substr($item['date'],4,2);
$jourFin = substr($item['date'],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<6E>es
$dataBFR['y'][$i] = $dataBFR['y'][$i+1] = $item['r236'];
$dataFR['y'][$i] = $dataFR['y'][$i+1] = $item['r235'];
$dataCA['y'][$i] = $dataCA['y'][$i+1] = $item['r6'];
$dataEBE['y'][$i] = $dataEBE['y'][$i+1] = $item['r146'];
$i+=2;
}
$firephp->log($dataCA,'dataCA');
2009-08-10 16:54:43 +00:00
$c = new XYChart(570, 350, 0xcccccc, 0x000000, 1);
$c->addTitle("Synth<EFBFBD>se *", "timesbi.ttf", 15, 0x000000);
$c->addText(60, 320, "* Elements financier rapport<72>s <20> 12 mois" );
$c->setPlotArea(60, 80, 500, 200, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
$c->yAxis->setTitle("KEUROS","timesbi.ttf",10);
$c->xAxis->setTitle( "<*block,valign=absmiddle*>Ann<6E>es<*/*>");
$c->xAxis->setWidth(2);
$c->yAxis->setWidth(2);
// Add a legend box at (55, 32) (top of the chart) with horizontal layout. Use 9 pts
// Arial Bold font. Set the background and border color to Transparent.
$legendObj = $c->addLegend(55, 30, false, "times.ttf", 9);
$legendObj->setBackground(Transparent);
// Add a blue (0000ff) step line layer to the chart and set the line width to 2 pixels
$layer1 = $c->addStepLineLayer($dataFR['y'], 0x0000ff, "FONDS DE ROULEMENT");
$layer1->setXData($dataFR['x']);
$layer1->setLineWidth(2);
// Add a red (ff0000) step line layer to the chart and set the line width to 2 pixels
$layer0 = $c->addStepLineLayer($dataBFR['y'], 0xff0000, "BESOIN EN FONDS DE ROULEMENT");
$layer0->setXData($dataBFR['x']);
$layer0->setLineWidth(2);
// Add a green (00ff00) step line layer to the chart and set the line width to 2 pixels
$layer2 = $c->addStepLineLayer($dataCA['y'], 0x00ff00, "CHIFFRE D'AFFAIRES");
$layer2->setXData($dataCA['x']);
$layer2->setLineWidth(2);
// Add a black (000000) step line layer style dash to the chart and set the line width to 2 pixels
$layer3 = $c->addStepLineLayer($dataEBE['y'], $c->dashLineColor(0x000000, DashLine), "EXCEDENT BRUT D'EXPLOITATION");
$layer3->setXData($dataEBE['x']);
$layer3->setLineWidth(2);
# If the FR line gets above the BFR line, color to area between the lines red (ff0000)
$c->addInterLineLayer($layer0->getLine(0), $layer1->getLine(0), 0xff0000, Transparent);
# If the FR line gets below the lower BFR line, color to area between the lines light green (8099ff99)
$c->addInterLineLayer($layer0->getLine(0), $layer1->getLine(0), Transparent, 0x8044ff44);
$path = PATH_SITE.'/cache/imgcache/';
$file = $filename.'-graph-linecompare.png';
if($c->makeChart($path.$file) === TRUE){
$return = '<img src="./imgcache/'.$file.'"/>';
}else{
$return = 'Impossible de g<>n<EFBFBD>rer le graphique';
}
return $return;
}
2009-06-16 07:47:53 +00:00
/**
* Retourne une cha<EFBFBD>ne contenant la ligne d'un tableau html.
* @param array $ratiosInfos
* Le tableau des information ratios
* @param array $dataEvol
* Le tableau des donn<EFBFBD>es <EFBFBD>volution
* @param array $tabRatio
* Un tableau des ratios <EFBFBD> utiliser pour le g<EFBFBD>n<EFBFBD>rer les lignes
* @return string
* Retourne une cha<EFBFBD>ne.
*/
function ratios_tablerow($ratiosInfos, $tabRatio, $bilan, $ratio = ''){
2009-06-23 15:26:15 +00:00
global $fileName;
2009-06-16 07:47:53 +00:00
foreach($tabRatio as $item){
if($ratio==''){
2009-06-16 07:47:53 +00:00
if(isset($item['ratio'])){
$row.= '<tr>'."\n";
$row.= ' <td><a tooltip="'.wrapComment($ratiosInfos[$item['ratio']]['commentaires']).'">'.$item['titre'].'<br/>'.$item['stitre'].'</a></td>'."\n";
$row.= ' <td class="right">'.dRatio($bilan,$item['ratio']).'</td>'."\n";
$row.= ' <td class="right">'.dSecteur($bilan,$item['ratio']).'</td>'."\n";
$row.= ' <td class="position">';
$row.= '<a class="rTip" href="/?page=ratios&siret='.$_REQUEST['siret'].'&idEntreprise='.$_REQUEST['idEntreprise'].'&ratio='.$item['ratio'].'" rel="./pages/ratios_dgraph.php?width=375&f='.ratios_graph($item['ratio'], dGraph($item['ratio']), $fileName).'" name="'.$item['titre'].'">'."\n";
$row.= dPosition($bilan,$item['ratio'],$item['position']);
$row.= '</a>';
$row.= '</td>'."\n";
$row.= '</tr>'."\n";
2009-06-16 07:47:53 +00:00
}else{
$row.= '<tr class="subhead">'."\n";
$row.= ' <td class="center italique">'.$item['titre'].'</td>'."\n";
$row.= ' <td>Entreprise</td>'."\n";
$row.= ' <td>Secteur</td>'."\n";
$row.= ' <td>Position</td>'."\n";
$row.= '</tr>'."\n";
}
}elseif($ratio==$item['ratio']){
2009-06-16 07:47:53 +00:00
$row.= '<tr class="subhead">'."\n".
' <td class="center italique">'.$tabRatio[$item['parent']]['titre'].'</td>'."\n".
' <td>Entreprise</td>'."\n".
' <td>Secteur</td>'."\n".
' <td>Position</td>'."\n".
'</tr>'."\n";
2009-06-16 07:47:53 +00:00
$row.= '<tr>'."\n".
' <td><a tooltip="'.wrapComment($ratiosInfos[$item['ratio']]['commentaires']).'">'.$item['titre'].'<br/>'.$item['stitre'].'</a></td>'."\n".
' <td class="right">'.dRatio($bilan,$item['ratio']).'</td>'."\n".
' <td class="right">'.dSecteur($bilan,$item['ratio']).'</td>'."\n".
' <td class="position">'."\n".
' <a href="#" name="'.$item['titre'].'">'."\n".
dPosition($bilan,$item['ratio'],$item['position'])."\n".
2009-06-16 07:47:53 +00:00
' </a>'."\n".
' </td>'."\n".
'</tr>'."\n";
}
}
return $row;
}
/**
* Enregistre le graphique bilan actif sous forme d'image.
* @param array $data
* Tableau structur<EFBFBD> des donn<EFBFBD>es
* @param array $filename
* Le nom de fichier g<EFBFBD>n<EFBFBD>r<EFBFBD>
* @return string
* Retourne un message d'erreur ou le code HTML d'affichage.
*/
function bilans_graph_actif($data, $filename){
require_once 'phpchartdir/phpchartdir.php';
$w = 570;
$h = 210;
$x = round($w/2);
$y = round($h/2);
$radius=90;
$c = new PieChart($w, $h);
$labels = array('Immo. incorporelles',
'Immo. corporelles',
'Immo. financi<63>res',
'Stock et encours',
'Cr<43>ances Clients',
'Autres cr<63>ances',
'Tr<54>sorerie Active');
$textBoxObj = $c->addTitle("Composition de l'actif", "timesbi.ttf", 15);
$c->setPieSize($x, $y, $radius);
$c->setLabelLayout(SideLayout);
$t = $c->setLabelStyle();
$t->setBackground(SameAsMainColor, Transparent, glassEffect());
$t->setRoundedCorners(5);
# Set the border color of the sector the same color as the fill color. Set the line # color of the join line to black (0x0)
$c->setLineColor(SameAsMainColor, 0x000000);
$c->setStartAngle(135);
$c->setLabelFormat("<*block,valign=absmiddle*>{label} <*font=timesbi.ttf,size=0*>({percent|0}%)");
$c->setData($data, $labels);
$c->set3D(20);
$path = PATH_SITE.'/cache/imgcache/';
$file = $filename.'-graph-bilansactif.png';
if($c->makeChart($path.$file) === TRUE){
$return = '<img src="./imgcache/'.$file.'"/>';
}else{
$return = 'Impossible de g<>n<EFBFBD>rer le graphique';
}
return $return;
}
2009-06-16 07:47:53 +00:00
/**
* Enregistre le graphique bilan SIG sous forme d'image.
* @param array $data
* Tableau structur<EFBFBD> des donn<EFBFBD>es
* @param array $filename
* Le nom de fichier g<EFBFBD>n<EFBFBD>r<EFBFBD>
* @return string
* Retourne un message d'erreur ou le code HTML d'affichage.
*/
function bilans_graph_sig($data, $filename){
require_once 'phpchartdir/phpchartdir.php';
$w = 570;
$h = 210;
$x = round($w/2);
$y = round($h/2);
$radius=70;
$c = new PieChart($w, $h);
$labels = array('Achats de marchandises.',
'Autres achats externes',
'Charges de fonctionnement',
'Amortissement et provisions',
'Perte financi<63>re',
'Imp<6D>ts soci<63>t<EFBFBD>s',
'R<>SULTAT NET',
);
$textBoxObj = $c->addTitle("Solde Interm<72>diaire de Gestion", "timesbi.ttf", 15);
$c->setPieSize($x, $y, $radius);
$c->setLabelLayout(SideLayout);
$t = $c->setLabelStyle();
$t->setBackground(SameAsMainColor, Transparent, glassEffect());
$t->setRoundedCorners(5);
$c->setLineColor(SameAsMainColor, 0x000000);
$c->setLabelFormat("<*block,valign=absmiddle*>{label} <*font=arial.ttf,size=0*>({percent|0}%)");
$c->setStartAngle(135);
$c->setData($data, $labels);
$c->set3D(20);
$path = PATH_SITE.'/cache/imgcache/';
$file = $filename.'-graph-bilanssig.png';
if($c->makeChart($path.$file) === TRUE){
$return = '<img src="./imgcache/'.$file.'"/>';
}else{
$return = 'Impossible de g<>n<EFBFBD>rer le graphique';
}
return $return;
}
2009-06-16 07:47:53 +00:00
/**
* Enregistre le graphique bilan passif sous forme d'image.
* @param array $data
* Tableau structur<EFBFBD> des donn<EFBFBD>es
* @param array $filename
* Le nom de fichier g<EFBFBD>n<EFBFBD>r<EFBFBD>
* @return string
* Retourne un message d'erreur ou le code HTML d'affichage.
*/
function bilans_graph_passif($data, $filename){
require_once 'phpchartdir/phpchartdir.php';
$w = 570;
$h = 210;
$x=round($w/2);
$y=round($h/2);
$radius=90;
$c = new PieChart($w, $h);
$labels = array('Fonds propres',
'Provisions Risques',
'Compte Courant',
'Dettes Financi<63>res',
'Dettes Fournisseurs',
'Dettes fiscales',
'Autres Dettes',
'Tr<54>sorerie Passive');
$textBoxObj = $c->addTitle("Composition du passif", "timesbi.ttf", 15);
$c->setPieSize($x, $y, $radius);
$c->setLabelLayout(SideLayout);
$t = $c->setLabelStyle();
$t->setBackground(SameAsMainColor, Transparent, glassEffect());
$t->setRoundedCorners(5);
$c->setLineColor(SameAsMainColor, 0x000000);
$c->setStartAngle(135);
$c->setLabelFormat("<*block,valign=absmiddle*>{label} <*font=timesbi.ttf,size=0*>({percent|0}%)");
$c->setData($data, $labels);
$c->set3D(20);
$path = PATH_SITE.'/cache/imgcache/';
$file = $filename.'-graph-bilanspassif.png';
if($c->makeChart($path.$file) === TRUE){
$return = '<img src="./imgcache/'.$file.'"/>';
}else{
$return = 'Impossible de g<>n<EFBFBD>rer le graphique';
}
return $return;
}
/**
* Enregistre le graphique <EFBFBD>volution.
* @param array $data
* Tableau structur<EFBFBD> des donn<EFBFBD>es
* @param array $filename
* Le nom de fichier g<EFBFBD>n<EFBFBD>r<EFBFBD>
* @return string
* Retourne un message d'erreur ou le code HTML d'affichage.
*/
2009-06-23 15:26:15 +00:00
function ratios_graph($ratio, $data, $filename){
$path = PATH_SITE.'/cache/imgcache/';
if($ratio != ''){
$file = $filename.'-'.$ratio.'.png';
}else{
$file = $filename.'.png';
}
if(file_exists($path.$file)){
$return = $file;
}else{
require_once 'phpchartdir/phpchartdir.php';
if(count($data)<=1){
$return = 0;
}else{
foreach($data['data'] as $value){
$dataX1[] = $value['entreprise'];
$dataX2[] = $value['secteur'];
$labelsX[] = substr($value['date'],0,4);
}
$i=-100; while($i>100){ $labelsY[] = $i;}
$c = new XYChart(350, 250);
$c->setPlotArea(55, 10, 280, 200);
$c->yAxis->setTitle($data['unite']);
$c->xAxis->setTitle("Ann<EFBFBD>es");
$c->xAxis->setWidth(2);
$c->yAxis->setWidth(2);
$legendObj = $c->addLegend(50, 10, false, "times.ttf", 9);
$legendObj->setBackground(Transparent);
$c->addLineLayer($dataX1, 0x0000ff, "Entreprise");
$c->addLineLayer($dataX2, 0x008C00, "Secteur");
$c->yAxis->setLabels($labelsY);
$c->yAxis->setLabelStep(10);
$c->xAxis->setLabels($labelsX);
if($c->makeChart($path.$file) === TRUE){ $return = $file; }
else{ $return = FALSE; }
}
}
return $return;
}
?>