From 657c4d6e90b35e7457f57ddb45952a1c67cbbc0b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Aug 2013 11:54:07 +0200 Subject: [PATCH] Fix: Fix graph for product distribution. Add limit and add entry other. --- htdocs/comm/propal/class/propal.class.php | 5 +- .../comm/propal/class/propalestats.class.php | 6 +- htdocs/commande/class/commandestats.class.php | 2 +- .../facture/class/facturestats.class.php | 2 +- .../boxes/box_graph_invoices_permonth.php | 4 +- .../core/boxes/box_graph_orders_permonth.php | 4 +- .../boxes/box_graph_product_distribution.php | 55 +++++++++++-------- .../boxes/box_graph_propales_permonth.php | 6 +- htdocs/core/class/stats.class.php | 12 ++-- 9 files changed, 54 insertions(+), 42 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index e3160dc61c9..eeedad858ff 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -27,7 +27,7 @@ /** * \file htdocs/comm/propal/class/propal.class.php - * \brief Fichier de la classe des propales + * \brief File of class to manage proposals */ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; @@ -36,8 +36,7 @@ require_once DOL_DOCUMENT_ROOT .'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT .'/margin/lib/margins.lib.php'; /** - * \class Propal - * \brief Classe permettant la gestion des propales + * Class to manage proposals */ class Propal extends CommonObject { diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index f8eecb486ad..343413f4012 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -21,7 +21,7 @@ /** * \file htdocs/comm/propal/class/propalestats.class.php * \ingroup propales - * \brief Fichier de la classe de gestion des stats des propales + * \brief File of class to manage proposals statistics */ include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php'; @@ -30,7 +30,7 @@ include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; /** - * Class to manage proposal statistics + * Class to manage proposals statistics */ class PropaleStats extends Stats { @@ -203,7 +203,7 @@ class PropaleStats extends Stats $sql.= " AND p.datep BETWEEN '".$this->db->idate(dol_get_first_day($year,1,false))."' AND '".$this->db->idate(dol_get_last_day($year,12,false))."'"; $sql.= " GROUP BY product.ref"; $sql.= $this->db->order('nb','DESC'); - $sql.= $this->db->plimit(20); + //$sql.= $this->db->plimit(20); return $this->_getAllByProduct($sql); } diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index 930c6ca4587..8691656128e 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -212,7 +212,7 @@ class CommandeStats extends Stats $sql.= " AND c.date_commande BETWEEN '".$this->db->idate(dol_get_first_day($year,1,false))."' AND '".$this->db->idate(dol_get_last_day($year,12,false))."'"; $sql.= " GROUP BY product.ref"; $sql.= $this->db->order('nb','DESC'); - $sql.= $this->db->plimit(20); + //$sql.= $this->db->plimit(20); return $this->_getAllByProduct($sql); } diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php index a402f2a70c4..676160ca846 100644 --- a/htdocs/compta/facture/class/facturestats.class.php +++ b/htdocs/compta/facture/class/facturestats.class.php @@ -212,7 +212,7 @@ class FactureStats extends Stats $sql.= " AND f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year,1,false))."' AND '".$this->db->idate(dol_get_last_day($year,12,false))."'"; $sql.= " GROUP BY product.ref"; $sql.= $this->db->order('nb','DESC'); - $sql.= $this->db->plimit(20); + //$sql.= $this->db->plimit(20); return $this->_getAllByProduct($sql); } diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index 7d77e2c31b4..159c834ea9e 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -66,8 +66,8 @@ class box_graph_invoices_permonth extends ModeleBoxes $refreshaction='refresh_'.$this->boxcode; - include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; - $facturestatic=new Facture($db); + //include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + //$facturestatic=new Facture($db); $text = $langs->trans("BoxCustomersInvoicesPerMonth",$max); $this->info_box_head = array( diff --git a/htdocs/core/boxes/box_graph_orders_permonth.php b/htdocs/core/boxes/box_graph_orders_permonth.php index b2456a52d76..8c33c138623 100644 --- a/htdocs/core/boxes/box_graph_orders_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_permonth.php @@ -66,8 +66,8 @@ class box_graph_orders_permonth extends ModeleBoxes $refreshaction='refresh_'.$this->boxcode; - include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; - $commandestatic=new Commande($db); + //include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; + //$commandestatic=new Commande($db); $text = $langs->trans("BoxCustomersOrdersPerMonth",$max); $this->info_box_head = array( diff --git a/htdocs/core/boxes/box_graph_product_distribution.php b/htdocs/core/boxes/box_graph_product_distribution.php index a08c25ff81d..2c63690e547 100644 --- a/htdocs/core/boxes/box_graph_product_distribution.php +++ b/htdocs/core/boxes/box_graph_product_distribution.php @@ -103,13 +103,14 @@ class box_graph_product_distribution extends ModeleBoxes $paramtitle=$langs->trans("Products").'/'.$langs->trans("Services"); if (empty($conf->produit->enabled)) $paramtitle=$langs->trans("Services"); if (empty($conf->service->enabled)) $paramtitle=$langs->trans("Products"); + + $socid=empty($user->societe_id)?0:$user->societe_id; + $userid=0; // No filter on user creation if ($user->rights->facture->lire) { include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; - $mode='customer'; - $userid=0; $WIDTH=($nbofgraph >= 2 || ! empty($conf->dol_optimize_smallscreen))?'160':'320'; $HEIGHT='192'; @@ -119,7 +120,8 @@ class box_graph_product_distribution extends ModeleBoxes include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php'; $showpointvalue = 1; $nocolor = 0; - $stats_invoice = new FactureStats($this->db, 0, $mode, ($userid>0?$userid:0)); + $mode='customer'; + $stats_invoice = new FactureStats($this->db, $socid, $mode, ($userid>0?$userid:0)); $data1 = $stats_invoice->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24))); if (empty($data1)) { @@ -134,17 +136,19 @@ class box_graph_product_distribution extends ModeleBoxes $mesg = $px1->isGraphKo(); if (! $mesg) { + $i=0;$tot=count($data1);$legend=array(); + while ($i <= $tot) + { + $data1[$i][0]=dol_trunc($data1[$i][0],5); // Required to avoid error "Could not draw pie with labels contained inside canvas" + $legend[]=$data1[$i][0]; + $i++; + } + $px1->SetData($data1); unset($data1); if ($nocolor) $px1->SetDataColor(array(array(220,220,220))); $px1->SetPrecisionY(0); - $i=0;$tot=count($data1);$legend=array(); - while ($i <= $tot) - { - $legend[]=$data1[$i][0]; - $i++; - } $px1->SetLegend($legend); $px1->setShowLegend(0); $px1->setShowPointValue($showpointvalue); @@ -174,7 +178,7 @@ class box_graph_product_distribution extends ModeleBoxes include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php'; $showpointvalue = 1; $nocolor = 0; - $stats_proposal = new PropaleStats($this->db, 0, $mode, ($userid>0?$userid:0)); + $stats_proposal = new PropaleStats($this->db, $socid, ($userid>0?$userid:0)); $data2 = $stats_proposal->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24))); if (empty($data2)) { @@ -190,17 +194,19 @@ class box_graph_product_distribution extends ModeleBoxes $mesg = $px2->isGraphKo(); if (! $mesg) { + $i=0;$tot=count($data2);$legend=array(); + while ($i <= $tot) + { + $data2[$i][0]=dol_trunc($data2[$i][0],5); // Required to avoid error "Could not draw pie with labels contained inside canvas" + $legend[]=$data2[$i][0]; + $i++; + } + $px2->SetData($data2); unset($data2); if ($nocolor) $px2->SetDataColor(array(array(220,220,220))); $px2->SetPrecisionY(0); - $i=0;$tot=count($data2);$legend=array(); - while ($i <= $tot) - { - $legend[]=$data2[$i][0]; - $i++; - } $px2->SetLegend($legend); $px2->setShowLegend(0); $px2->setShowPointValue($showpointvalue); @@ -230,7 +236,8 @@ class box_graph_product_distribution extends ModeleBoxes include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php'; $showpointvalue = 1; $nocolor = 0; - $stats_order = new CommandeStats($this->db, 0, $mode, ($userid>0?$userid:0)); + $mode='customer'; + $stats_order = new CommandeStats($this->db, $socid, $mode, ($userid>0?$userid:0)); $data3 = $stats_order->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24))); if (empty($data3)) { @@ -246,17 +253,19 @@ class box_graph_product_distribution extends ModeleBoxes $mesg = $px3->isGraphKo(); if (! $mesg) { + $i=0;$tot=count($data3);$legend=array(); + while ($i <= $tot) + { + $data3[$i][0]=dol_trunc($data3[$i][0],5); // Required to avoid error "Could not draw pie with labels contained inside canvas" + $legend[]=$data3[$i][0]; + $i++; + } + $px3->SetData($data3); unset($data3); if ($nocolor) $px3->SetDataColor(array(array(220,220,220))); $px3->SetPrecisionY(0); - $i=0;$tot=count($data3);$legend=array(); - while ($i <= $tot) - { - $legend[]=$data3[$i][0]; - $i++; - } $px3->SetLegend($legend); $px3->setShowLegend(0); $px3->setShowPointValue($showpointvalue); diff --git a/htdocs/core/boxes/box_graph_propales_permonth.php b/htdocs/core/boxes/box_graph_propales_permonth.php index d7134d3339f..e09b19b45ad 100644 --- a/htdocs/core/boxes/box_graph_propales_permonth.php +++ b/htdocs/core/boxes/box_graph_propales_permonth.php @@ -66,8 +66,8 @@ class box_graph_propales_permonth extends ModeleBoxes $refreshaction='refresh_'.$this->boxcode; - include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; - $commandestatic=new Propal($db); + //include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; + //$propalstatic=new Propal($db); $text = $langs->trans("BoxProposalsPerMonth",$max); $this->info_box_head = array( @@ -81,7 +81,7 @@ class box_graph_propales_permonth extends ModeleBoxes 'target'=>'none' // Set '' to get target="_blank" ); - if ($user->rights->commande->lire) + if ($user->rights->propal->lire) { $param_year='DOLUSERCOOKIE_param'.$this->boxcode.'year'; $param_shownb='DOLUSERCOOKIE_param'.$this->boxcode.'shownb'; diff --git a/htdocs/core/class/stats.class.php b/htdocs/core/class/stats.class.php index a1375ffb79f..874a2740edc 100644 --- a/htdocs/core/class/stats.class.php +++ b/htdocs/core/class/stats.class.php @@ -537,10 +537,13 @@ abstract class Stats * Return number or total of product refs * * @param string $sql SQL + * @param int $limit Limit * @return array */ - function _getAllByProduct($sql) + function _getAllByProduct($sql, $limit=10) { + global $langs; + $result=array(); $res=array(); @@ -549,14 +552,15 @@ abstract class Stats if ($resql) { $num = $this->db->num_rows($resql); - $i = 0; $j = 0; + $i = 0; $other=0; while ($i < $num) { $row = $this->db->fetch_row($resql); - $result[$j] = array($row[0],$row[1]); // Ref of product, nb - $j++; + if ($i < $limit || $num == $limit) $result[$i] = array($row[0],$row[1]); // Ref of product, nb + else $other += $row[1]; $i++; } + if ($num > $limit) $result[$i] = array($langs->transnoentitiesnoconv("Other"),$other); $this->db->free($resql); } else dol_print_error($this->db);