Qual: Code cleaner for statistics

This commit is contained in:
Laurent Destailleur 2008-09-07 21:36:42 +00:00
parent dc0b7da9a9
commit e434ffd4f6
8 changed files with 436 additions and 288 deletions

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2005-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (c) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 '<br>';
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 '<br>';
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);
}
}
?>

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (c) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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&amp;file=nbfacture2year-'.$year.'.png';
$filenamenbinvoices = $conf->facture->dir_temp."/invoicesnbinyear-".$year.".png";
$fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;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&amp;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 '<table class="border" width="100%">';
print '<tr><td align="center">'.$langs->trans("Year").'</td><td width="10%" align="center">'.$langs->trans("NumberOfBills").'</td><td align="center">'.$langs->trans("AmountTotal").'</td>';
print '<td align="center" valign="top" rowspan="'.($num + 1).'">';
if ($mesg) { print $mesg; }
else { print '<img src="'.$fileurl.'" alt="Nombre de factures par mois">'; }
print '</td></tr>';
$num = $db->num_rows($resql);
while ($obj = $db->fetch_object($resql))
{
$nbproduct = $obj->nb;
$year = $obj->dm;
$total = price($obj->total);
print "<tr>";
print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td align="center">'.$nbproduct.'</td><td align="center">'.$total.'</td></tr>';
print '<table class="border" width="100%">';
print '<tr height="24"><td align="center">'.$langs->trans("Year").'</td><td width="10%" align="center">'.$langs->trans("NumberOfBills").'</td><td align="center">'.$langs->trans("AmountTotal").'</td>';
print '<td align="center" valign="top" rowspan="'.($num + 2).'">';
if ($mesg) { print $mesg; }
else {
print '<img src="'.$fileurlnbinvoices.'" title="'.$langs->trans("NumberOfBills").'" alt="'.$langs->trans("NumberOfBills").'">';
print "<br>\n";
print '<img src="'.$fileurlamountinvoices.'" title="'.$langs->trans("AmountOfBills").'" alt="'.$langs->trans("AmountOfBills").'">';
}
print '</td></tr>';
}
print '</table>';
$db->free($resql);
while ($obj = $db->fetch_object($resql))
{
$nbproduct = $obj->nb;
$year = $obj->dm;
$total = price($obj->total);
print '<tr height="24">';
print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td>';
print '<td align="right">'.$nbproduct.'</td>';
print '<td align="right">'.$total.'</td></tr>';
}
print '<tr><td colspan="3"></td></tr>';
print '</table>';
$db->free($resql);
}
else
{
dolibarr_print_error($db);
dolibarr_print_error($db);
}
$db->close();

View File

@ -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.= ' <a href="month.php?year='.($year + 1).'">'.img_next().'</a>';
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);

View File

@ -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;

View File

@ -149,7 +149,9 @@ ConfirmClassifyAbandonReasonOtherDesc=This choice will be used in all other case
ConfirmCustomerPayment=Do you confirm this paiement input for <b>%s</b> %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

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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<EFBFBD>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<EFBFBD>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<EFBFBD>e donn<EFBFBD>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;
}
}
?>