diff --git a/htdocs/comm/propal/stats/propalestats.class.php b/htdocs/comm/propal/stats/propalestats.class.php
index 717e8d5c3a6..0ab2f60ce31 100644
--- a/htdocs/comm/propal/stats/propalestats.class.php
+++ b/htdocs/comm/propal/stats/propalestats.class.php
@@ -80,14 +80,10 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(p.datep,'%m') as dm, count(*)";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
+ $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if($user->societe_id)
- {
- $sql .= " AND p.fk_soc = ".$user->societe_id;
- }
+ $sql .= " WHERE date_format(p.datep,'%Y') = ".$year;
+ $sql.= " AND ".$this->where;
$sql .= " GROUP BY dm DESC";
return $this->_getNbByMonth($year, $sql);
@@ -103,15 +99,10 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(p.datep,'%Y') as dm, count(*)";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE p.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if($user->societe_id)
- {
- $sql .= " AND p.fk_soc = ".$user->societe_id;
- }
- $sql .= " GROUP BY dm DESC";
+ $sql.= " WHERE ".$this->where;
+ $sql.= " GROUP BY dm DESC";
return $this->_getNbByYear($sql);
}
@@ -125,15 +116,11 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.total_ht)";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if($user->societe_id)
- {
- $sql .= " AND p.fk_soc = ".$user->societe_id;
- }
- $sql .= " GROUP BY dm DESC";
+ $sql.= " WHERE date_format(p.datep,'%Y') = ".$year;
+ $sql.= " AND ".$this->where;
+ $sql.= " GROUP BY dm DESC";
return $this->_getAmountByMonth($year, $sql);
}
@@ -146,16 +133,12 @@ class PropaleStats extends Stats
global $user;
$sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.total_ht)";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if($user->societe_id)
- {
- $sql .= " AND p.fk_soc = ".$user->societe_id;
- }
- $sql .= " GROUP BY dm DESC";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", sc.fk_soc, sc.fk_user";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql.= " WHERE date_format(p.datep,'%Y') = ".$year;
+ $sql.= " AND ".$this->where;
+ $sql.= " GROUP BY dm DESC";
return $this->_getAverageByMonth($year, $sql);
}
@@ -170,9 +153,9 @@ class PropaleStats extends Stats
global $user;
$sql = "SELECT date_format(p.datep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
- $sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", sc.fk_soc, sc.fk_user";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE ".$this->where;
$sql.= " GROUP BY year DESC";
diff --git a/htdocs/commande/stats/commandestats.class.php b/htdocs/commande/stats/commandestats.class.php
index 590c2afa96c..89cf59f56e9 100644
--- a/htdocs/commande/stats/commandestats.class.php
+++ b/htdocs/commande/stats/commandestats.class.php
@@ -15,128 +15,153 @@
* 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$
- * $Source$
*/
/**
- \file htdocs/commande/stats/commandestats.class.php
- \ingroup commandes
- \brief Fichier de la classe de gestion des stats des commandes
- \version $Revision$
-*/
-
+ * \file htdocs/commande/stats/commandestats.class.php
+ * \ingroup commandes
+ * \brief Fichier de la classe de gestion des stats des commandes
+ * \version $Id$
+ */
include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
+include_once DOL_DOCUMENT_ROOT . "/commande/commande.class.php";
/**
- \class CommandeStats
- \brief Classe permettant la gestion des stats des commandes
-*/
-
+ * \class CommandeStats
+ * \brief Classe permettant la gestion des stats des commandes
+ */
class CommandeStats extends Stats
{
- var $db ;
+ var $db ;
- function CommandeStats($DB, $socid)
- {
- $this->db = $DB;
- $this->socid = $socid;
- }
+ var $socid;
+ var $where;
- /**
- * \brief Renvoie le nombre de commande par mois pour une année donnée
- *
- */
- function getNbByMonth($year)
- {
- global $conf;
- global $user;
-
- $sql = "SELECT date_format(c.date_commande,'%m') as dm, count(*) nb";
- $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE date_format(c.date_commande,'%Y') = $year AND c.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if ($this->socid)
- {
- $sql .= " AND c.fk_soc = ".$this->socid;
- }
- $sql .= " GROUP BY dm";
- $sql .= " ORDER BY dm DESC";
+ var $table_element;
+ var $field;
- return $this->_getNbByMonth($year, $sql);
- }
+
+ /**
+ * Constructor
+ *
+ * @param $DB Database handler
+ * @param $socid Id third party
+ * @return PropaleStats
+ */
+ function CommandeStats($DB, $socid=0)
+ {
+ global $user;
+
+ $this->db = $DB;
+
+ $object=new Commande($this->db);
+ $this->table_element=$object->table_element;
+ $this->field='total_ht';
+
+ $this->socid = $socid;
+ $this->where.= " c.fk_statut > 0";
+ if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
+ if($this->socid)
+ {
+ $this->where .= " AND c.fk_soc = ".$this->socid;
+ }
+
+ }
- /**
- * Renvoie le nombre de commande par année
- *
- */
- function getNbByYear()
- {
- global $conf;
- global $user;
-
- $sql = "SELECT date_format(c.date_commande,'%Y') as dm, count(*), sum(c.total_ht)";
- $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE c.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if ($this->socid)
- {
- $sql .= " AND c.fk_soc = ".$this->socid;
- }
- $sql .= " GROUP BY dm DESC";
+ /**
+ * \brief Renvoie le nombre de commande par mois pour une année donnée
+ *
+ */
+ function getNbByMonth($year)
+ {
+ global $conf;
+ global $user;
+
+ $sql = "SELECT date_format(c.date_commande,'%m') as dm, count(*) nb";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql.= " WHERE date_format(c.date_commande,'%Y') = ".$year;
+ $sql.= " AND ".$this->where;
+ $sql.= " GROUP BY dm DESC";
- return $this->_getNbByYear($sql);
- }
-
- /**
- * Renvoie le nombre de commande par mois pour une année donnée
- *
- */
- function getAmountByMonth($year)
- {
- global $conf;
- global $user;
-
- $sql = "SELECT date_format(c.date_commande,'%m') as dm, sum(c.total_ht)";
- $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE date_format(c.date_commande,'%Y') = $year AND c.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if ($this->socid)
- {
- $sql .= " AND c.fk_soc = ".$this->socid;
- }
- $sql .= " GROUP BY dm DESC";
+ return $this->_getNbByMonth($year, $sql);
+ }
- return $this->_getAmountByMonth($year, $sql);
- }
-
- /**
- * Renvoie le nombre de commande par mois pour une année donnée
- *
- */
- function getAverageByMonth($year)
- {
- global $conf;
- global $user;
-
- $sql = "SELECT date_format(c.date_commande,'%m') as dm, avg(c.total_ht)";
- $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE date_format(c.date_commande,'%Y') = $year AND c.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$this->socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if ($this->socid)
- {
- $sql .= " AND c.fk_soc = ".$this->socid;
- }
- $sql .= " GROUP BY dm DESC";
+ /**
+ * Renvoie le nombre de commande par année
+ *
+ */
+ function getNbByYear()
+ {
+ global $conf;
+ global $user;
+
+ $sql = "SELECT date_format(c.date_commande,'%Y') as dm, count(*), sum(c.".$this->field.")";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql.= " WHERE ".$this->where;
+ $sql.= " GROUP BY dm DESC";
- return $this->_getAverageByMonth($year, $sql);
- }
+ return $this->_getNbByYear($sql);
+ }
+
+ /**
+ * Renvoie le nombre de commande par mois pour une année donnée
+ *
+ */
+ function getAmountByMonth($year)
+ {
+ global $conf;
+ global $user;
+
+ $sql = "SELECT date_format(c.date_commande,'%m') as dm, sum(c.".$this->field.")";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql.= " WHERE date_format(c.date_commande,'%Y') = ".$year;
+ $sql.= " AND ".$this->where;
+ $sql.= " GROUP BY dm DESC";
+
+ return $this->_getAmountByMonth($year, $sql);
+ }
+
+ /**
+ * Renvoie le nombre de commande par mois pour une année donnée
+ *
+ */
+ function getAverageByMonth($year)
+ {
+ global $conf;
+ global $user;
+
+ $sql = "SELECT date_format(c.date_commande,'%m') as dm, avg(c.".$this->field.")";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql.= " WHERE date_format(c.date_commande,'%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()
+ {
+ global $user;
+
+ $sql = "SELECT date_format(c.date_commande,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", sc.fk_soc, sc.fk_user";
+ $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
+ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql.= " WHERE ".$this->where;
+ $sql.= " GROUP BY year DESC";
+
+ return $this->_getAllByYear($sql);
+ }
}
?>
diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php
index 3693f66f199..b95f70023ab 100644
--- a/htdocs/commande/stats/index.php
+++ b/htdocs/commande/stats/index.php
@@ -41,36 +41,39 @@ if ($user->societe_id > 0)
$socid = $user->societe_id;
}
+$year = strftime("%Y", time());
+$startyear=$year-2;
+$endyear=$year;
+/*
+ * View
+ */
+
llxHeader();
print_fiche_titre($langs->trans("OrdersStatistics"), $mesg);
-$stats = new CommandeStats($db, $socid);
-$year = strftime("%Y", time());
-$startyear=$year-2;
-$endyear=$year;
-$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
-
-// Création répertoire pour images générées
$dir=$conf->commande->dir_temp;
-if (! file_exists($dir))
-{
- if (create_exdir($dir) < 0)
- {
- $mesg = $langs->trans("ErrorCanNotCreateDir",$dir);
- }
-}
+
+create_exdir($dir);
+
+$stats = new CommandeStats($db, $socid);
+
+// Build graphic number of object
+$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
+//var_dump($data);
+// $data = array(array('Lib',val1,val2,val3),...)
+
if (!$user->rights->societe->client->voir || $user->societe_id)
{
- $filename = $conf->commande->dir_temp.'/nbcommande2year-'.$user->id.'-'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=nbcommande2year-'.$user->id.'-'.$year.'.png';
+ $filenamenb = $dir.'/ordersnbinyear-'.$user->id.'-'.$year.'.png';
+ $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
}
else
{
- $filename = $conf->commande->dir_temp.'/nbcommande2year-'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=nbcommande2year-'.$year.'.png';
+ $filenamenb = $dir.'/ordersnbinyear-'.$year.'.png';
+ $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png';
}
$px = new DolGraph();
@@ -87,6 +90,7 @@ if (! $mesg)
}
$px->SetLegend($legend);
$px->SetMaxValue($px->GetCeilMaxValue());
+ $px->SetMinValue(min(0,$px->GetFloorMinValue()));
$px->SetWidth($WIDTH);
$px->SetHeight($HEIGHT);
$px->SetYLabel($langs->trans("NbOfOrder"));
@@ -94,31 +98,109 @@ if (! $mesg)
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->mode='depth';
- $px->draw($filename);
+ $px->SetTitle($langs->trans("NumberOfOrdersByMonth"));
+ $px->draw($filenamenb);
}
-$rows = $stats->getNbByYear();
-$num = sizeof($rows);
+
+// Build graphic amount of object
+$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
+//var_dump($data);
+// $data = array(array('Lib',val1,val2,val3),...)
+
+if (!$user->rights->societe->client->voir || $user->societe_id)
+{
+ $filenameamount = $dir.'/ordersamountinyear-'.$user->id.'-'.$year.'.png';
+ $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
+}
+else
+{
+ $filenameamount = $dir.'/ordersamountinyear-'.$year.'.png';
+ $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$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("AmountOfOrders"));
+ $px->SetShading(3);
+ $px->SetHorizTickIncrement(1);
+ $px->SetPrecisionY(0);
+ $px->mode='depth';
+ $px->SetTitle($langs->trans("AmountOfOrdersByMonthHT"));
+
+ $px->draw($filenameamount);
+}
+
+print '
';
+print '';
+
+// Show array
+$data = $stats->getAllByYear();
print '';
-print '| '.$langs->trans("Year").' | '.$langs->trans("NbOfOrders").' | '.$langs->trans("AmountTotal").' | ';
-print '';
-if ($px->isGraphKo()) { print ''.$px->isGraphKo().''; }
-else { print ' '; }
-print ' | ';
-$i = 0;
-while (list($key, $value) = each ($rows))
+print '';
+print '| '.$langs->trans("Year").' | ';
+print ''.$langs->trans("NbOfOrders").' | ';
+print ''.$langs->trans("AmountTotal").' | ';
+print ''.$langs->trans("AmountAverage").' | ';
+print ' ';
+
+$oldyear=0;
+foreach ($data as $val)
{
- $year = $value[0];
- $nbproduct = $value[1];
- $price = $value[2];
- print "";
- print '| '.$year.' | '.$nbproduct.' | '.price($price).' | ';
- $i++;
+ $year = $val['year'];
+ print $avg;
+ while ($oldyear > $year+1)
+ { // If we have empty year
+ $oldyear--;
+ print '';
+ print '| '.$oldyear.' | ';
+ print '0 | ';
+ print '0 | ';
+ print '0 | ';
+ print ' ';
+ }
+ print '';
+ print '| '.$year.' | ';
+ print ''.$val['nb'].' | ';
+ print ''.price(price2num($val['total'],'MT'),1).' | ';
+ print ''.price(price2num($val['avg'],'MT'),1).' | ';
+ print ' ';
+ $oldyear=$year;
}
print ' ';
+print ' | ';
+print '';
+
+// Show graphs
+print '';
+if ($mesg) { print $mesg; }
+else {
+ print ' ';
+ print " \n";
+ print ' ';
+}
+print ' | ';
+
+print ' |
';
+
$db->close();
llxFooter('$Date$ - $Revision$');
diff --git a/htdocs/commande/stats/month.php b/htdocs/commande/stats/month.php
index 1d47197b393..b120c0f1893 100644
--- a/htdocs/commande/stats/month.php
+++ b/htdocs/commande/stats/month.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,57 +18,71 @@
*/
/**
- \file htdocs/commande/stats/month.php
- \ingroup commande
- \brief Page des stats commandes par mois
- \version $Id$
-*/
-
+ * \file htdocs/commande/stats/month.php
+ * \ingroup commande
+ * \brief Page des stats commandes par mois
+ * \version $Id$
+ */
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
require_once(DOL_DOCUMENT_ROOT."/commande/stats/commandestats.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
-// Sécurité accés client
+$GRAPHWIDTH=500;
+$GRAPHHEIGHT=200;
+
+// Check security access
if ($user->societe_id > 0)
{
$action = '';
$socid = $user->societe_id;
}
-llxHeader();
-
$year = isset($_GET["year"])?$_GET["year"]:date("Y",time());
-$mesg = ''.img_previous().' ';
-$mesg.= $langs->trans("Year")." $year";
-$mesg.= ' '.img_next().'';
+$mode='customer';
+if (isset($_GET["mode"])) $mode=$_GET["mode"];
+
-$WIDTH=500;
-$HEIGHT=200;
/*
- *
- *
+ * View
*/
-print_fiche_titre($langs->trans("OrdersStatistics"), $mesg);
+llxHeader();
+
+if ($mode == 'customer')
+{
+ $title=$langs->trans("OrdersStatistics");
+ $dir=$conf->commande->dir_temp;
+}
+if ($mode == 'supplier')
+{
+ $title=$langs->trans("OrdersStatisticsSuppliers");
+ $dir=$conf->fournisseur->commande->dir_temp;
+}
+
+$mesg = ''.img_previous().' ';
+$mesg.= $langs->trans("Year")." $year";
+$mesg.= ' '.img_next().'';
+print_fiche_titre($title, $mesg);
+
+create_exdir($dir);
+
+$stats = new CommandeStats($db, $socid, $mode);
+
-$stats = new CommandeStats($db, $socid);
$data = $stats->getNbByMonth($year);
-create_exdir($conf->commande->dir_temp);
-
-
if (!$user->rights->societe->client->voir || $user->societe_id)
{
- $filename = $conf->commande->dir_temp.'/commande-'.$user->id.'-'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commande-'.$user->id.'-'.$year.'.png';
+ $filename = $dir.'/ordersnb-'.$user->id.'-'.$year.'.png';
+ $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$user->id.'-'.$year.'.png';
}
else
{
- $filename = $conf->commande->dir_temp.'/commande'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commande'.$year.'.png';
+ $filename = $dir.'/ordersnb-'.$year.'.png';
+ $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$year.'.png';
}
$px = new DolGraph();
@@ -77,8 +91,9 @@ if (! $mesg)
{
$px->SetData($data);
$px->SetMaxValue($px->GetCeilMaxValue());
- $px->SetWidth($WIDTH);
- $px->SetHeight($HEIGHT);
+ $px->SetMinValue($px->GetFloorMinValue());
+ $px->SetWidth($GRAPHWIDTH);
+ $px->SetHeight($GRAPHHEIGHT);
$px->SetYLabel($langs->trans("NbOfOrders"));
$px->SetShading(3);
$px->SetHorizTickIncrement(1);
@@ -86,24 +101,18 @@ 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);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
- $filename_amount = $conf->commande->dir_temp.'/commandeamount-'.$user->id.'-'.$year.'.png';
- $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeamount-'.$user->id.'-'.$year.'.png';
+ $filename_amount = $dir.'/ordersamount-'.$user->id.'-'.$year.'.png';
+ $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$user->id.'-'.$year.'.png';
}
else
{
- $filename_amount = $conf->commande->dir_temp.'/commandeamount'.$year.'.png';
- $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeamount'.$year.'.png';
+ $filename_amount = $dir.'/ordersamount-'.$year.'.png';
+ $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$year.'.png';
}
$px = new DolGraph();
@@ -111,11 +120,12 @@ $mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
- $px->SetMaxValue($px->GetCeilMaxValue());
- $px->SetWidth($WIDTH);
- $px->SetHeight($HEIGHT);
$px->SetYLabel($langs->trans("AmountTotal"));
- $px->SetShading(5);
+ $px->SetMaxValue($px->GetCeilMaxValue());
+ $px->SetMinValue($px->GetFloorMinValue());
+ $px->SetWidth($GRAPHWIDTH);
+ $px->SetHeight($GRAPHHEIGHT);
+ $px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->draw($filename_amount);
@@ -131,13 +141,13 @@ for ($i = 1 ; $i < 13 ; $i++)
if (!$user->rights->societe->client->voir || $user->societe_id)
{
- $filename_avg = $conf->commande->dir_temp.'/commandeaverage-'.$user->id.'-'.$year.'.png';
- $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeaverage-'.$user->id.'-'.$year.'.png';
+ $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
+ $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
}
else
{
- $filename_avg = $conf->commande->dir_temp.'/commandeaverage'.$year.'.png';
- $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeaverage'.$year.'.png';
+ $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
+ $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
}
$px = new DolGraph();
@@ -145,11 +155,12 @@ $mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
- $px->SetMaxValue($px->GetCeilMaxValue());
- $px->SetWidth($WIDTH);
- $px->SetHeight($HEIGHT);
$px->SetYLabel($langs->trans("AmountAverage"));
- $px->SetShading(5);
+ $px->SetMaxValue($px->GetCeilMaxValue());
+ $px->SetMinValue($px->GetFloorMinValue());
+ $px->SetWidth($GRAPHWIDTH);
+ $px->SetHeight($GRAPHHEIGHT);
+ $px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->draw($filename_avg);
diff --git a/htdocs/compta/facture/stats/month.php b/htdocs/compta/facture/stats/month.php
index dae0963bde0..e0874eae705 100644
--- a/htdocs/compta/facture/stats/month.php
+++ b/htdocs/compta/facture/stats/month.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
@@ -136,7 +136,6 @@ $mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
- $px->SetPrecisionY(0);
$px->SetYLabel($langs->trans("AmountAverage"));
$px->SetMaxValue($px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue());
diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang
index 6f9122cf046..2c2883d3a45 100755
--- a/htdocs/langs/en_US/orders.lang
+++ b/htdocs/langs/en_US/orders.lang
@@ -69,6 +69,7 @@ AllOrders=All orders
NbOfOrders=Number of orders
OrdersStatistics=Orders' statistics
NumberOfOrdersByMonth=Number of orders by month
+AmountOfOrdersByMonthHT=amount of orders by month (net of tax)
ListOfOrders=List of orders
CloseOrder=Close order
ConfirmCloseOrder=Are you sure you want to close this order ? Once an order is closed, it can only be billed.
diff --git a/htdocs/langs/fr_FR/orders.lang b/htdocs/langs/fr_FR/orders.lang
index b59c74ae46a..e4a4205fe45 100755
--- a/htdocs/langs/fr_FR/orders.lang
+++ b/htdocs/langs/fr_FR/orders.lang
@@ -69,6 +69,7 @@ AllOrders=Toutes les commandes
NbOfOrders=Nombre de commandes
OrdersStatistics=Statistiques des commandes
NumberOfOrdersByMonth=Nombre de commandes par mois
+AmountOfOrdersByMonthHT=Montant total de commandes par mois (HT)
ListOfOrders=Liste des commandes
CloseOrder=Cloturer commande
ConfirmCloseOrder=Êtes-vous sur de vouloir cloturer cette commande ? Une fois une commande cloturée, elle doit être facturée.