diff --git a/htdocs/commande/stats/commandestats.class.php b/htdocs/commande/stats/commandestats.class.php
index 89cf59f56e9..16e82b9414c 100644
--- a/htdocs/commande/stats/commandestats.class.php
+++ b/htdocs/commande/stats/commandestats.class.php
@@ -25,6 +25,7 @@
*/
include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
include_once DOL_DOCUMENT_ROOT . "/commande/commande.class.php";
+include_once DOL_DOCUMENT_ROOT . "/fourn/fournisseur.commande.class.php";
/**
@@ -47,20 +48,32 @@ class CommandeStats extends Stats
*
* @param $DB Database handler
* @param $socid Id third party
+ * @param $mode Option
* @return PropaleStats
*/
- function CommandeStats($DB, $socid=0)
+ function CommandeStats($DB, $socid=0, $mode)
{
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 ($mode == 'customer')
+ {
+ $object=new Commande($this->db);
+ $this->table_element=$object->table_element;
+ $this->field='total_ht';
+ $this->where.= " c.fk_statut > 0";
+ }
+ if ($mode == 'supplier')
+ {
+ $object=new CommandeFournisseur($this->db);
+ $this->table_element=$object->table_element;
+ $this->field='total_ht';
+ $this->where.= " c.fk_statut >= 3 AND c.date_commande IS NOT NULL";
+ }
+
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)
{
@@ -153,7 +166,7 @@ class CommandeStats extends Stats
{
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";
+ $sql = "SELECT date_format(c.date_commande,'%Y') as year, count(*) as nb, sum(c.".$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";
diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php
index b95f70023ab..cafc35e975d 100644
--- a/htdocs/commande/stats/index.php
+++ b/htdocs/commande/stats/index.php
@@ -45,19 +45,31 @@ $year = strftime("%Y", time());
$startyear=$year-2;
$endyear=$year;
+$mode='customer';
+if (isset($_GET["mode"])) $mode=$_GET["mode"];
+
/*
* View
*/
llxHeader();
-print_fiche_titre($langs->trans("OrdersStatistics"), $mesg);
+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;
+}
-$dir=$conf->commande->dir_temp;
+print_fiche_titre($title, $mesg);
create_exdir($dir);
-$stats = new CommandeStats($db, $socid);
+$stats = new CommandeStats($db, $socid, $mode);
// Build graphic number of object
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
@@ -68,12 +80,14 @@ $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filenamenb = $dir.'/ordersnbinyear-'.$user->id.'-'.$year.'.png';
- $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
+ if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
+ if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
}
else
{
$filenamenb = $dir.'/ordersnbinyear-'.$year.'.png';
- $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png';
+ if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png';
+ if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.'.png';
}
$px = new DolGraph();
@@ -110,12 +124,14 @@ $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
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';
+ if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
+ if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
}
else
{
$filenameamount = $dir.'/ordersamountinyear-'.$year.'.png';
- $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.'.png';
+ if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.'.png';
+ if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.'.png';
}
$px = new DolGraph();
@@ -123,7 +139,6 @@ $mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
- $px->SetPrecisionY(0);
$i=$startyear;
while ($i <= $endyear)
{
@@ -163,8 +178,7 @@ $oldyear=0;
foreach ($data as $val)
{
$year = $val['year'];
- print $avg;
- while ($oldyear > $year+1)
+ while ($year && $oldyear > $year+1)
{ // If we have empty year
$oldyear--;
print '
';
@@ -175,7 +189,7 @@ foreach ($data as $val)
print '
';
}
print '';
- print '| '.$year.' | ';
+ print ''.$year.' | ';
print ''.$val['nb'].' | ';
print ''.price(price2num($val['total'],'MT'),1).' | ';
print ''.price(price2num($val['avg'],'MT'),1).' | ';
diff --git a/htdocs/commande/stats/month.php b/htdocs/commande/stats/month.php
index b120c0f1893..7a729cdb599 100644
--- a/htdocs/commande/stats/month.php
+++ b/htdocs/commande/stats/month.php
@@ -77,12 +77,14 @@ $data = $stats->getNbByMonth($year);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filename = $dir.'/ordersnb-'.$user->id.'-'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$user->id.'-'.$year.'.png';
+ if ($mode == 'customer') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$user->id.'-'.$year.'.png';
+ if ($mode == 'supplier') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnb-'.$user->id.'-'.$year.'.png';
}
else
{
$filename = $dir.'/ordersnb-'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$year.'.png';
+ if ($mode == 'customer') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$year.'.png';
+ if ($mode == 'supplier') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnb-'.$year.'.png';
}
$px = new DolGraph();
@@ -107,12 +109,14 @@ $data = $stats->getAmountByMonth($year);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filename_amount = $dir.'/ordersamount-'.$user->id.'-'.$year.'.png';
- $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$user->id.'-'.$year.'.png';
+ if ($mode == 'customer') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$user->id.'-'.$year.'.png';
+ if ($mode == 'supplier') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamount-'.$user->id.'-'.$year.'.png';
}
else
{
$filename_amount = $dir.'/ordersamount-'.$year.'.png';
- $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$year.'.png';
+ if ($mode == 'customer') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$year.'.png';
+ if ($mode == 'supplier') $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamount-'.$year.'.png';
}
$px = new DolGraph();
@@ -142,12 +146,14 @@ for ($i = 1 ; $i < 13 ; $i++)
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
- $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
+ if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
+ if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
}
else
{
$filename_avg = $dir.'/ordersaverage-'.$year.'.png';
- $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
+ if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
+ if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
}
$px = new DolGraph();
diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php
index 15c8d09c6c0..773bfbae112 100644
--- a/htdocs/compta/facture/stats/index.php
+++ b/htdocs/compta/facture/stats/index.php
@@ -118,7 +118,6 @@ $mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
- $px->SetPrecisionY(0);
$i=$startyear;
while ($i <= $endyear)
{
@@ -160,8 +159,7 @@ $oldyear=0;
foreach ($data as $val)
{
$year = $val['year'];
- print $avg;
- while ($oldyear > $year+1)
+ while ($year && $oldyear > $year+1)
{ // If we have empty year
$oldyear--;
print '
';
diff --git a/htdocs/includes/menus/barre_left/eldy_backoffice.php b/htdocs/includes/menus/barre_left/eldy_backoffice.php
index e1a28076d2a..60e530deb8c 100644
--- a/htdocs/includes/menus/barre_left/eldy_backoffice.php
+++ b/htdocs/includes/menus/barre_left/eldy_backoffice.php
@@ -334,6 +334,7 @@ class MenuLeft {
$newmenu->add(DOL_URL_ROOT."/fourn/commande/index.php?leftmenu=orders_suppliers",$langs->trans("SuppliersOrders"), 0, $user->rights->fournisseur->commande->lire);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/societe.php?leftmenu=orders_suppliers", $langs->trans("NewOrder"), 1, $user->rights->fournisseur->commande->creer);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/fourn/commande/liste.php?leftmenu=orders_suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
+ if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/commande/stats/index.php?leftmenu=orders_suppliers&mode=supplier", $langs->trans("Statistics"), 1 ,$user->rights->fournisseur->commande->lire);
}
// Contrat
diff --git a/htdocs/includes/menus/barre_left/eldy_frontoffice.php b/htdocs/includes/menus/barre_left/eldy_frontoffice.php
index df0aedc223d..429fd24e28f 100644
--- a/htdocs/includes/menus/barre_left/eldy_frontoffice.php
+++ b/htdocs/includes/menus/barre_left/eldy_frontoffice.php
@@ -316,6 +316,7 @@ class MenuLeft {
$newmenu->add(DOL_URL_ROOT."/fourn/commande/index.php?leftmenu=orders_suppliers",$langs->trans("SuppliersOrders"), 0, $user->rights->fournisseur->commande->lire);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/societe.php?leftmenu=orders_suppliers", $langs->trans("NewOrder"), 1, $user->rights->fournisseur->commande->creer);
if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/fourn/commande/liste.php?leftmenu=orders_suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
+ if ($leftmenu=="orders_suppliers") $newmenu->add_submenu(DOL_URL_ROOT."/commande/stats/index.php?leftmenu=orders_suppliers&mode=supplier", $langs->trans("Statistics"), 1 ,$user->rights->fournisseur->commande->lire);
}
// Contrat
diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang
index 2c2883d3a45..75c87318c5e 100755
--- a/htdocs/langs/en_US/orders.lang
+++ b/htdocs/langs/en_US/orders.lang
@@ -68,6 +68,7 @@ LastClosedOrders=Last %s closed orders
AllOrders=All orders
NbOfOrders=Number of orders
OrdersStatistics=Orders' statistics
+OrdersStatisticsSuppliers=Supplier orders' statistics
NumberOfOrdersByMonth=Number of orders by month
AmountOfOrdersByMonthHT=amount of orders by month (net of tax)
ListOfOrders=List of orders
diff --git a/htdocs/langs/fr_FR/orders.lang b/htdocs/langs/fr_FR/orders.lang
index e4a4205fe45..07eb7602ad2 100755
--- a/htdocs/langs/fr_FR/orders.lang
+++ b/htdocs/langs/fr_FR/orders.lang
@@ -68,6 +68,7 @@ LastClosedOrders=Les %s derni
AllOrders=Toutes les commandes
NbOfOrders=Nombre de commandes
OrdersStatistics=Statistiques des commandes
+OrdersStatisticsSuppliers=Statistiques des commandes fournisseurs
NumberOfOrdersByMonth=Nombre de commandes par mois
AmountOfOrdersByMonthHT=Montant total de commandes par mois (HT)
ListOfOrders=Liste des commandes
diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php
index 7f8206c8fc0..2c5c7bb7e23 100644
--- a/htdocs/viewimage.php
+++ b/htdocs/viewimage.php
@@ -156,7 +156,16 @@ if ($modulepart)
}
$original_file=$conf->commande->dir_temp.'/'.$original_file;
}
-
+ elseif ($modulepart == 'orderstatssupplier')
+ {
+ $user->getrights('fournisseur');
+ if ($user->rights->fournisseur->commande->lire)
+ {
+ $accessallowed=1;
+ }
+ $original_file=$conf->fournisseur->commande->dir_temp.'/'.$original_file;
+ }
+
// Wrapping pour les images des stats factures
elseif ($modulepart == 'billstats')
{