示例#1
0
文件: pie.php 项目: kd2org/garradin
<?php

namespace Garradin;

require_once __DIR__ . '/_inc.php';
if (!in_array(Utils::get('g'), ['recettes', 'depenses'])) {
    throw new UserException('Graphique inconnu.');
}
$graph = Utils::get('g');
if (Static_Cache::expired('pie_' . $graph)) {
    $stats = new Compta\Stats();
    $categories = new Compta\Categories();
    $pie = new \KD2\SVGPie(400, 250);
    if ($graph == 'recettes') {
        $data = $stats->repartitionRecettes();
        $categories = $categories->getList(Compta\Categories::RECETTES);
        $pie->setTitle('Répartition des recettes');
    } else {
        $data = $stats->repartitionDepenses();
        $categories = $categories->getList(Compta\Categories::DEPENSES);
        $pie->setTitle('Répartition des dépenses');
    }
    $others = 0;
    $colors = ['#c71', '#941', '#fa4', '#fd9', '#ffc', '#cc9'];
    $max = count($colors);
    $i = 0;
    foreach ($data as $row) {
        if ($i++ >= $max) {
            $others += $row['somme'];
        } else {
            $cat = $categories[$row['id_categorie']];
示例#2
0
 /**
  * Liste des plugins officiels depuis le repository signé
  * @return array Liste des plugins
  */
 public static function listOfficial()
 {
     // La liste est stockée en cache une heure pour ne pas tuer le serveur distant
     if (Static_Cache::expired('plugins_list', 3600 * 24)) {
         $url = parse_url(PLUGINS_URL);
         $context_options = ['ssl' => ['verify_peer' => TRUE, 'cafile' => ROOT . '/include/data/cacert.pem', 'verify_depth' => 5, 'CN_match' => $url['host'], 'SNI_enabled' => true, 'SNI_server_name' => $url['host'], 'disable_compression' => true]];
         $context = stream_context_create($context_options);
         try {
             $result = file_get_contents(PLUGINS_URL, NULL, $context);
         } catch (\Exception $e) {
             throw new UserException('Le téléchargement de la liste des plugins a échoué : ' . $e->getMessage());
         }
         Static_Cache::store('plugins_list', $result);
     } else {
         $result = Static_Cache::get('plugins_list');
     }
     $list = json_decode($result, true);
     return $list;
 }
示例#3
0
文件: graph.php 项目: kd2org/garradin
<?php

namespace Garradin;

require_once __DIR__ . '/_inc.php';
if (!in_array(Utils::get('g'), ['recettes_depenses', 'banques_caisses'])) {
    throw new UserException('Graphique inconnu.');
}
$graph = Utils::get('g');
if (Static_Cache::expired('graph_' . $graph)) {
    $stats = new Compta\Stats();
    $plot = new \KD2\SVGPlot(400, 300);
    if ($graph == 'recettes_depenses') {
        $r = new \KD2\SVGPlot_Data($stats->recettes());
        $r->title = 'Recettes';
        $d = new \KD2\SVGPlot_Data($stats->depenses());
        $d->title = 'Dépenses';
        $data = [$d, $r];
        $plot->setTitle('Recettes et dépenses de l\'exercice courant');
    } elseif ($graph == 'banques_caisses') {
        $banques = new Compta\Comptes_Bancaires();
        $data = [];
        $r = new \KD2\SVGPlot_Data($stats->soldeCompte(Compta\Comptes::CAISSE));
        $r->title = 'Caisse';
        $data[] = $r;
        foreach ($banques->getList() as $banque) {
            $r = new \KD2\SVGPlot_Data($stats->soldeCompte($banque['id']));
            $r->title = $banque['libelle'];
            $data[] = $r;
        }
        $plot->setTitle('Solde des comptes et caisses');