From 0812a19c5c9eb9dffffd1a599f44036e6acad723 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 16 Jul 2005 14:56:25 +0000 Subject: [PATCH] Qual: Uniformisation du code des pages de stats graphiques. --- htdocs/comm/propal/stats/index.php | 12 +- htdocs/comm/propal/stats/month.php | 6 +- .../comm/propal/stats/propalestats.class.php | 14 ++ htdocs/commande/stats/commandestats.class.php | 121 +++--------------- htdocs/commande/stats/index.php | 27 ++-- htdocs/commande/stats/month.php | 12 +- .../facture/stats/facturestats.class.php | 17 ++- htdocs/compta/facture/stats/index.php | 2 +- htdocs/compta/facture/stats/month.php | 7 +- htdocs/graph.class.php | 4 +- 10 files changed, 85 insertions(+), 137 deletions(-) diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php index 3980d789d87..2c2115162ce 100644 --- a/htdocs/comm/propal/stats/index.php +++ b/htdocs/comm/propal/stats/index.php @@ -31,6 +31,10 @@ require("./pre.inc.php"); require("./propalestats.class.php"); +$WIDTH=500; +$HEIGHT=250; + + llxHeader(); print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg); @@ -50,8 +54,8 @@ if (! $mesg) { $px->SetData($data); $px->SetLegend(array($year - 1, $year)); $px->SetMaxValue($px->GetMaxValue()); - $px->SetWidth(450); - $px->SetHeight(280); + $px->SetWidth($WIDTH); + $px->SetHeight($HEIGHT); $px->draw($filename); } @@ -82,11 +86,11 @@ if ($db->query($sql)) } else { - print "Erreur : $sql"; + dolibarr_print_error($db); } $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/comm/propal/stats/month.php b/htdocs/comm/propal/stats/month.php index a39f3dc9fc9..2bad123327a 100644 --- a/htdocs/comm/propal/stats/month.php +++ b/htdocs/comm/propal/stats/month.php @@ -73,7 +73,7 @@ $data = array(); for ($i = 1 ; $i < 13 ; $i++) { - $data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); + $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); } $filename_amount = $conf->propal->dir_images."/propaleamount".$year.".png"; @@ -95,7 +95,7 @@ $data = array(); for ($i = 1 ; $i < 13 ; $i++) { - $data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); + $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); } $filename_avg = $conf->propal->dir_images."/propaleaverage".$year.".png"; $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage'.$year.'.png'; @@ -130,5 +130,5 @@ print ''; $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/comm/propal/stats/propalestats.class.php b/htdocs/comm/propal/stats/propalestats.class.php index 94ce1998008..bf040d6584a 100644 --- a/htdocs/comm/propal/stats/propalestats.class.php +++ b/htdocs/comm/propal/stats/propalestats.class.php @@ -1,5 +1,6 @@ + * Copyright (c) 2005 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,8 +21,21 @@ * */ +/** + \file htdocs/propal/stats/propalestats.class.php + \ingroup propales + \brief Fichier de la classe de gestion des stats des propales + \version $Revision$ +*/ + include_once DOL_DOCUMENT_ROOT . "/stats.class.php"; + +/** + \class PropaleStats + \brief Classe permettant la gestion des stats des propales +*/ + class PropaleStats extends Stats { var $db ; diff --git a/htdocs/commande/stats/commandestats.class.php b/htdocs/commande/stats/commandestats.class.php index 1ec2a78adf2..87c41b60e88 100644 --- a/htdocs/commande/stats/commandestats.class.php +++ b/htdocs/commande/stats/commandestats.class.php @@ -1,5 +1,6 @@ + * Copyright (c) 2005 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,21 +18,24 @@ * * $Id$ * $Source$ - * */ -/** \file htdocs/commande/stats/commandestats.class.php +/** + \file htdocs/commande/stats/commandestats.class.php \ingroup commandes \brief Fichier de la classe de gestion des stats des commandes \version $Revision$ */ +include_once DOL_DOCUMENT_ROOT . "/stats.class.php"; -/** \class CommandeStats + +/** + \class CommandeStats \brief Classe permettant la gestion des stats des commandes */ -class CommandeStats +class CommandeStats extends Stats { var $db ; @@ -41,29 +45,12 @@ class CommandeStats $this->socidp = $socidp; } - function getNbCommandeByMonthWithPrevYear($year) - { - $data1 = $this->getNbCommandeByMonth($year - 1); - $data2 = $this->getNbCommandeByMonth($year); - - $data = array(); - - for ($i = 0 ; $i < 12 ; $i++) - { - $data[$i] = array($data1[$i][0], - $data1[$i][1], - $data2[$i][1]); - } - return $data; - } - /** * \brief Renvoie le nombre de commande par mois pour une année donnée * */ - function getNbCommandeByMonth($year) + function getNbByMonth($year) { - $tabresult = array(); $sql = "SELECT date_format(date_commande,'%m') as dm, count(*) nb FROM ".MAIN_DB_PREFIX."commande"; $sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0"; if ($this->socidp) @@ -72,29 +59,8 @@ class CommandeStats } $sql .= " GROUP BY dm"; $sql .= " ORDER BY dm DESC"; - $result=$this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_object($result); - $j = $row->dm; - $tabresult[$j+0] = $row->nb; - $i++; - } - $this->db->free($result); - } - - $data = array(); - - for ($i = 1 ; $i < 13 ; $i++) - { - $data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $tabresult[$i] ); - } - - return $data; + + return $this->_getNbByMonth($year, $sql); } /** @@ -103,35 +69,22 @@ class CommandeStats */ function getNbByYear() { - $result = array(); $sql = "SELECT date_format(date_commande,'%Y') as dm, count(*), sum(total_ht) FROM ".MAIN_DB_PREFIX."commande WHERE fk_statut > 0"; if ($this->socidp) { $sql .= " AND fk_soc = ".$this->socidp; } $sql .= " GROUP BY dm DESC"; - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($i); - $result[$row[0]] = array($row[1], $row[2]); - $i++; - } - $this->db->free(); - } - return $result; + return $this->_getNbByYear($sql); } + /** * Renvoie le nombre de commande par mois pour une année donnée * */ - function getCommandeAmountByMonth($year) + function getAmountByMonth($year) { - $result = array(); $sql = "SELECT date_format(date_commande,'%m') as dm, sum(total_ht) FROM ".MAIN_DB_PREFIX."commande"; $sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0"; if ($this->socidp) @@ -140,34 +93,15 @@ class CommandeStats } $sql .= " GROUP BY dm DESC"; - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($i); - $j = $row[0] * 1; - $result[$j] = $row[1]; - $i++; - } - $this->db->free(); - } - - for ($i = 1 ; $i < 13 ; $i++) - { - $res[$i] = $result[$i] + 0; - } - - return $res; + return $this->_getAmountByMonth($year, $sql); } + /** * Renvoie le nombre de commande par mois pour une année donnée * */ - function getCommandeAverageByMonth($year) + function getAverageByMonth($year) { - $result = array(); $sql = "SELECT date_format(date_commande,'%m') as dm, avg(total_ht) FROM ".MAIN_DB_PREFIX."commande"; $sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0"; if ($this->socidp) @@ -176,26 +110,7 @@ class CommandeStats } $sql .= " GROUP BY dm DESC"; - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($i); - $j = $row[0] * 1; - $result[$j] = $row[1]; - $i++; - } - $this->db->free(); - } - - for ($i = 1 ; $i < 13 ; $i++) - { - $res[$i] = $result[$i] + 0; - } - - return $res; + return $this->_getAverageByMonth($year, $sql); } } diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php index a35efd6bbdc..b9c872c9837 100644 --- a/htdocs/commande/stats/index.php +++ b/htdocs/commande/stats/index.php @@ -28,31 +28,29 @@ \version $Revision$ */ - require("./pre.inc.php"); require("../commande.class.php"); require("./commandestats.class.php"); -/* - * Sécurité accés client - */ + +$WIDTH=500; +$HEIGHT=250; + +// Sécurité accés client if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } + llxHeader(); -/* - * - * - */ print_fiche_titre($langs->trans("OrdersStatistics"), $mesg); $stats = new CommandeStats($db, $socidp); $year = strftime("%Y", time()); -$data = $stats->getNbCommandeByMonthWithPrevYear($year); +$data = $stats->getNbByMonthWithPrevYear($year); if (! is_dir($conf->commande->dir_images)) { @@ -68,8 +66,9 @@ $mesg = $px->isGraphKo(); if (! $mesg) { $px->SetData($data); $px->SetMaxValue($px->GetMaxValue()); - $px->SetWidth(450); - $px->SetHeight(280); + $px->SetLegend(array($year - 1, $year)); + $px->SetWidth($WIDTH); + $px->SetHeight($HEIGHT); $px->SetYLabel("Nombre de commande"); $px->draw($filename); } @@ -85,9 +84,9 @@ print ''; $i = 0; while (list($key, $value) = each ($rows)) { - $nbproduct = $value[0]; - $price = $value[1]; - $year = $key; + $year = $value[0]; + $nbproduct = $value[1]; + $price = $value[2]; print ""; print ''.$year.''.$nbproduct.''.price($price).''; $i++; diff --git a/htdocs/commande/stats/month.php b/htdocs/commande/stats/month.php index de444a320fa..ed5fa5af15f 100644 --- a/htdocs/commande/stats/month.php +++ b/htdocs/commande/stats/month.php @@ -60,7 +60,7 @@ $HEIGHT=250; print_fiche_titre($langs->trans("OrdersStatistics"), $mesg); $stats = new CommandeStats($db, $socidp); -$data = $stats->getNbCommandeByMonth($year); +$data = $stats->getNbByMonth($year); if (! is_dir($conf->commande->dir_images)) { mkdir($conf->commande->dir_images); } @@ -78,13 +78,13 @@ if (! $mesg) { $px->draw($filename); } -$res = $stats->getCommandeAmountByMonth($year); +$res = $stats->getAmountByMonth($year); $data = array(); for ($i = 1 ; $i < 13 ; $i++) { - $data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); + $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); } $filename_amount = $conf->commande->dir_images."/commandeamount".$year.".png"; @@ -100,13 +100,13 @@ if (! $mesg) { $px->SetYLabel($langs->trans("AmountTotal")); $px->draw($filename_amount); } -$res = $stats->getCommandeAverageByMonth($year); +$res = $stats->getAverageByMonth($year); $data = array(); for ($i = 1 ; $i < 13 ; $i++) { - $data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); + $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); } $filename_avg = $conf->commande->dir_images."/commandeaverage".$year.".png"; @@ -142,5 +142,5 @@ print ''; $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/compta/facture/stats/facturestats.class.php b/htdocs/compta/facture/stats/facturestats.class.php index 8895380249f..e9d7c05e25c 100644 --- a/htdocs/compta/facture/stats/facturestats.class.php +++ b/htdocs/compta/facture/stats/facturestats.class.php @@ -1,5 +1,6 @@ + * Copyright (c) 2005 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,8 +21,21 @@ * */ +/** + \file htdocs/facture/stats/facturestats.class.php + \ingroup factures + \brief Fichier de la classe de gestion des stats des factures + \version $Revision$ +*/ + include_once DOL_DOCUMENT_ROOT . "/stats.class.php"; + +/** + \class FactureStats + \brief Classe permettant la gestion des stats des factures +*/ + class FactureStats extends Stats { var $db ; @@ -61,6 +75,7 @@ class FactureStats extends Stats return $this->_getNbByYear($sql); } + /** * Renvoie le nombre de facture par mois pour une année donnée * @@ -90,8 +105,8 @@ class FactureStats extends Stats $sql .= " AND fk_soc = ".$this->socidp; } $sql .= " GROUP BY dm DESC"; - return $this->_getAverageByMonth($year, $sql); + return $this->_getAverageByMonth($year, $sql); } } diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php index 0b238c1e5c6..116771f7233 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -105,5 +105,5 @@ else $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/compta/facture/stats/month.php b/htdocs/compta/facture/stats/month.php index 05758f91889..add0aa76ea0 100644 --- a/htdocs/compta/facture/stats/month.php +++ b/htdocs/compta/facture/stats/month.php @@ -76,7 +76,7 @@ $data = array(); for ($i = 1 ; $i < 13 ; $i++) { - $data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); + $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); } $filename_amount = $conf->facture->dir_images."/factureamount".$year.".png"; @@ -98,7 +98,7 @@ $data = array(); for ($i = 1 ; $i < 13 ; $i++) { - $data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); + $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); } $filename_avg = $conf->facture->dir_images."/factureaverage".$year.".png"; @@ -107,6 +107,7 @@ $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=factureave $px = new BarGraph(); $mesg = $px->isGraphKo(); if (! $mesg) { + $px->SetData($data); $px->SetYLabel($langs->trans("AmountAverage")); $px->SetMaxValue($px->GetAmountMaxValue()); $px->SetWidth($GRAPHWIDTH); @@ -133,5 +134,5 @@ print ''; $db->close(); -llxFooter("Dernière modification $Date$ révision $Revision$"); +llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/graph.class.php b/htdocs/graph.class.php index 1e508507784..7e416aff990 100644 --- a/htdocs/graph.class.php +++ b/htdocs/graph.class.php @@ -135,14 +135,14 @@ class Graph // Défini position du graphe (et legende) au sein de l'image if (isset($this->Legend)) { - $this->graph->SetMarginsPixels(60,100,10,30); + $this->graph->SetMarginsPixels(100,100,10,30); $this->graph->SetLegend($this->Legend); $this->graph->SetLegendWorld(13,$this->MaxValue); } else { - $this->graph->SetMarginsPixels(60,10,10,30); + $this->graph->SetMarginsPixels(100,10,10,30); } if (substr($this->MaxValue,0,1) == 1)