4 require_once __DIR__
. '/_inc.php';
6 if (!in_array(utils
::get('g'), ['recettes_depenses', 'banques_caisses']))
8 throw new UserException('Graphique inconnu.');
11 $graph = utils
::get('g');
13 if (Static_Cache
::expired('graph_' . $graph))
15 $stats = new Compta_Stats
;
17 require_once ROOT
. '/include/libs/svgplot/lib.svgplot.php';
19 $plot = new \
SVGPlot(400, 300);
21 if ($graph == 'recettes_depenses')
23 $r = new \
SVGPlot_Data($stats->recettes());
24 $r->title
= 'Recettes';
26 $d = new \
SVGPlot_Data($stats->depenses());
27 $d->title
= 'Dépenses';
31 $plot->setTitle('Recettes et dépenses de l\'exercice courant');
33 elseif ($graph == 'banques_caisses')
35 $banques = new Compta_Comptes_Bancaires
;
39 $r = new \
SVGPlot_Data($stats->soldeCompte(Compta_Comptes
::CAISSE
));
44 foreach ($banques->getList() as $banque)
46 $r = new \
SVGPlot_Data($stats->soldeCompte($banque['id']));
47 $r->title
= $banque['libelle'];
51 $plot->setTitle('Solde des comptes et caisses');
58 foreach ($data[0]->get() as $k=>$v)
60 $labels[] = utils
::date_fr('M y', strtotime(substr($k, 0, 4) . '-' . substr($k, 4, 2) .'-01'));
63 $plot->setLabels($labels);
66 $colors = ['#c71', '#941', '#fa4', '#fd9', '#ffc', '#cc9'];
68 foreach ($data as $line)
70 $line->color
= $colors[$i++
];
74 if ($i > count($colors))
79 Static_Cache
::store('graph_' . $graph, $plot->output());
82 header('Content-Type: image/svg+xml');
83 Static_Cache
::display('graph_' . $graph);