Qual: Code cleaner for statistics
This commit is contained in:
parent
dc0b7da9a9
commit
e434ffd4f6
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* 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
|
* 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
|
* 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
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/compta/facture/stats/facturestats.class.php
|
* \file htdocs/compta/facture/stats/facturestats.class.php
|
||||||
\ingroup factures
|
* \ingroup factures
|
||||||
\brief Fichier de la classe de gestion des stats des factures
|
* \brief Fichier de la classe de gestion des stats des factures
|
||||||
\version $Revision$
|
* \version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
|
include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\class FactureStats
|
* \class FactureStats
|
||||||
\brief Classe permettant la gestion des stats des factures
|
* \brief Classe permettant la gestion des stats des factures
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class FactureStats extends Stats
|
class FactureStats extends Stats
|
||||||
{
|
{
|
||||||
var $db ;
|
var $db ;
|
||||||
|
|
||||||
function FactureStats($DB, $socid=0)
|
function FactureStats($DB, $socid=0)
|
||||||
{
|
{
|
||||||
$this->db = $DB;
|
$this->db = $DB;
|
||||||
$this->socid = $socid;
|
$this->socid = $socid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renvoie le nombre de facture par mois pour une année donnée
|
* \brief Renvoie le nombre de facture par année
|
||||||
*
|
* \return array Array of values
|
||||||
*/
|
*/
|
||||||
function getNbByMonth($year)
|
function getNbByYear()
|
||||||
{
|
{
|
||||||
$sql = "SELECT date_format(datef,'%m') as dm, count(*) FROM ".MAIN_DB_PREFIX."facture";
|
$sql = "SELECT date_format(datef,'%Y') as dm, count(*) FROM ".MAIN_DB_PREFIX."facture GROUP BY dm DESC WHERE fk_statut > 0";
|
||||||
$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);
|
return $this->_getNbByYear($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renvoie le nombre de facture par année
|
* \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 getNbByYear()
|
*/
|
||||||
{
|
function getNbByMonth($year)
|
||||||
$sql = "SELECT date_format(datef,'%Y') as dm, count(*) FROM ".MAIN_DB_PREFIX."facture GROUP BY dm DESC WHERE fk_statut > 0";
|
{
|
||||||
|
$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->_getNbByYear($sql);
|
$res=$this->_getNbByMonth($year, $sql);
|
||||||
}
|
//var_dump($res);print '<br>';
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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";
|
|
||||||
|
|
||||||
return $this->_getAmountByMonth($year, $sql);
|
/**
|
||||||
}
|
* \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)
|
||||||
function getAverageByMonth($year)
|
{
|
||||||
{
|
$sql = "SELECT date_format(datef,'%m') as dm, sum(total) FROM ".MAIN_DB_PREFIX."facture";
|
||||||
$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";
|
||||||
$sql .= " WHERE date_format(datef,'%Y') = $year AND fk_statut > 0";
|
if ($this->socid)
|
||||||
if ($this->socid)
|
{
|
||||||
{
|
$sql .= " AND fk_soc = ".$this->socid;
|
||||||
$sql .= " AND fk_soc = ".$this->socid;
|
}
|
||||||
}
|
$sql .= " GROUP BY dm DESC";
|
||||||
$sql .= " GROUP BY dm DESC";
|
|
||||||
|
|
||||||
return $this->_getAverageByMonth($year, $sql);
|
$res=$this->_getAmountByMonth($year, $sql);
|
||||||
}
|
//var_dump($res);print '<br>';
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -18,11 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/compta/facture/stats/index.php
|
* \file htdocs/compta/facture/stats/index.php
|
||||||
\ingroup facture
|
* \ingroup facture
|
||||||
\brief Page des stats factures
|
* \brief Page des stats factures
|
||||||
\version $Id$
|
* \version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
|
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
|
||||||
@ -33,83 +33,141 @@ $HEIGHT=200;
|
|||||||
// Sécurité accés client
|
// Sécurité accés client
|
||||||
if ($user->societe_id > 0)
|
if ($user->societe_id > 0)
|
||||||
{
|
{
|
||||||
$action = '';
|
$action = '';
|
||||||
$socid = $user->societe_id;
|
$socid = $user->societe_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
llxHeader();
|
llxHeader();
|
||||||
|
|
||||||
print_fiche_titre($langs->trans("BillsStatistics"), $mesg);
|
print_fiche_titre($langs->trans("BillsStatistics"), $mesg);
|
||||||
|
|
||||||
$stats = new FactureStats($db, $socid);
|
create_exdir($conf->facture->dir_temp);
|
||||||
|
|
||||||
$year = strftime("%Y", time());
|
$year = strftime("%Y", time());
|
||||||
$startyear=$year-2;
|
$startyear=$year-2;
|
||||||
$endyear=$year;
|
$endyear=$year;
|
||||||
|
|
||||||
|
$stats = new FactureStats($db, $socid);
|
||||||
|
|
||||||
|
|
||||||
|
// Build graphic number of invoices
|
||||||
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
|
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
|
||||||
|
//var_dump($data);
|
||||||
|
// $data = array(array('Lib',val1,val2,val3),...)
|
||||||
|
|
||||||
create_exdir($conf->facture->dir_temp);
|
$filenamenbinvoices = $conf->facture->dir_temp."/invoicesnbinyear-".$year.".png";
|
||||||
|
$fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png';
|
||||||
$filename = $conf->facture->dir_temp."/nbfacture2year-".$year.".png";
|
|
||||||
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=nbfacture2year-'.$year.'.png';
|
|
||||||
|
|
||||||
$px = new DolGraph();
|
$px = new DolGraph();
|
||||||
$mesg = $px->isGraphKo();
|
$mesg = $px->isGraphKo();
|
||||||
if (! $mesg)
|
if (! $mesg)
|
||||||
{
|
{
|
||||||
$px->SetData($data);
|
$px->SetData($data);
|
||||||
$px->SetPrecisionY(0);
|
$px->SetPrecisionY(0);
|
||||||
$i=$startyear;
|
$i=$startyear;
|
||||||
while ($i <= $endyear)
|
while ($i <= $endyear)
|
||||||
{
|
{
|
||||||
$legend[]=$i;
|
$legend[]=$i;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$px->SetLegend($legend);
|
$px->SetLegend($legend);
|
||||||
$px->SetMaxValue($px->GetCeilMaxValue());
|
$px->SetMaxValue($px->GetCeilMaxValue());
|
||||||
$px->SetWidth($WIDTH);
|
$px->SetWidth($WIDTH);
|
||||||
$px->SetHeight($HEIGHT);
|
$px->SetHeight($HEIGHT);
|
||||||
$px->SetYLabel($langs->trans("NbOfInvoices"));
|
$px->SetYLabel($langs->trans("NumberOfBills"));
|
||||||
$px->SetShading(3);
|
$px->SetShading(3);
|
||||||
$px->SetHorizTickIncrement(1);
|
$px->SetHorizTickIncrement(1);
|
||||||
$px->SetPrecisionY(0);
|
$px->SetPrecisionY(0);
|
||||||
$px->mode='depth';
|
$px->mode='depth';
|
||||||
$px->draw($filename);
|
$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)
|
if ($socid)
|
||||||
{
|
{
|
||||||
$sql .= " AND fk_soc=$socid";
|
$sql .= " AND fk_soc=$socid";
|
||||||
}
|
}
|
||||||
$sql.= " GROUP BY dm DESC;";
|
$sql.= " GROUP BY dm DESC;";
|
||||||
$resql=$db->query($sql);
|
$resql=$db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
|
|
||||||
print '<table class="border" width="100%">';
|
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 '<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 + 1).'">';
|
print '<td align="center" valign="top" rowspan="'.($num + 2).'">';
|
||||||
if ($mesg) { print $mesg; }
|
if ($mesg) { print $mesg; }
|
||||||
else { print '<img src="'.$fileurl.'" alt="Nombre de factures par mois">'; }
|
else {
|
||||||
print '</td></tr>';
|
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>';
|
||||||
|
|
||||||
while ($obj = $db->fetch_object($resql))
|
while ($obj = $db->fetch_object($resql))
|
||||||
{
|
{
|
||||||
$nbproduct = $obj->nb;
|
$nbproduct = $obj->nb;
|
||||||
$year = $obj->dm;
|
$year = $obj->dm;
|
||||||
$total = price($obj->total);
|
$total = price($obj->total);
|
||||||
print "<tr>";
|
print '<tr height="24">';
|
||||||
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 '<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 '</table>';
|
print '<tr><td colspan="3"></td></tr>';
|
||||||
$db->free($resql);
|
|
||||||
|
print '</table>';
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($db);
|
dolibarr_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|||||||
@ -18,11 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/compta/facture/stats/month.php
|
* \file htdocs/compta/facture/stats/month.php
|
||||||
\ingroup facture
|
* \ingroup facture
|
||||||
\brief Page des stats factures par mois
|
* \brief Page des stats factures par mois
|
||||||
\version $Id$
|
* \version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
|
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
|
||||||
@ -38,6 +38,10 @@ if ($user->societe_id > 0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* View
|
||||||
|
*/
|
||||||
|
|
||||||
llxHeader();
|
llxHeader();
|
||||||
|
|
||||||
$year = isset($_GET["year"])?$_GET["year"]:date("Y",time());
|
$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);
|
print_fiche_titre($langs->trans("BillsStatistics"), $mesg);
|
||||||
|
|
||||||
$stats = new FactureStats($db, $socid);
|
$stats = new FactureStats($db, $socid);
|
||||||
$data = $stats->getNbByMonth($year);
|
|
||||||
|
|
||||||
create_exdir($conf->facture->dir_temp);
|
create_exdir($conf->facture->dir_temp);
|
||||||
|
|
||||||
|
|
||||||
|
$data = $stats->getNbByMonth($year);
|
||||||
|
|
||||||
$filename = $conf->facture->dir_temp."/facture".$year.".png";
|
$filename = $conf->facture->dir_temp."/facture".$year.".png";
|
||||||
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=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->SetData($data);
|
||||||
$px->SetMaxValue($px->GetCeilMaxValue());
|
$px->SetMaxValue($px->GetCeilMaxValue());
|
||||||
$px->SetPrecisionY(0);
|
$px->SetMinValue($px->GetFloorMinValue());
|
||||||
|
$px->SetPrecisionY(0);
|
||||||
$px->SetWidth($GRAPHWIDTH);
|
$px->SetWidth($GRAPHWIDTH);
|
||||||
$px->SetHeight($GRAPHHEIGHT);
|
$px->SetHeight($GRAPHHEIGHT);
|
||||||
$px->SetShading(3);
|
$px->SetShading(3);
|
||||||
@ -71,14 +77,9 @@ if (! $mesg)
|
|||||||
$px->draw($filename);
|
$px->draw($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $stats->getAmountByMonth($year);
|
|
||||||
|
|
||||||
$data = array();
|
|
||||||
|
|
||||||
for ($i = 1 ; $i < 13 ; $i++)
|
$data = $stats->getAmountByMonth($year);
|
||||||
{
|
|
||||||
$data[$i-1] = array(ucfirst(substr(strftime("%b",dolibarr_mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename_amount = $conf->facture->dir_temp."/factureamount".$year.".png";
|
$filename_amount = $conf->facture->dir_temp."/factureamount".$year.".png";
|
||||||
$fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=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->SetData($data);
|
||||||
$px->SetYLabel($langs->trans("AmountTotal"));
|
$px->SetYLabel($langs->trans("AmountTotal"));
|
||||||
$px->SetMaxValue($px->GetCeilMaxValue());
|
$px->SetMaxValue($px->GetCeilMaxValue());
|
||||||
$px->SetPrecisionY(0);
|
$px->SetMinValue($px->GetFloorMinValue());
|
||||||
|
$px->SetPrecisionY(0);
|
||||||
$px->SetWidth($GRAPHWIDTH);
|
$px->SetWidth($GRAPHWIDTH);
|
||||||
$px->SetHeight($GRAPHHEIGHT);
|
$px->SetHeight($GRAPHHEIGHT);
|
||||||
$px->SetShading(3);
|
$px->SetShading(3);
|
||||||
@ -98,6 +100,9 @@ if (! $mesg)
|
|||||||
$px->SetPrecisionY(0);
|
$px->SetPrecisionY(0);
|
||||||
$px->draw($filename_amount);
|
$px->draw($filename_amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$res = $stats->getAverageByMonth($year);
|
$res = $stats->getAverageByMonth($year);
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
@ -118,6 +123,7 @@ if (! $mesg)
|
|||||||
$px->SetPrecisionY(0);
|
$px->SetPrecisionY(0);
|
||||||
$px->SetYLabel($langs->trans("AmountAverage"));
|
$px->SetYLabel($langs->trans("AmountAverage"));
|
||||||
$px->SetMaxValue($px->GetCeilMaxValue());
|
$px->SetMaxValue($px->GetCeilMaxValue());
|
||||||
|
$px->SetMinValue($px->GetFloorMinValue());
|
||||||
$px->SetWidth($GRAPHWIDTH);
|
$px->SetWidth($GRAPHWIDTH);
|
||||||
$px->SetHeight($GRAPHHEIGHT);
|
$px->SetHeight($GRAPHHEIGHT);
|
||||||
$px->SetShading(5);
|
$px->SetShading(5);
|
||||||
|
|||||||
@ -347,6 +347,11 @@ class DolGraph
|
|||||||
return $vals[0];
|
return $vals[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return max value of all data
|
||||||
|
*
|
||||||
|
* @return int Max value of all data
|
||||||
|
*/
|
||||||
function GetCeilMaxValue()
|
function GetCeilMaxValue()
|
||||||
{
|
{
|
||||||
$max = $this->GetMaxValueInData();
|
$max = $this->GetMaxValueInData();
|
||||||
@ -357,12 +362,19 @@ class DolGraph
|
|||||||
{
|
{
|
||||||
$factor*=10;
|
$factor*=10;
|
||||||
}
|
}
|
||||||
$res=ceil($max/$factor)*$factor;
|
|
||||||
|
$res=0;
|
||||||
|
if (is_numeric($max)) $res=ceil($max/$factor)*$factor;
|
||||||
|
|
||||||
//print "max=".$max." res=".$res;
|
//print "max=".$max." res=".$res;
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return min value of all data
|
||||||
|
*
|
||||||
|
* @return int Max value of all data
|
||||||
|
*/
|
||||||
function GetFloorMinValue()
|
function GetFloorMinValue()
|
||||||
{
|
{
|
||||||
$min = $this->GetMinValueInData();
|
$min = $this->GetMinValueInData();
|
||||||
@ -373,6 +385,7 @@ class DolGraph
|
|||||||
{
|
{
|
||||||
$factor*=10;
|
$factor*=10;
|
||||||
}
|
}
|
||||||
|
|
||||||
$res=floor($min/$factor)*$factor;
|
$res=floor($min/$factor)*$factor;
|
||||||
|
|
||||||
//print "min=".$min." res=".$res;
|
//print "min=".$min." res=".$res;
|
||||||
|
|||||||
@ -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 ?
|
ConfirmCustomerPayment=Do you confirm this paiement input for <b>%s</b> %s ?
|
||||||
ValidateBill=Validate invoice
|
ValidateBill=Validate invoice
|
||||||
NumberOfBills=Nb of invoices
|
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
|
ShowSocialContribution=Show social contribution
|
||||||
ShowBill=Show invoice
|
ShowBill=Show invoice
|
||||||
ShowInvoice=Show invoice
|
ShowInvoice=Show invoice
|
||||||
|
|||||||
@ -221,10 +221,10 @@ AmountTTC=Amount (inc. tax)
|
|||||||
AmountVAT=Amount VAT
|
AmountVAT=Amount VAT
|
||||||
AmountTotal=Total amount
|
AmountTotal=Total amount
|
||||||
AmountAverage=Average amount
|
AmountAverage=Average amount
|
||||||
PriceQtyHT=Price for this quantity HT
|
PriceQtyHT=Price for this quantity (net of tax)
|
||||||
PriceQtyMinHT=Price quantity min. HT
|
PriceQtyMinHT=Price quantity min. (net of tax)
|
||||||
PriceQtyTTC=Price for this quantity TTC
|
PriceQtyTTC=Price for this quantity (inc. tax)
|
||||||
PriceQtyMinTTC=Price quantity min. TTC
|
PriceQtyMinTTC=Price quantity min. (inc. of tax)
|
||||||
Percentage=Pourcentage
|
Percentage=Pourcentage
|
||||||
Total=Total
|
Total=Total
|
||||||
SubTotal=Subtotal
|
SubTotal=Subtotal
|
||||||
|
|||||||
@ -150,6 +150,8 @@ ConfirmCustomerPayment=Confirmez-vous la saisie de ce r
|
|||||||
ValidateBill=Valider facture
|
ValidateBill=Valider facture
|
||||||
NumberOfBills=Nb de factures
|
NumberOfBills=Nb de factures
|
||||||
NumberOfBillsByMonth=Nb de factures par mois
|
NumberOfBillsByMonth=Nb de factures par mois
|
||||||
|
AmountOfBills=Montant de factures
|
||||||
|
AmountOfBillsByMonthHT=Montant de factures par mois (HT)
|
||||||
ShowSocialContribution=Afficher charge sociale
|
ShowSocialContribution=Afficher charge sociale
|
||||||
ShowBill=Afficher facture
|
ShowBill=Afficher facture
|
||||||
ShowInvoice=Afficher facture
|
ShowInvoice=Afficher facture
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* 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
|
* 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
|
* 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
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file htdocs/stats.class.php
|
||||||
|
* \ingroup core
|
||||||
|
* \brief Common class to manage statistics reports
|
||||||
|
* \version $Id$
|
||||||
|
*/
|
||||||
class Stats
|
class Stats
|
||||||
{
|
{
|
||||||
var $db ;
|
var $db ;
|
||||||
|
|
||||||
function Stats($DB)
|
function Stats($DB)
|
||||||
{
|
|
||||||
$this->db = $DB;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNbByMonthWithPrevYear($endyear,$startyear)
|
|
||||||
{
|
|
||||||
$datay=array();
|
|
||||||
|
|
||||||
$year=$startyear;
|
|
||||||
while($year <= $endyear)
|
|
||||||
{
|
{
|
||||||
$datay[$year] = $this->getNbByMonth($year);
|
$this->db = $DB;
|
||||||
$year++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array();
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
for ($i = 0 ; $i < 12 ; $i++)
|
|
||||||
{
|
|
||||||
$data[$i][]=$datay[$endyear][$i][0];
|
|
||||||
$year=$startyear;
|
$year=$startyear;
|
||||||
while($year <= $endyear)
|
while($year <= $endyear)
|
||||||
{
|
{
|
||||||
$data[$i][]=$datay[$year][$i][1];
|
$datay[$year] = $this->getNbByMonth($year);
|
||||||
$year++;
|
$year++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$data = array();
|
||||||
* \brief Renvoie le nombre de proposition par mois pour une annee donnee
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function _getNbByMonth($year, $sql)
|
|
||||||
{
|
|
||||||
$result = array();
|
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
for ($i = 0 ; $i < 12 ; $i++)
|
||||||
if ($resql)
|
{
|
||||||
{
|
$data[$i][]=$datay[$endyear][$i][0];
|
||||||
$num = $this->db->num_rows($resql);
|
$year=$startyear;
|
||||||
$i = 0;
|
while($year <= $endyear)
|
||||||
while ($i < $num)
|
{
|
||||||
{
|
$data[$i][]=$datay[$year][$i][1];
|
||||||
$row = $this->db->fetch_row($resql);
|
$year++;
|
||||||
$j = $row[0] * 1;
|
}
|
||||||
$result[$j] = $row[1];
|
}
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
$this->db->free($resql);
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($i = 1 ; $i < 13 ; $i++)
|
// return array(array('Month',val1,val2,val3),...)
|
||||||
{
|
return $data;
|
||||||
$res[$i] = $result[$i] + 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$data = array();
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
for ($i = 1 ; $i < 13 ; $i++)
|
$year=$startyear;
|
||||||
{
|
while($year <= $endyear)
|
||||||
$data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,0,0,$i,1,$year)),0,3)), $res[$i]);
|
{
|
||||||
}
|
$datay[$year] = $this->getAmountByMonth($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 $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Renvoie le nombre d'element par ann<EFBFBD>e
|
* \brief Renvoie le nombre d'element par ann<EFBFBD>e
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function _getNbByYear($sql)
|
function _getNbByYear($sql)
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
$resql=$this->db->query($sql);
|
||||||
{
|
if ($resql)
|
||||||
$num = $this->db->num_rows();
|
{
|
||||||
$i = 0;
|
$num = $this->db->num_rows($resql);
|
||||||
while ($i < $num)
|
$i = 0;
|
||||||
{
|
while ($i < $num)
|
||||||
$row = $this->db->fetch_row($i);
|
{
|
||||||
$result[$i] = $row;
|
$row = $this->db->fetch_row($resql);
|
||||||
$i++;
|
$result[$i] = $row;
|
||||||
}
|
$i++;
|
||||||
$this->db->free();
|
}
|
||||||
}
|
$this->db->free($resql);
|
||||||
else {
|
}
|
||||||
dolibarr_print_error($this->db);
|
else {
|
||||||
}
|
dolibarr_print_error($this->db);
|
||||||
return $result;
|
}
|
||||||
}
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Renvoie le nombre d'element par mois pour une ann<EFBFBD>e donn<EFBFBD>e
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
function _getAmountByMonth($year, $sql)
|
/**
|
||||||
{
|
* \brief Renvoie le nombre de proposition par mois pour une annee donnee
|
||||||
$result = array();
|
*
|
||||||
|
*/
|
||||||
|
function _getNbByMonth($year, $sql)
|
||||||
|
{
|
||||||
|
$result = array();
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
$resql=$this->db->query($sql);
|
||||||
{
|
dolibarr_syslog("Stats::_getNbByMonth sql=".$sql);
|
||||||
$num = $this->db->num_rows();
|
if ($resql)
|
||||||
$i = 0;
|
{
|
||||||
while ($i < $num)
|
$num = $this->db->num_rows($resql);
|
||||||
{
|
$i = 0; $j = 0;
|
||||||
$row = $this->db->fetch_row($i);
|
while ($i < $num)
|
||||||
$j = $row[0] * 1;
|
{
|
||||||
$result[$j] = $row[1];
|
$row = $this->db->fetch_row($resql);
|
||||||
$i++;
|
$j = $row[0] * 1;
|
||||||
}
|
$result[$j] = $row[1];
|
||||||
$this->db->free();
|
$i++;
|
||||||
}
|
}
|
||||||
|
$this->db->free($resql);
|
||||||
|
}
|
||||||
|
|
||||||
for ($i = 1 ; $i < 13 ; $i++)
|
for ($i = 1 ; $i < 13 ; $i++)
|
||||||
{
|
{
|
||||||
$res[$i] = $result[$i] + 0;
|
$res[$i] = $result[$i] + 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
$data = array();
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function _getAverageByMonth($year, $sql)
|
|
||||||
{
|
|
||||||
$result = array();
|
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
for ($i = 1 ; $i < 13 ; $i++)
|
||||||
{
|
{
|
||||||
$num = $this->db->num_rows();
|
$data[$i-1] = array(ucfirst(substr(strftime("%b",dolibarr_mktime(12,0,0,$i,1,$year)),0,3)), $res[$i]);
|
||||||
$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++)
|
return $data;
|
||||||
{
|
}
|
||||||
$res[$i] = $result[$i] + 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
/**
|
||||||
|
* \brief Renvoie le nombre d'element par mois pour une annee donnee
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = 1 ; $i < 13 ; $i++)
|
||||||
|
{
|
||||||
|
$res[$i] = (int) round($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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user