diff --git a/htdocs/compta/facture/stats/facturestats.class.php b/htdocs/compta/facture/stats/facturestats.class.php
index 77cc5aea4e6..9360e74d1dd 100644
--- a/htdocs/compta/facture/stats/facturestats.class.php
+++ b/htdocs/compta/facture/stats/facturestats.class.php
@@ -24,6 +24,8 @@
* \version $Id$
*/
include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
+include_once DOL_DOCUMENT_ROOT . "/facture.class.php";
+include_once DOL_DOCUMENT_ROOT . "/fourn/fournisseur.facture.class.php";
/**
* \class FactureStats
@@ -32,11 +34,37 @@ include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
class FactureStats extends Stats
{
var $db ;
-
- function FactureStats($DB, $socid=0)
+
+ var $socid;
+ var $where;
+
+ var $table_element;
+ var $field;
+
+ function FactureStats($DB, $socid=0, $mode)
{
$this->db = $DB;
+ if ($mode == 'customer')
+ {
+ $object=new Facture($this->db);
+ $this->table_element=$object->table_element;
+ $this->field='total';
+ }
+ if ($mode == 'supplier')
+ {
+ $object=new FactureFournisseur($this->db);
+ $this->table_element=$object->table_element;
+ $this->field='total_ht';
+ }
+
$this->socid = $socid;
+ $this->where =" fk_statut > 0";
+ if ($mode == 'customer') $this->where.=" AND (fk_statut != 3 OR close_code != 'replaced')"; // Exclude replaced invoices
+ if ($this->socid)
+ {
+ $this->where.=" AND fk_soc = ".$this->socid;
+ }
+
}
@@ -46,8 +74,10 @@ class FactureStats extends Stats
*/
function getNbByYear()
{
- $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,'%Y') as dm, count(*)";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." GROUP BY dm DESC";
+ $sql.= " WHERE ".$this->where;
+
return $this->_getNbByYear($sql);
}
@@ -59,13 +89,11 @@ class FactureStats extends Stats
*/
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";
+ $sql = "SELECT date_format(datef,'%m') as dm, count(*)";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
+ $sql.= " WHERE date_format(datef,'%Y') = ".$year;
+ $sql.= " AND ".$this->where;
+ $sql.= " GROUP BY dm DESC";
$res=$this->_getNbByMonth($year, $sql);
//var_dump($res);print '
';
@@ -80,13 +108,11 @@ class FactureStats extends Stats
*/
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";
+ $sql = "SELECT date_format(datef,'%m') as dm, sum(".$this->field.")";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
+ $sql.= " WHERE date_format(datef,'%Y') = ".$year;
+ $sql.= " AND ".$this->where;
+ $sql.= " GROUP BY dm DESC";
$res=$this->_getAmountByMonth($year, $sql);
//var_dump($res);print '
';
@@ -100,16 +126,28 @@ class FactureStats extends Stats
*/
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";
+ $sql = "SELECT date_format(datef,'%m') as dm, avg(".$this->field.")";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
+ $sql.= " WHERE date_format(datef,'%Y') = ".$year;
+ $sql.= " AND ".$this->where;
+ $sql.= " GROUP BY dm DESC";
return $this->_getAverageByMonth($year, $sql);
}
+
+ /**
+ * \brief Return nb, total and average
+ * \return array Array of values
+ */
+ function getAllByYear()
+ {
+ $sql = "SELECT date_format(datef,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
+ $sql.= " WHERE ".$this->where;
+ $sql.= " GROUP BY year DESC";
+
+ return $this->_getAllByYear($sql);
+ }
}
?>
diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php
index 96c57ef06af..37cb32e6aa9 100644
--- a/htdocs/compta/facture/stats/index.php
+++ b/htdocs/compta/facture/stats/index.php
@@ -37,6 +37,13 @@ if ($user->societe_id > 0)
$socid = $user->societe_id;
}
+$year = strftime("%Y", time());
+$startyear=$year-2;
+$endyear=$year;
+
+$mode='customer';
+if (isset($_GET["mode"])) $mode=$_GET["mode"];
+
/*
* View
@@ -44,15 +51,22 @@ if ($user->societe_id > 0)
llxHeader();
-print_fiche_titre($langs->trans("BillsStatistics"), $mesg);
+if ($mode == 'customer')
+{
+ $title=$langs->trans("BillsStatistics");
+ $dir=$conf->facture->dir_temp;
+}
+if ($mode == 'supplier')
+{
+ $title=$langs->trans("BillsStatisticsSuppliers");
+ $dir=$conf->fournisseur->facture->dir_temp;
+}
-create_exdir($conf->facture->dir_temp);
+print_fiche_titre($title, $mesg);
-$year = strftime("%Y", time());
-$startyear=$year-2;
-$endyear=$year;
+create_exdir($dir);
-$stats = new FactureStats($db, $socid);
+$stats = new FactureStats($db, $socid, $mode);
// Build graphic number of invoices
@@ -60,8 +74,9 @@ $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
//var_dump($data);
// $data = array(array('Lib',val1,val2,val3),...)
-$filenamenbinvoices = $conf->facture->dir_temp."/invoicesnbinyear-".$year.".png";
-$fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png';
+$filenamenbinvoices = $dir."/invoicesnbinyear-".$year.".png";
+if ($mode == 'customer') $fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png';
+if ($mode == 'supplier') $fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.'.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
@@ -94,8 +109,9 @@ $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';
+$filenameamountinvoices = $dir."/invoicesamountinyear-".$year.".png";
+if ($mode == 'customer') $fileurlamountinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.'.png';
+if ($mode == 'supplier') $fileurlamountinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.'.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
@@ -125,52 +141,66 @@ if (! $mesg)
}
+
+print '
';
+print '';
+
// 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.= " GROUP BY dm DESC;";
-$resql=$db->query($sql);
-if ($resql)
-{
- $num = $db->num_rows($resql);
+$data = $stats->getAllByYear();
- print '';
- print '| '.$langs->trans("Year").' | '.$langs->trans("NumberOfBills").' | '.$langs->trans("AmountTotal").' | ';
- print '';
- if ($mesg) { print $mesg; }
- else {
- print ' ';
- print " \n";
- print ' ';
- }
- print ' | ';
+print '';
+print '';
+print '| '.$langs->trans("Year").' | ';
+print ''.$langs->trans("NumberOfBills").' | ';
+print ''.$langs->trans("AmountTotal").' | ';
+print ''.$langs->trans("AmountAverage").' | ';
+print ' ';
- while ($obj = $db->fetch_object($resql))
- {
- $nbproduct = $obj->nb;
- $year = $obj->dm;
- $total = price($obj->total);
+$oldyear=0;
+foreach ($data as $val)
+{
+ $year = $val['year'];
+ $nbproduct = $val['nb'];
+ $total = price($val['total']);
+ $avg = price($val['avg']);
+ while ($oldyear > $year+1)
+ { // If we have empty year
+ $oldyear--;
print '';
- print '| '.$year.' | ';
- print ''.$nbproduct.' | ';
- print ''.$total.' | ';
-
+ print ''.$oldyear.' | ';
+ print '0 | ';
+ print '0 | ';
+ print '0 | ';
+ print '';
}
-
- print ' | ';
-
- print ' ';
- $db->free($resql);
-}
-else
-{
- dolibarr_print_error($db);
+ print '';
+ print '| '.$year.' | ';
+ print ''.$nbproduct.' | ';
+ print ''.$total.' | ';
+ print ''.$avg.' | ';
+ print ' ';
+ $oldyear=$year;
}
+
+print ' ';
+
$db->close();
+print ' | ';
+print '';
+
+// Show graphs
+print '';
+if ($mesg) { print $mesg; }
+else {
+ print ' ';
+ print " \n";
+ print ' ';
+}
+print ' | ';
+
+print ' |
';
+
llxFooter('$Date$ - $Revision$');
?>
diff --git a/htdocs/compta/facture/stats/month.php b/htdocs/compta/facture/stats/month.php
index e4ecaa4b847..07256ab7969 100644
--- a/htdocs/compta/facture/stats/month.php
+++ b/htdocs/compta/facture/stats/month.php
@@ -30,13 +30,19 @@ require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
$GRAPHWIDTH=500;
$GRAPHHEIGHT=200;
-// Sécurité accés client
+// Check security access
if ($user->societe_id > 0)
{
$action = '';
$socid = $user->societe_id;
}
+$year = isset($_GET["year"])?$_GET["year"]:date("Y",time());
+
+$mode='customer';
+if (isset($_GET["mode"])) $mode=$_GET["mode"];
+
+
/*
* View
@@ -44,22 +50,32 @@ if ($user->societe_id > 0)
llxHeader();
-$year = isset($_GET["year"])?$_GET["year"]:date("Y",time());
+if ($mode == 'customer')
+{
+ $title=$langs->trans("BillsStatistics");
+ $dir=$conf->facture->dir_temp;
+}
+if ($mode == 'supplier')
+{
+ $title=$langs->trans("BillsStatisticsSuppliers");
+ $dir=$conf->fournisseur->facture->dir_temp;
+}
-$mesg = ''.img_previous().' ';
+$mesg = ''.img_previous().' ';
$mesg.= $langs->trans("Year")." $year";
-$mesg.= ' '.img_next().'';
+$mesg.= ' '.img_next().'';
+print_fiche_titre($title, $mesg);
-print_fiche_titre($langs->trans("BillsStatistics"), $mesg);
+create_exdir($dir);
-$stats = new FactureStats($db, $socid);
-create_exdir($conf->facture->dir_temp);
+$stats = new FactureStats($db, $socid, $mode);
$data = $stats->getNbByMonth($year);
-$filename = $conf->facture->dir_temp."/facture".$year.".png";
-$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=facture'.$year.'.png';
+$filename = $dir."/invoices-".$year.".png";
+if ($mode == 'customer') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoices-'.$year.'.png';
+if ($mode == 'supplier') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoices-'.$year.'.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
@@ -81,8 +97,9 @@ if (! $mesg)
$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';
+$filename_amount = $dir."/invoicesamount-".$year.".png";
+if ($mode == 'customer') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamount-'.$year.'.png';
+if ($mode == 'supplier') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesamount-'.$year.'.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
@@ -112,8 +129,9 @@ 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]);
}
-$filename_avg = $conf->facture->dir_temp."/factureaverage".$year.".png";
-$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=factureaverage'.$year.'.png';
+$filename_avg = $dir."/invoicesaverage-".$year.".png";
+if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesaverage-'.$year.'.png';
+if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesaverage-'.$year.'.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
diff --git a/htdocs/includes/menus/barre_left/eldy_backoffice.php b/htdocs/includes/menus/barre_left/eldy_backoffice.php
index 66299aaa53b..e1a28076d2a 100644
--- a/htdocs/includes/menus/barre_left/eldy_backoffice.php
+++ b/htdocs/includes/menus/barre_left/eldy_backoffice.php
@@ -395,6 +395,8 @@ class MenuLeft {
}
if ($leftmenu=="suppliers_bills") $newmenu->add_submenu(DOL_URL_ROOT."/fourn/facture/impayees.php", $langs->trans("Unpayed"),2,$user->rights->fournisseur->facture->lire);
if ($leftmenu=="suppliers_bills") $newmenu->add_submenu(DOL_URL_ROOT."/fourn/facture/paiement.php", $langs->trans("Payments"),2,$user->rights->fournisseur->facture->lire);
+
+ if ($leftmenu=="suppliers_bills") $newmenu->add_submenu(DOL_URL_ROOT."/compta/facture/stats/index.php?leftmenu=suppliers_bills&mode=supplier", $langs->trans("Statistics"),2,$user->rights->fournisseur->facture->lire);
}
}
diff --git a/htdocs/includes/menus/barre_left/eldy_frontoffice.php b/htdocs/includes/menus/barre_left/eldy_frontoffice.php
index 6d1bad276c9..df0aedc223d 100644
--- a/htdocs/includes/menus/barre_left/eldy_frontoffice.php
+++ b/htdocs/includes/menus/barre_left/eldy_frontoffice.php
@@ -377,6 +377,8 @@ class MenuLeft {
}
if ($leftmenu=="suppliers_bills") $newmenu->add_submenu(DOL_URL_ROOT."/fourn/facture/impayees.php", $langs->trans("Unpayed"),2,$user->rights->fournisseur->facture->lire);
if ($leftmenu=="suppliers_bills") $newmenu->add_submenu(DOL_URL_ROOT."/fourn/facture/paiement.php", $langs->trans("Payments"),2,$user->rights->fournisseur->facture->lire);
+
+ if ($leftmenu=="suppliers_bills") $newmenu->add_submenu(DOL_URL_ROOT."/compta/facture/stats/index.php?leftmenu=suppliers_bills&mode=supplier", $langs->trans("Statistics"),2,$user->rights->fournisseur->facture->lire);
}
}
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index 678b4df78d2..98af534c561 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -7,7 +7,8 @@ BillsCustomersUnpayed=Unpayed customers' invoices
BillsCustomersUnpayedForCompany=Unpayed customers' invoices for %s
BillsSuppliersUnpayed=Unpayed suppliers' invoices
BillsUnpayed=Unpayed
-BillsStatistics=Invoices statistics
+BillsStatistics=Customers' invoices statistics
+BillsStatisticsSuppliers=Suppliers' invoices statistics
InvoiceStandard=Standard invoice
InvoiceStandardAsk=Standard invoice
InvoiceStandardDesc=This kind of invoice is the common invoice.
diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang
index 8887bd7400a..e728c6e3f6f 100644
--- a/htdocs/langs/fr_FR/bills.lang
+++ b/htdocs/langs/fr_FR/bills.lang
@@ -8,7 +8,8 @@ BillsCustomersUnpayedForCompany=Factures clients impay
BillsSuppliersUnpayed=Factures fournisseurs impayées
BillsUnpayed=Impayées
BillsLate=Retards de paiement
-BillsStatistics=Statistiques factures
+BillsStatistics=Statistiques factures clients
+BillsStatisticsSuppliers=Statistiques factures fournisseurs
InvoiceStandard=Facture standard
InvoiceStandardAsk=Facture standard
InvoiceStandardDesc=Ce type de facture est la facture traditionnelle. On l'appelle aussi facture de doit (du verbe devoir).
diff --git a/htdocs/stats.class.php b/htdocs/stats.class.php
index fb8ea15fdbe..2baa45cd6e3 100644
--- a/htdocs/stats.class.php
+++ b/htdocs/stats.class.php
@@ -103,8 +103,9 @@ class Stats
/**
- * \brief Renvoie le nombre d'element par ann�e
- *
+ * \brief Return nb of elements by year
+ * \param sql SQL request
+ * \return array
*/
function _getNbByYear($sql)
{
@@ -129,6 +130,36 @@ class Stats
return $result;
}
+ /**
+ * \brief Return nb of elements, total amount and avg amount by year
+ * \param sql SQL request
+ * \return array
+ */
+ function _getAllByYear($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_object($resql);
+ $result[$i]['year'] = $row->year;
+ $result[$i]['nb'] = $row->nb;
+ $result[$i]['total'] = $row->total;
+ $result[$i]['avg'] = $row->avg;
+ $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
@@ -203,7 +234,7 @@ class Stats
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]);
+ $data[$i-1] = array(ucfirst(substr(strftime("%b",dolibarr_mktime(12,0,0,$i,1,$year)),0,3)), $res[$i]);
}
return $data;
diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php
index 5f60c3216f7..7f8206c8fc0 100644
--- a/htdocs/viewimage.php
+++ b/htdocs/viewimage.php
@@ -167,7 +167,16 @@ if ($modulepart)
}
$original_file=$conf->facture->dir_temp.'/'.$original_file;
}
-
+ elseif ($modulepart == 'billstatssupplier')
+ {
+ $user->getrights('fourn');
+ if ($user->rights->fournisseur->facture->lire)
+ {
+ $accessallowed=1;
+ }
+ $original_file=$conf->fournisseur->facture->dir_temp.'/'.$original_file;
+ }
+
// Wrapping pour les images des stats expeditions
elseif ($modulepart == 'expeditionstats')
{