From e434ffd4f6755051d66af21ff7eba5a63315adc4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 7 Sep 2008 21:36:42 +0000 Subject: [PATCH] Qual: Code cleaner for statistics --- .../facture/stats/facturestats.class.php | 156 ++++---- htdocs/compta/facture/stats/index.php | 154 +++++--- htdocs/compta/facture/stats/month.php | 36 +- htdocs/core/dolgraph.class.php | 15 +- htdocs/langs/en_US/bills.lang | 4 +- htdocs/langs/en_US/main.lang | 8 +- htdocs/langs/fr_FR/bills.lang | 2 + htdocs/stats.class.php | 349 +++++++++++------- 8 files changed, 436 insertions(+), 288 deletions(-) diff --git a/htdocs/compta/facture/stats/facturestats.class.php b/htdocs/compta/facture/stats/facturestats.class.php index 930836eddd5..77cc5aea4e6 100644 --- a/htdocs/compta/facture/stats/facturestats.class.php +++ b/htdocs/compta/facture/stats/facturestats.class.php @@ -1,6 +1,6 @@ - * Copyright (c) 2005-2007 Laurent Destailleur + * Copyright (c) 2005-2008 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 @@ -15,97 +15,101 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** - \file htdocs/compta/facture/stats/facturestats.class.php - \ingroup factures - \brief Fichier de la classe de gestion des stats des factures - \version $Revision$ -*/ - + * \file htdocs/compta/facture/stats/facturestats.class.php + * \ingroup factures + * \brief Fichier de la classe de gestion des stats des factures + * \version $Id$ + */ include_once DOL_DOCUMENT_ROOT . "/stats.class.php"; - /** - \class FactureStats - \brief Classe permettant la gestion des stats des factures -*/ - + * \class FactureStats + * \brief Classe permettant la gestion des stats des factures + */ class FactureStats extends Stats { - var $db ; + var $db ; - function FactureStats($DB, $socid=0) - { - $this->db = $DB; - $this->socid = $socid; - } + function FactureStats($DB, $socid=0) + { + $this->db = $DB; + $this->socid = $socid; + } - /** - * Renvoie le nombre de facture par mois pour une année donnée - * - */ - function getNbByMonth($year) - { - $sql = "SELECT date_format(datef,'%m') as dm, count(*) FROM ".MAIN_DB_PREFIX."facture"; - $sql .= " WHERE date_format(datef,'%Y') = $year AND fk_statut > 0"; - if ($this->socid) - { - $sql .= " AND fk_soc = ".$this->socid; - } - $sql .= " GROUP BY dm DESC"; - - return $this->_getNbByMonth($year, $sql); - } + /** + * \brief Renvoie le nombre de facture par année + * \return array Array of values + */ + function getNbByYear() + { + $sql = "SELECT date_format(datef,'%Y') as dm, count(*) FROM ".MAIN_DB_PREFIX."facture GROUP BY dm DESC WHERE fk_statut > 0"; + + return $this->_getNbByYear($sql); + } + + + /** + * \brief Renvoie le nombre de facture par mois pour une année donnée + * \param year Year to scan + * \return array Array of values + */ + function getNbByMonth($year) + { + $sql = "SELECT date_format(datef,'%m') as dm, count(*) FROM ".MAIN_DB_PREFIX."facture"; + $sql .= " WHERE date_format(datef,'%Y') = $year AND fk_statut > 0"; + if ($this->socid) + { + $sql .= " AND fk_soc = ".$this->socid; + } + $sql .= " GROUP BY dm DESC"; + + $res=$this->_getNbByMonth($year, $sql); + //var_dump($res);print '
'; + return $res; + } - /** - * Renvoie le nombre de facture par année - * - */ - function getNbByYear() - { - $sql = "SELECT date_format(datef,'%Y') as dm, count(*) FROM ".MAIN_DB_PREFIX."facture GROUP BY dm DESC WHERE fk_statut > 0"; + /** + * \brief Renvoie le montant de facture par mois pour une année donnée + * \param year Year to scan + * \return array Array of values + */ + function getAmountByMonth($year) + { + $sql = "SELECT date_format(datef,'%m') as dm, sum(total) FROM ".MAIN_DB_PREFIX."facture"; + $sql .= " WHERE date_format(datef,'%Y') = $year AND fk_statut > 0"; + if ($this->socid) + { + $sql .= " AND fk_soc = ".$this->socid; + } + $sql .= " GROUP BY dm DESC"; - return $this->_getNbByYear($sql); - } - - /** - * Renvoie le nombre de facture par mois pour une année donnée - * - */ - function getAmountByMonth($year) - { - $sql = "SELECT date_format(datef,'%m') as dm, sum(total) FROM ".MAIN_DB_PREFIX."facture"; - $sql .= " WHERE date_format(datef,'%Y') = $year AND fk_statut > 0"; - if ($this->socid) - { - $sql .= " AND fk_soc = ".$this->socid; - } - $sql .= " GROUP BY dm DESC"; + $res=$this->_getAmountByMonth($year, $sql); + //var_dump($res);print '
'; + return $res; + } - return $this->_getAmountByMonth($year, $sql); - } - /** - * - * - */ - function getAverageByMonth($year) - { - $sql = "SELECT date_format(datef,'%m') as dm, avg(total) FROM ".MAIN_DB_PREFIX."facture"; - $sql .= " WHERE date_format(datef,'%Y') = $year AND fk_statut > 0"; - if ($this->socid) - { - $sql .= " AND fk_soc = ".$this->socid; - } - $sql .= " GROUP BY dm DESC"; + /** + * \brief Return average amount + * \param year Year to scan + * \return array Array of values + */ + function getAverageByMonth($year) + { + $sql = "SELECT date_format(datef,'%m') as dm, avg(total) FROM ".MAIN_DB_PREFIX."facture"; + $sql .= " WHERE date_format(datef,'%Y') = $year AND fk_statut > 0"; + if ($this->socid) + { + $sql .= " AND fk_soc = ".$this->socid; + } + $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 d6a21fabed7..96c57ef06af 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -1,6 +1,6 @@ - * Copyright (c) 2004-2006 Laurent Destailleur + * Copyright (c) 2004-2008 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 @@ -18,11 +18,11 @@ */ /** - \file htdocs/compta/facture/stats/index.php - \ingroup facture - \brief Page des stats factures - \version $Id$ -*/ + * \file htdocs/compta/facture/stats/index.php + * \ingroup facture + * \brief Page des stats factures + * \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php"); @@ -31,85 +31,143 @@ $WIDTH=500; $HEIGHT=200; // Sécurité accés client -if ($user->societe_id > 0) +if ($user->societe_id > 0) { - $action = ''; - $socid = $user->societe_id; + $action = ''; + $socid = $user->societe_id; } + +/* + * View + */ + llxHeader(); print_fiche_titre($langs->trans("BillsStatistics"), $mesg); -$stats = new FactureStats($db, $socid); +create_exdir($conf->facture->dir_temp); + $year = strftime("%Y", time()); $startyear=$year-2; $endyear=$year; + +$stats = new FactureStats($db, $socid); + + +// Build graphic number of invoices $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); +//var_dump($data); +// $data = array(array('Lib',val1,val2,val3),...) -create_exdir($conf->facture->dir_temp); - -$filename = $conf->facture->dir_temp."/nbfacture2year-".$year.".png"; -$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=nbfacture2year-'.$year.'.png'; +$filenamenbinvoices = $conf->facture->dir_temp."/invoicesnbinyear-".$year.".png"; +$fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png'; $px = new DolGraph(); $mesg = $px->isGraphKo(); if (! $mesg) { - $px->SetData($data); - $px->SetPrecisionY(0); + $px->SetData($data); + $px->SetPrecisionY(0); $i=$startyear; while ($i <= $endyear) { $legend[]=$i; $i++; } - $px->SetLegend($legend); - $px->SetMaxValue($px->GetCeilMaxValue()); - $px->SetWidth($WIDTH); - $px->SetHeight($HEIGHT); - $px->SetYLabel($langs->trans("NbOfInvoices")); + $px->SetLegend($legend); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetWidth($WIDTH); + $px->SetHeight($HEIGHT); + $px->SetYLabel($langs->trans("NumberOfBills")); $px->SetShading(3); - $px->SetHorizTickIncrement(1); - $px->SetPrecisionY(0); - $px->mode='depth'; - $px->draw($filename); + $px->SetHorizTickIncrement(1); + $px->SetPrecisionY(0); + $px->mode='depth'; + $px->SetTitle($langs->trans("NumberOfBillsByMonth")); + + $px->draw($filenamenbinvoices); } - -$sql = "SELECT count(*) as nb, date_format(datef,'%Y') as dm, sum(total) as total FROM ".MAIN_DB_PREFIX."facture WHERE fk_statut > 0 "; + +// Build graphic amount of invoices +$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear); +//var_dump($data); +// $data = array(array('Lib',val1,val2,val3),...) + +$filenameamountinvoices = $conf->facture->dir_temp."/invoicesamountinyear-".$year.".png"; +$fileurlamountinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.'.png'; + +$px = new DolGraph(); +$mesg = $px->isGraphKo(); +if (! $mesg) +{ + $px->SetData($data); + $px->SetPrecisionY(0); + $i=$startyear; + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px->SetLegend($legend); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetMinValue(min(0,$px->GetFloorMinValue())); + $px->SetWidth($WIDTH); + $px->SetHeight($HEIGHT); + $px->SetYLabel($langs->trans("AmountOfBills")); + $px->SetShading(3); + $px->SetHorizTickIncrement(1); + $px->SetPrecisionY(0); + $px->mode='depth'; + $px->SetTitle($langs->trans("AmountOfBillsByMonthHT")); + + $px->draw($filenameamountinvoices); +} + + +// Show array +$sql = "SELECT date_format(datef,'%Y') as dm, count(*) as nb, sum(total) as total FROM ".MAIN_DB_PREFIX."facture WHERE fk_statut > 0 "; if ($socid) { - $sql .= " AND fk_soc=$socid"; + $sql .= " AND fk_soc=$socid"; } $sql.= " GROUP BY dm DESC;"; $resql=$db->query($sql); if ($resql) { - $num = $db->num_rows($resql); - - print ''; - print ''; - print ''; + $num = $db->num_rows($resql); - while ($obj = $db->fetch_object($resql)) - { - $nbproduct = $obj->nb; - $year = $obj->dm; - $total = price($obj->total); - print ""; - print ''; + print '
'.$langs->trans("Year").''.$langs->trans("NumberOfBills").''.$langs->trans("AmountTotal").''; - if ($mesg) { print $mesg; } - else { print 'Nombre de factures par mois'; } - print '
'.$year.''.$nbproduct.''.$total.'
'; + print ''; + print ''; - } - - print '
'.$langs->trans("Year").''.$langs->trans("NumberOfBills").''.$langs->trans("AmountTotal").''; + if ($mesg) { print $mesg; } + else { + print ''.$langs->trans('; + print "
\n"; + print ''.$langs->trans('; + } + print '
'; - $db->free($resql); + while ($obj = $db->fetch_object($resql)) + { + $nbproduct = $obj->nb; + $year = $obj->dm; + $total = price($obj->total); + print ''; + print ''.$year.''; + print ''.$nbproduct.''; + print ''.$total.''; + + } + + print ''; + + print ''; + $db->free($resql); } else { - dolibarr_print_error($db); + dolibarr_print_error($db); } $db->close(); diff --git a/htdocs/compta/facture/stats/month.php b/htdocs/compta/facture/stats/month.php index 69d9db820ba..e4ecaa4b847 100644 --- a/htdocs/compta/facture/stats/month.php +++ b/htdocs/compta/facture/stats/month.php @@ -18,11 +18,11 @@ */ /** - \file htdocs/compta/facture/stats/month.php - \ingroup facture - \brief Page des stats factures par mois - \version $Id$ -*/ + * \file htdocs/compta/facture/stats/month.php + * \ingroup facture + * \brief Page des stats factures par mois + * \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php"); @@ -38,6 +38,10 @@ if ($user->societe_id > 0) } +/* + * View + */ + llxHeader(); $year = isset($_GET["year"])?$_GET["year"]:date("Y",time()); @@ -49,10 +53,11 @@ $mesg.= ' '.img_next().''; print_fiche_titre($langs->trans("BillsStatistics"), $mesg); $stats = new FactureStats($db, $socid); -$data = $stats->getNbByMonth($year); - create_exdir($conf->facture->dir_temp); + +$data = $stats->getNbByMonth($year); + $filename = $conf->facture->dir_temp."/facture".$year.".png"; $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=facture'.$year.'.png'; @@ -62,7 +67,8 @@ if (! $mesg) { $px->SetData($data); $px->SetMaxValue($px->GetCeilMaxValue()); - $px->SetPrecisionY(0); + $px->SetMinValue($px->GetFloorMinValue()); + $px->SetPrecisionY(0); $px->SetWidth($GRAPHWIDTH); $px->SetHeight($GRAPHHEIGHT); $px->SetShading(3); @@ -71,14 +77,9 @@ if (! $mesg) $px->draw($filename); } -$res = $stats->getAmountByMonth($year); -$data = array(); -for ($i = 1 ; $i < 13 ; $i++) -{ - $data[$i-1] = array(ucfirst(substr(strftime("%b",dolibarr_mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]); -} +$data = $stats->getAmountByMonth($year); $filename_amount = $conf->facture->dir_temp."/factureamount".$year.".png"; $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=factureamount'.$year.'.png'; @@ -90,7 +91,8 @@ if (! $mesg) $px->SetData($data); $px->SetYLabel($langs->trans("AmountTotal")); $px->SetMaxValue($px->GetCeilMaxValue()); - $px->SetPrecisionY(0); + $px->SetMinValue($px->GetFloorMinValue()); + $px->SetPrecisionY(0); $px->SetWidth($GRAPHWIDTH); $px->SetHeight($GRAPHHEIGHT); $px->SetShading(3); @@ -98,6 +100,9 @@ if (! $mesg) $px->SetPrecisionY(0); $px->draw($filename_amount); } + + + $res = $stats->getAverageByMonth($year); $data = array(); @@ -118,6 +123,7 @@ if (! $mesg) $px->SetPrecisionY(0); $px->SetYLabel($langs->trans("AmountAverage")); $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetMinValue($px->GetFloorMinValue()); $px->SetWidth($GRAPHWIDTH); $px->SetHeight($GRAPHHEIGHT); $px->SetShading(5); diff --git a/htdocs/core/dolgraph.class.php b/htdocs/core/dolgraph.class.php index 1e309c0fb29..1f36c5f9f9d 100644 --- a/htdocs/core/dolgraph.class.php +++ b/htdocs/core/dolgraph.class.php @@ -347,6 +347,11 @@ class DolGraph return $vals[0]; } + /** + * Return max value of all data + * + * @return int Max value of all data + */ function GetCeilMaxValue() { $max = $this->GetMaxValueInData(); @@ -357,12 +362,19 @@ class DolGraph { $factor*=10; } - $res=ceil($max/$factor)*$factor; + + $res=0; + if (is_numeric($max)) $res=ceil($max/$factor)*$factor; //print "max=".$max." res=".$res; return $res; } + /** + * Return min value of all data + * + * @return int Max value of all data + */ function GetFloorMinValue() { $min = $this->GetMinValueInData(); @@ -373,6 +385,7 @@ class DolGraph { $factor*=10; } + $res=floor($min/$factor)*$factor; //print "min=".$min." res=".$res; diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 6ced22a5db6..678b4df78d2 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -149,7 +149,9 @@ ConfirmClassifyAbandonReasonOtherDesc=This choice will be used in all other case ConfirmCustomerPayment=Do you confirm this paiement input for %s %s ? ValidateBill=Validate invoice NumberOfBills=Nb of invoices -NumberOfBillsByMonth=Nb of invoices by month +NumberOfBillsByMonthHT=Nb of invoices by month (net of tax) +AmountOfBills=Amount of invoices +AmountOfBillsByMonth=Amount of invoices by month ShowSocialContribution=Show social contribution ShowBill=Show invoice ShowInvoice=Show invoice diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 2dd6fc63e82..ad8589e192f 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -221,10 +221,10 @@ AmountTTC=Amount (inc. tax) AmountVAT=Amount VAT AmountTotal=Total amount AmountAverage=Average amount -PriceQtyHT=Price for this quantity HT -PriceQtyMinHT=Price quantity min. HT -PriceQtyTTC=Price for this quantity TTC -PriceQtyMinTTC=Price quantity min. TTC +PriceQtyHT=Price for this quantity (net of tax) +PriceQtyMinHT=Price quantity min. (net of tax) +PriceQtyTTC=Price for this quantity (inc. tax) +PriceQtyMinTTC=Price quantity min. (inc. of tax) Percentage=Pourcentage Total=Total SubTotal=Subtotal diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index 57f4d3232fc..8887bd7400a 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -150,6 +150,8 @@ ConfirmCustomerPayment=Confirmez-vous la saisie de ce r ValidateBill=Valider facture NumberOfBills=Nb de factures NumberOfBillsByMonth=Nb de factures par mois +AmountOfBills=Montant de factures +AmountOfBillsByMonthHT=Montant de factures par mois (HT) ShowSocialContribution=Afficher charge sociale ShowBill=Afficher facture ShowInvoice=Afficher facture diff --git a/htdocs/stats.class.php b/htdocs/stats.class.php index 2669f71261e..fb8ea15fdbe 100644 --- a/htdocs/stats.class.php +++ b/htdocs/stats.class.php @@ -1,5 +1,6 @@ + * Copyright (c) 2008 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 @@ -14,169 +15,231 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ -class Stats +/** + * \file htdocs/stats.class.php + * \ingroup core + * \brief Common class to manage statistics reports + * \version $Id$ + */ +class Stats { - var $db ; + var $db ; - function Stats($DB) - { - $this->db = $DB; - } - - function getNbByMonthWithPrevYear($endyear,$startyear) - { - $datay=array(); - - $year=$startyear; - while($year <= $endyear) + function Stats($DB) { - $datay[$year] = $this->getNbByMonth($year); - $year++; + $this->db = $DB; } - $data = array(); - - for ($i = 0 ; $i < 12 ; $i++) - { - $data[$i][]=$datay[$endyear][$i][0]; + /** + * Return nb of entity by month for several years + * + * @param endyear Start year + * @param startyear End year + * @return array Array of values + */ + function getNbByMonthWithPrevYear($endyear,$startyear) + { + $datay=array(); + $year=$startyear; while($year <= $endyear) { - $data[$i][]=$datay[$year][$i][1]; + $datay[$year] = $this->getNbByMonth($year); $year++; } - } - return $data; - } + + $data = array(); + + for ($i = 0 ; $i < 12 ; $i++) + { + $data[$i][]=$datay[$endyear][$i][0]; + $year=$startyear; + while($year <= $endyear) + { + $data[$i][]=$datay[$year][$i][1]; + $year++; + } + } + + // return array(array('Month',val1,val2,val3),...) + return $data; + } + + /** + * Return amount of entity by month for several years + * + * @param endyear Start year + * @param startyear End year + * @return array Array of values + */ + function getAmountByMonthWithPrevYear($endyear,$startyear) + { + $datay=array(); + + $year=$startyear; + while($year <= $endyear) + { + $datay[$year] = $this->getAmountByMonth($year); + $year++; + } + + $data = array(); + + for ($i = 0 ; $i < 12 ; $i++) + { + $data[$i][]=$datay[$endyear][$i][0]; + $year=$startyear; + while($year <= $endyear) + { + $data[$i][]=$datay[$year][$i][1]; + $year++; + } + } + + return $data; + } + + + /** + * \brief Renvoie le nombre d'element par ann�e + * + */ + function _getNbByYear($sql) + { + $result = array(); + + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + $result[$i] = $row; + $i++; + } + $this->db->free($resql); + } + else { + dolibarr_print_error($this->db); + } + return $result; + } + - /** - * \brief Renvoie le nombre de proposition par mois pour une annee donnee - * - */ - function _getNbByMonth($year, $sql) - { - $result = array(); - - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($resql); - $j = $row[0] * 1; - $result[$j] = $row[1]; - $i++; - } - $this->db->free($resql); - } - - for ($i = 1 ; $i < 13 ; $i++) - { - $res[$i] = $result[$i] + 0; - } - - $data = array(); - - for ($i = 1 ; $i < 13 ; $i++) - { - $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,0,0,$i,1,$year)),0,3)), $res[$i]); - } - - return $data; - } + /** + * \brief Renvoie le nombre de proposition par mois pour une annee donnee + * + */ + function _getNbByMonth($year, $sql) + { + $result = array(); + + $resql=$this->db->query($sql); + dolibarr_syslog("Stats::_getNbByMonth sql=".$sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; $j = 0; + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + $j = $row[0] * 1; + $result[$j] = $row[1]; + $i++; + } + $this->db->free($resql); + } + + for ($i = 1 ; $i < 13 ; $i++) + { + $res[$i] = $result[$i] + 0; + } + + $data = array(); + + for ($i = 1 ; $i < 13 ; $i++) + { + $data[$i-1] = array(ucfirst(substr(strftime("%b",dolibarr_mktime(12,0,0,$i,1,$year)),0,3)), $res[$i]); + } + + return $data; + } - /** - * \brief Renvoie le nombre d'element par ann�e - * - */ - function _getNbByYear($sql) - { - $result = array(); - - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) - { - $row = $this->db->fetch_row($i); - $result[$i] = $row; - $i++; - } - $this->db->free(); - } - else { - dolibarr_print_error($this->db); - } - return $result; - } + /** + * \brief Renvoie le nombre d'element par mois pour une annee donnee + * + */ + function _getAmountByMonth($year, $sql) + { + $result = array(); - /** - * \brief Renvoie le nombre d'element par mois pour une ann�e donn�e - * - */ - - function _getAmountByMonth($year, $sql) - { - $result = array(); + dolibarr_syslog("Stats::_getAmountByMonth sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + $j = $row[0] * 1; + $result[$j] = $row[1]; + $i++; + } + $this->db->free($resql); + } - 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; - } + for ($i = 1 ; $i < 13 ; $i++) + { + $res[$i] = (int) round($result[$i]) + 0; + } - return $res; - } - /** - * - * - */ - function _getAverageByMonth($year, $sql) - { - $result = array(); + $data = array(); - 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; - } + for ($i = 1 ; $i < 13 ; $i++) + { + $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,0,0,$i,1,$year)),0,3)), $res[$i]); + } - return $res; - } + return $data; + } + + /** + * + * + */ + function _getAverageByMonth($year, $sql) + { + $result = array(); + + dolibarr_syslog("Stats::_getAmountByMonth sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; $j = 0; + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + $j = $row[0] * 1; + $result[$j] = $row[1]; + $i++; + } + $this->db->free($resql); + } + + for ($i = 1 ; $i < 13 ; $i++) + { + $res[$i] = $result[$i] + 0; + } + + return $res; + } } ?>