diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 1b1b5d2e045..f8eecb486ad 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -200,6 +200,7 @@ class PropaleStats extends Stats //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; $sql.= " AND p.rowid = tl.fk_propal AND tl.fk_product = product.rowid"; + $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); diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index a1c976db6a5..930c6ca4587 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -209,6 +209,7 @@ class CommandeStats extends Stats //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; $sql.= " AND c.rowid = tl.fk_commande AND tl.fk_product = product.rowid"; + $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); diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php index 7f33f66fd8b..a402f2a70c4 100644 --- a/htdocs/compta/facture/class/facturestats.class.php +++ b/htdocs/compta/facture/class/facturestats.class.php @@ -209,6 +209,7 @@ class FactureStats extends Stats //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; $sql.= " AND f.rowid = tl.fk_facture AND tl.fk_product = product.rowid"; + $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); diff --git a/htdocs/core/boxes/box_graph_product_distribution.php b/htdocs/core/boxes/box_graph_product_distribution.php index c92b9100e1f..9311832d3be 100644 --- a/htdocs/core/boxes/box_graph_product_distribution.php +++ b/htdocs/core/boxes/box_graph_product_distribution.php @@ -112,9 +112,14 @@ class box_graph_product_distribution extends ModeleBoxes { include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php'; + $showpointvalue = 1; $stats_invoice = new FactureStats($this->db, 0, $mode, ($userid>0?$userid:0)); $data1 = $stats_invoice->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24))); - + if (empty($data1)) + { + $showpointvalue=0; + $data1=array(array(0=>$langs->trans("None"),1=>1)); + } $filenamenb = $dir."/prodserforinvoice-".$year.".png"; $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=productstats&file=prodserforinvoice-'.$year.'.png'; @@ -125,13 +130,16 @@ class box_graph_product_distribution extends ModeleBoxes $px1->SetData($data1); unset($data1); $px1->SetPrecisionY(0); - $i=0;$tot=count($data2);$legend=array(); + $i=0;$tot=count($data1);$legend=array(); while ($i <= $tot) { - $legend[]=$data2[$i][0]; + $legend[]=$data1[$i][0]; $i++; } $px1->SetLegend($legend); + $px1->setShowLegend(0); + $px1->setShowPointValue($showpointvalue); + $px1->setShowPercent(0); $px1->SetMaxValue($px1->GetCeilMaxValue()); $px1->SetWidth($WIDTH); $px1->SetHeight($HEIGHT); @@ -143,7 +151,7 @@ class box_graph_product_distribution extends ModeleBoxes //$px1->mode='depth'; $px1->SetType(array('pie')); $px1->SetTitle($langs->trans("BoxProductDistributionFor",$paramtitle,$langs->transnoentitiesnoconv("Invoices"))); - + $px1->draw($filenamenb,$fileurlnb); } } @@ -156,9 +164,15 @@ class box_graph_product_distribution extends ModeleBoxes { include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php'; + $showpointvalue = 1; $stats_proposal = new PropaleStats($this->db, 0, $mode, ($userid>0?$userid:0)); $data2 = $stats_proposal->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24))); - + if (empty($data2)) + { + $showpointvalue = 0; + $data2=array(array(0=>$langs->trans("None"),1=>1)); + } + $filenamenb = $dir."/prodserforpropal-".$year.".png"; $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=proposalstats&file=prodserforpropal-'.$year.'.png'; @@ -176,6 +190,9 @@ class box_graph_product_distribution extends ModeleBoxes $i++; } $px2->SetLegend($legend); + $px2->setShowLegend(0); + $px2->setShowPointValue($showpointvalue); + $px2->setShowPercent(0); $px2->SetMaxValue($px2->GetCeilMaxValue()); $px2->SetWidth($WIDTH); $px2->SetHeight($HEIGHT); @@ -200,9 +217,15 @@ class box_graph_product_distribution extends ModeleBoxes { include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php'; + $showpointvalue = 1; $stats_order = new CommandeStats($this->db, 0, $mode, ($userid>0?$userid:0)); $data3 = $stats_order->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24))); - + if (empty($data3)) + { + $showpointvalue = 0; + $data3=array(array(0=>$langs->trans("None"),1=>1)); + } + $filenamenb = $dir."/prodserfororder-".$year.".png"; $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=prodserfororder-'.$year.'.png'; @@ -220,6 +243,9 @@ class box_graph_product_distribution extends ModeleBoxes $i++; } $px3->SetLegend($legend); + $px3->setShowLegend(0); + $px3->setShowPointValue($showpointvalue); + $px3->setShowPercent(0); $px3->SetMaxValue($px3->GetCeilMaxValue()); $px3->SetWidth($WIDTH); $px3->SetHeight($HEIGHT); diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 9c6cc5b424e..54ec78a8287 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -68,7 +68,10 @@ class DolGraph var $Legend=array(); var $LegendWidthMin=0; - + var $showlegend=1; + var $showpointvalue=1; + var $showpercent=0; + var $graph; // Objet Graph (Artichow, Phplot...) var $error; @@ -234,6 +237,7 @@ class DolGraph * * @param array $data Data * @return void + * @see draw_jflot for syntax of data array */ function SetData($data) { @@ -379,7 +383,41 @@ class DolGraph return $this->error; } + /** + * Show legend or not + * + * @param int $showlegend 1=Show legend (default), 0=Hide legend + * @return void + */ + function setShowLegend($showlegend) + { + $this->showlegend=$showlegend; + } + /** + * Show pointvalue or not + * + * @param int $showpointvalue 1=Show value for each point, as tooltip or inline (default), 0=Hide value + * @return void + */ + function setShowPointValue($showpointvalue) + { + $this->showpointvalue=$showpointvalue; + } + + /** + * Show percent or not + * + * @param int $showpercent 1=Show percent for each point, as tooltip or inline, 0=Hide percent (default) + * @return void + */ + function setShowPercent($showpercent) + { + $this->showpercent=$showpercent; + } + + + /** * Define background color of complete image * @@ -766,14 +804,13 @@ class DolGraph // Works with line but not with bars //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x - $i=$firstlot; $serie=array(); while ($i < $nblot) // Loop on each serie { $values=array(); // Array with horizontal y values (specific values of a serie) for each abscisse x $serie[$i]="var d".$i." = [];\n"; - + // Fill array $values $x=0; foreach($this->data as $valarray) // Loop on each x @@ -816,7 +853,12 @@ class DolGraph { $datacolor=array(); foreach($this->datacolor as $val) $datacolor[]="#".sprintf("%02x%02x%02x",$val[0],$val[1],$val[2]); - + + $urltemp=''; // TODO Add support for url link into labels + $showlegend=$this->showlegend; + $showpointvalue=$this->showpointvalue; + $showpercent=$this->showpercent; + $this->_stringtoshow.= ' function plotWithOptions_'.$tag.'() { $.plot($("#placeholder_'.$tag.'"), d0, @@ -833,11 +875,13 @@ class DolGraph var number=series.data[0][1]; return \''; $this->_stringtoshow.='