Fix: Fix graph for product distribution.

Add limit and add entry other.
This commit is contained in:
Laurent Destailleur 2013-08-27 11:54:07 +02:00
parent 34fe1fba7f
commit 657c4d6e90
9 changed files with 54 additions and 42 deletions

View File

@ -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
{

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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(

View File

@ -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(

View File

@ -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);

View File

@ -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';

View File

@ -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);