New: Enhance DolGraph class for pie charts.

This commit is contained in:
Laurent Destailleur 2013-08-09 19:19:48 +02:00
parent 4f9a1768d5
commit 59c1f54d68
5 changed files with 92 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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.='<div style="font-size:8pt;text-align:center;padding:2px;color:white;">';
if ($url) $this->_stringtoshow.='<a style="color: #FFFFFF;" border="0" href="'.$url.'=">';
$this->_stringtoshow.='\'+'.($showlegend?'number':'label+\'<br/>\'+number');
if (! empty($showpercent)) $this->_stringtoshow.='+\'<br/>\'+percent+\'%\'';
$this->_stringtoshow.='+\'';
if ($url) $this->_stringtoshow.='</a>';
if ($urltemp) $this->_stringtoshow.='<a style="color: #FFFFFF;" border="0" href="'.$urltemp.'">';
$this->_stringtoshow.='\'+';
$this->_stringtoshow.=($showlegend?'':'label+\'<br/>\'+'); // Hide label if already shown in legend
$this->_stringtoshow.=($showpointvalue?'number+':'');
$this->_stringtoshow.=($showpercent?'\'<br/>\'+percent+\'%\'+':'');
$this->_stringtoshow.='\'';
if ($urltemp) $this->_stringtoshow.='</a>';
$this->_stringtoshow.='</div>\';
},
background: {
@ -894,9 +938,12 @@ class DolGraph
var x = item.datapoint[0].toFixed(2);
var y = item.datapoint[1].toFixed(2);
var z = item.series.xaxis.ticks[item.dataIndex].label;
';
if ($this->showpointvalue > 0) $this->_stringtoshow.='
showTooltip_'.$tag.'(item.pageX, item.pageY,
item.series.label + "<br>" + z + " => " + y);
';
$this->_stringtoshow.='
}
}
else {