Ticket UUID: e6a2c8e0d9b280b53ae32ff1fc2eb2cd3f15c8fa
Title: Camemberts de recettes/dépenses par valeur plutot que par nombre de transactions
Status: Fixed Type: Feature_Request
Severity: Minor Priority: Low
Subsystem: Resolution: Fixed
Last Modified: 2015-01-02 23:56:56
Version Found In: 0.6.2
User Comments:
ghostdog added on 2014-11-21 16:13:49:
Les camemberts dans la vue comptabilité montre des pourcentages en nombre de transaction et pas en valeur de transaction (c'est à dire si vous avez 2 catégories de recettes une de 50€ et une de 150€: le camembert est coupé en deux parts égales).

Le patch ci-dessous permet d'avoir des pourcentages par valeur.

$ diff -u include/libs/svgplot/lib.svgpie.php.orig include/libs/svgplot/lib.svgpie.php
--- include/libs/svgplot/lib.svgpie.php.orig    2014-11-21 16:12:54.841072386 +0100
+++ include/libs/svgplot/lib.svgpie.php 2014-11-21 16:54:43.147069985 +0100
@@ -64,15 +64,15 @@

                        foreach ($this->data as $row)
                        {
-                               $sum += $row->data;
+                               $sum += $row->somme;
                        }

                        foreach ($this->data as $row)
                        {
-                               $row->angle = ceil(360 * $row->data / $sum);
+                               $row->angle = ceil(360 * $row->somme / $sum);

-                   $start_angle = $end_angle;
-                   $end_angle = $start_angle + $row->angle;
+                               $start_angle = $end_angle;
+                               $end_angle = $start_angle + $row->angle;

                                $x1 = $cx + $radius * cos(deg2rad($start_angle));
                                $y1 = $cy + $radius * sin(deg2rad($start_angle));
@@ -84,7 +84,7 @@

                                $out .= "<path d=\"M{$cx},{$cy} L{$x1},{$y1} A{$radius},{$radius} 0 {$arc},1 {$x2},{$y2} Z\"
                                        fill=\"{$row->fill}\" stroke=\"white\" stroke-width=\"".($circle_size * 0.005)."\" stroke-linecap=\"round\"
-                                       stroke-linejoin=\"round\" />";
+                                       stroke-linejoin=\"round\" />" . PHP_EOL;
                        }
                }

@@ -132,12 +132,14 @@
        public $fill = 'blue';
        public $data = 0.0;
        public $label = null;
+       public $somme = 0.0;

-       public function __construct($data, $label = null, $fill = 'blue')
+       public function __construct($data, $label = null, $fill = 'blue', $somme)
        {
                $this->data = $data;
                $this->fill = $fill;
                $this->label = $label;
+               $this->somme = $somme;
        }
 }


$ diff -u include/class.compta_stats.php.orig include/class.compta_stats.php
--- include/class.compta_stats.php.orig 2014-11-21 16:26:11.011071624 +0100
+++ include/class.compta_stats.php      2014-11-21 16:32:23.436071268 +0100
@@ -7,7 +7,7 @@
        protected function _parRepartitionCategorie($type)
        {
                $db = DB::getInstance();
-               return $db->simpleStatementFetch('SELECT COUNT(*) AS nb, id_categorie
+               return $db->simpleStatementFetch('SELECT COUNT(*) AS nb, id_categorie, SUM(montant) AS somme
                        FROM compta_journal
                        WHERE id_categorie IN (SELECT id FROM compta_categories WHERE type = ?)
                        AND id_exercice = (SELECT id FROM compta_exercices WHERE cloture = 0)


$ diff -u www/admin/compta/pie.php.orig www/admin/compta/pie.php
--- www/admin/compta/pie.php.orig       2014-11-21 16:40:08.583070822 +0100
+++ www/admin/compta/pie.php    2014-11-21 16:38:38.373070908 +0100
@@ -33,6 +33,7 @@
        }

        $others = 0;
+       $somme_others = 0;
        $colors = ['#c71', '#941', '#fa4', '#fd9', '#ffc', '#cc9'];
        $max = count($colors);
        $i = 0;
@@ -42,17 +43,18 @@
                if ($i++ >= $max)
                {
                        $others += $row['nb'];
+                       $somme_others += $row['somme'];
                }
                else
                {
                        $cat = $categories[$row['id_categorie']];
-                       $pie->add(new \SVGPie_Data($row['nb'], substr($cat['intitule'], 0, 50), $colors[$i-1]));
+                       $pie->add(new \SVGPie_Data($row['nb'], substr($cat['intitule'], 0, 50), $colors[$i-1], $row['somme']));
                }
        }

        if ($others > 0)
        {
-               $pie->add(new \SVGPie_Data($others, 'Autres', '#ccc'));
+               $pie->add(new \SVGPie_Data($others, 'Autres', '#ccc', $somme_others));
        }

        Static_Cache::store('pie_' . $graph, $pie->output());

ghostdog added on 2014-11-21 16:26:31:
Mise à jour du patch sur la requête SQL pour que les catégories soient retournées par ordre décroissant de valeur:

$ diff -u include/class.compta_stats.php.orig include/class.compta_stats.php
--- include/class.compta_stats.php.orig 2014-11-21 16:26:11.011071624 +0100
+++ include/class.compta_stats.php      2014-11-21 17:14:47.917068832 +0100
@@ -7,11 +7,11 @@
        protected function _parRepartitionCategorie($type)
        {
                $db = DB::getInstance();
-               return $db->simpleStatementFetch('SELECT COUNT(*) AS nb, id_categorie
+               return $db->simpleStatementFetch('SELECT COUNT(*) AS nb, id_categorie, SUM(montant) AS somme
                        FROM compta_journal
                        WHERE id_categorie IN (SELECT id FROM compta_categories WHERE type = ?)
                        AND id_exercice = (SELECT id FROM compta_exercices WHERE cloture = 0)
-                       GROUP BY id_categorie ORDER BY nb DESC;', SQLITE3_ASSOC, $type);
+                       GROUP BY id_categorie ORDER BY somme DESC;', SQLITE3_ASSOC, $type);
        }

        public function repartitionRecettes()

bohwaz added on 2015-01-02 22:56:56:
Patch inclus dans [050e4d960ade08c18e9c403610978a8e9a7f43a7]