Work on graphical box with product distribution
This commit is contained in:
parent
6d4fa94bf1
commit
4f9a1768d5
@ -62,10 +62,11 @@ class PropaleStats extends Stats
|
||||
$object=new Propal($this->db);
|
||||
|
||||
$this->from = MAIN_DB_PREFIX.$object->table_element." as p";
|
||||
//$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl";
|
||||
|
||||
$this->field='total_ht';
|
||||
|
||||
$this->field_line='total_ht';
|
||||
|
||||
$this->where.= " p.fk_statut > 0";
|
||||
//$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity;
|
||||
$this->where.= " AND p.entity = ".$conf->entity;
|
||||
@ -182,5 +183,28 @@ class PropaleStats extends Stats
|
||||
return $this->_getAllByYear($sql);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return nb, amount of predefined product for year
|
||||
*
|
||||
* @param int $year Year to scan
|
||||
* @return array Array of values
|
||||
*/
|
||||
function getAllByProduct($year)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg";
|
||||
$sql.= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product";
|
||||
//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.= " GROUP BY product.ref";
|
||||
$sql.= $this->db->order('nb','DESC');
|
||||
$sql.= $this->db->plimit(20);
|
||||
|
||||
return $this->_getAllByProduct($sql);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@ -66,16 +66,18 @@ class CommandeStats extends Stats
|
||||
{
|
||||
$object=new Commande($this->db);
|
||||
$this->from = MAIN_DB_PREFIX.$object->table_element." as c";
|
||||
//$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl";
|
||||
$this->field='total_ht';
|
||||
$this->field_line='total_ht';
|
||||
$this->where.= " c.fk_statut > 0"; // Not draft and not cancelled
|
||||
}
|
||||
if ($mode == 'supplier')
|
||||
{
|
||||
$object=new CommandeFournisseur($this->db);
|
||||
$this->from = MAIN_DB_PREFIX.$object->table_element." as c";
|
||||
//$this->from.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl";
|
||||
$this->field='total_ht';
|
||||
$this->field_line='total_ht';
|
||||
$this->where.= " c.fk_statut > 2"; // Only approved & ordered
|
||||
}
|
||||
//$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity;
|
||||
@ -191,6 +193,29 @@ class CommandeStats extends Stats
|
||||
|
||||
return $this->_getAllByYear($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return nb, amount of predefined product for year
|
||||
*
|
||||
* @param int $year Year to scan
|
||||
* @return array Array of values
|
||||
*/
|
||||
function getAllByProduct($year)
|
||||
{
|
||||
global $user;
|
||||
|
||||
$sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg";
|
||||
$sql.= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product";
|
||||
//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.= " GROUP BY product.ref";
|
||||
$sql.= $this->db->order('nb','DESC');
|
||||
$sql.= $this->db->plimit(20);
|
||||
|
||||
return $this->_getAllByProduct($sql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@ -86,28 +86,34 @@ class box_graph_product_distribution extends ModeleBoxes
|
||||
$param_year='DOLUSERCOOKIE_param'.$this->boxcode.'year';
|
||||
$param_showinvoicenb='DOLUSERCOOKIE_param'.$this->boxcode.'showinvoicenb';
|
||||
$param_showpropalnb='DOLUSERCOOKIE_param'.$this->boxcode.'showpropalnb';
|
||||
$param_showordernb='DOLUSERCOOKIE_param'.$this->boxcode.'showordernb';
|
||||
$showinvoicenb=GETPOST($param_showinvoicenb,'alpha',4);
|
||||
$showpropalnb=GETPOST($param_showpropalnb,'alpha',4);
|
||||
if (empty($showinvoicenb) && empty($showpropalnb)) { $showpropalnb=1; $showinvoicenb=1; }
|
||||
$showordernb=GETPOST($param_showordernb,'alpha',4);
|
||||
if (empty($showinvoicenb) && empty($showpropalnb) && empty($showordernb)) { $showpropalnb=1; $showinvoicenb=1; $showordernb=1; }
|
||||
$nowarray=dol_getdate(dol_now(),true);
|
||||
$year=(GETPOST($param_year,'',4)?GETPOST($param_year,'int',4):$nowarray['year']);
|
||||
|
||||
$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");
|
||||
|
||||
if ($user->rights->facture->lire)
|
||||
{
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php';
|
||||
|
||||
$mode='customer';
|
||||
$userid=0;
|
||||
$WIDTH=(($showinvoicenb && $showpropalnb) || ! empty($conf->dol_optimize_smallscreen))?'256':'320';
|
||||
$WIDTH=(($showinvoicenb && $showpropalnb) || ! empty($conf->dol_optimize_smallscreen))?'160':'320';
|
||||
$HEIGHT='192';
|
||||
|
||||
$stats = new FactureStats($this->db, 0, $mode, ($userid>0?$userid:0));
|
||||
|
||||
|
||||
// Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
|
||||
if ($showinvoicenb)
|
||||
{
|
||||
$data1 = $stats->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24)));
|
||||
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php';
|
||||
|
||||
$stats_invoice = new FactureStats($this->db, 0, $mode, ($userid>0?$userid:0));
|
||||
$data1 = $stats_invoice->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24)));
|
||||
|
||||
$filenamenb = $dir."/prodserforinvoice-".$year.".png";
|
||||
$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=productstats&file=prodserforinvoice-'.$year.'.png';
|
||||
@ -136,22 +142,25 @@ class box_graph_product_distribution extends ModeleBoxes
|
||||
$px1->SetCssPrefix("cssboxes");
|
||||
//$px1->mode='depth';
|
||||
$px1->SetType(array('pie'));
|
||||
$px1->SetTitle($langs->trans("BoxProductDistributionFor",$langs->trans("ProductsServices"),$langs->transnoentitiesnoconv("Invoices")));
|
||||
$px1->SetTitle($langs->trans("BoxProductDistributionFor",$paramtitle,$langs->transnoentitiesnoconv("Invoices")));
|
||||
|
||||
$px1->draw($filenamenb,$fileurlnb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if ($user->rights->propal->lire)
|
||||
if ($user->rights->propal->lire)
|
||||
{
|
||||
// Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
|
||||
if ($showpropalnb)
|
||||
{
|
||||
$data2 = $stats->getAmountByMonthWithPrevYear($year,(GETPOST('action')==$refreshaction?-1:(3600*24)));
|
||||
include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php';
|
||||
|
||||
$stats_proposal = new PropaleStats($this->db, 0, $mode, ($userid>0?$userid:0));
|
||||
$data2 = $stats_proposal->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24)));
|
||||
|
||||
$filenamenb = $dir."/prodserforpropal-".$year.".png";
|
||||
$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=prodserforpropal-'.$year.'.png';
|
||||
$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=proposalstats&file=prodserforpropal-'.$year.'.png';
|
||||
|
||||
$px2 = new DolGraph();
|
||||
$mesg = $px2->isGraphKo();
|
||||
@ -175,14 +184,58 @@ class box_graph_product_distribution extends ModeleBoxes
|
||||
$px2->SetHorizTickIncrement(1);
|
||||
$px2->SetPrecisionY(0);
|
||||
$px2->SetCssPrefix("cssboxes");
|
||||
$px2->mode='depth';
|
||||
$px2->SetTitle($langs->trans("BoxProductDistributionFor",$langs->trans("ProductsServices"),$langs->transnoentitiesnoconv("Proposals")));
|
||||
//$px2->mode='depth';
|
||||
$px2->SetType(array('pie'));
|
||||
$px2->SetTitle($langs->trans("BoxProductDistributionFor",$paramtitle,$langs->transnoentitiesnoconv("Proposals")));
|
||||
|
||||
$px2->draw($filenamenb,$fileurlnb);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if ($user->rights->commande->lire)
|
||||
{
|
||||
// Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
|
||||
if ($showordernb)
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php';
|
||||
|
||||
$stats_order = new CommandeStats($this->db, 0, $mode, ($userid>0?$userid:0));
|
||||
$data3 = $stats_order->getAllByProductEntry($year,(GETPOST('action')==$refreshaction?-1:(3600*24)));
|
||||
|
||||
$filenamenb = $dir."/prodserfororder-".$year.".png";
|
||||
$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=prodserfororder-'.$year.'.png';
|
||||
|
||||
$px3 = new DolGraph();
|
||||
$mesg = $px3->isGraphKo();
|
||||
if (! $mesg)
|
||||
{
|
||||
$px3->SetData($data3);
|
||||
unset($data3);
|
||||
$px3->SetPrecisionY(0);
|
||||
$i=0;$tot=count($data3);$legend=array();
|
||||
while ($i <= $tot)
|
||||
{
|
||||
$legend[]=$data3[$i][0];
|
||||
$i++;
|
||||
}
|
||||
$px3->SetLegend($legend);
|
||||
$px3->SetMaxValue($px3->GetCeilMaxValue());
|
||||
$px3->SetWidth($WIDTH);
|
||||
$px3->SetHeight($HEIGHT);
|
||||
//$px3->SetYLabel($langs->trans("AmountOfBillsHT"));
|
||||
$px3->SetShading(3);
|
||||
$px3->SetHorizTickIncrement(1);
|
||||
$px3->SetPrecisionY(0);
|
||||
$px3->SetCssPrefix("cssboxes");
|
||||
//$px3->mode='depth';
|
||||
$px3->SetType(array('pie'));
|
||||
$px3->SetTitle($langs->trans("BoxProductDistributionFor",$paramtitle,$langs->transnoentitiesnoconv("Orders")));
|
||||
$px3->draw($filenamenb,$fileurlnb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $mesg)
|
||||
{
|
||||
$stringtoshow='';
|
||||
@ -197,33 +250,39 @@ class box_graph_product_distribution extends ModeleBoxes
|
||||
$stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
$stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
|
||||
$stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="'.$param_year.','.$param_showinvoicenb.','.$param_showpropalnb.'">';
|
||||
$stringtoshow.='<input type="checkbox" name="'.$param_showinvoicenb.'"'.($showinvoicenb?' checked="true"':'').'"> '.$langs->trans("ForInvoice");
|
||||
$stringtoshow.='<input type="checkbox" name="'.$param_showinvoicenb.'"'.($showinvoicenb?' checked="true"':'').'"> '.$langs->trans("ForCustomersInvoices");
|
||||
$stringtoshow.=' ';
|
||||
$stringtoshow.='<input type="checkbox" name="'.$param_showpropalnb.'"'.($showpropalnb?' checked="true"':'').'"> '.$langs->trans("ForProposals");
|
||||
$stringtoshow.=' ';
|
||||
$stringtoshow.='<input type="checkbox" name="'.$param_showordernb.'"'.($showordernb?' checked="true"':'').'"> '.$langs->trans("ForOrders");
|
||||
$stringtoshow.='<input type="checkbox" name="'.$param_showordernb.'"'.($showordernb?' checked="true"':'').'"> '.$langs->trans("ForCustomersOrders");
|
||||
$stringtoshow.='<br>';
|
||||
$stringtoshow.=$langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$year.'">';
|
||||
$stringtoshow.='<input type="image" src="'.img_picto($langs->trans("Refresh"),'refresh.png','','',1).'">';
|
||||
$stringtoshow.='</form>';
|
||||
$stringtoshow.='</div>';
|
||||
if ($showinvoicenb && $showpropalnb)
|
||||
{
|
||||
$stringtoshow.='<div class="fichecenter">';
|
||||
$stringtoshow.='<div class="fichehalfleft">';
|
||||
}
|
||||
//if ($showinvoicenb && $showpropalnb && $showordernb)
|
||||
//{
|
||||
$stringtoshow.='<div class="fichecenter"><div class="containercenter">';
|
||||
$stringtoshow.='<div class="fichehalfleftxxx">';
|
||||
//}
|
||||
if ($showinvoicenb) $stringtoshow.=$px1->show();
|
||||
if ($showinvoicenb && $showpropalnb)
|
||||
{
|
||||
//if ($showinvoicenb && $showpropalnb)
|
||||
//{
|
||||
$stringtoshow.='</div>';
|
||||
$stringtoshow.='<div class="fichehalfright">';
|
||||
}
|
||||
// if ($showpropalnb) $stringtoshow.=$px2->show();
|
||||
if ($showinvoicenb && $showpropalnb)
|
||||
{
|
||||
$stringtoshow.='<div class="fichehalfrightxxx">';
|
||||
//}
|
||||
if ($showpropalnb) $stringtoshow.=$px2->show();
|
||||
//if ($showinvoicenb && $showpropalnb)
|
||||
//{
|
||||
$stringtoshow.='</div>';
|
||||
$stringtoshow.='<div class="fichehalfrightxxx">';
|
||||
//}
|
||||
if ($showordernb) $stringtoshow.=$px3->show();
|
||||
//if ($showinvoicenb && $showpropalnb)
|
||||
//{
|
||||
$stringtoshow.='</div></div>';
|
||||
$stringtoshow.='</div>';
|
||||
}
|
||||
//}
|
||||
$this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"','textnoformat'=>$stringtoshow);
|
||||
}
|
||||
else
|
||||
|
||||
@ -85,4 +85,7 @@ BoxSuppliersOrdersPerMonth=Supplier orders per month
|
||||
BoxProposalsPerMonth=Proposals per month
|
||||
NoTooLowStockProducts=No product under the low stock limit
|
||||
BoxProductDistribution=Products/Services distribution
|
||||
BoxProductDistributionFor=Distribution of %s for %s
|
||||
BoxProductDistributionFor=Distribution of %s for %s
|
||||
ForCustomersInvoices=Customers invoices
|
||||
ForCustomersOrders=Customers orders
|
||||
ForProposals=Proposals
|
||||
@ -85,4 +85,7 @@ BoxSuppliersOrdersPerMonth=Commandes fournisseurs par mois
|
||||
BoxProposalsPerMonth=Proposition par mois
|
||||
NoTooLowStockProducts=Pas de produits sous le seuil de stock minimal
|
||||
BoxProductDistribution=Répartition des produis/services
|
||||
BoxProductDistributionFor=Répartition des %s pour les %s
|
||||
BoxProductDistributionFor=Répartition des %s pour les %s
|
||||
ForCustomersInvoices=Factures clients
|
||||
ForCustomersOrders=Commandes clients
|
||||
ForProposals=Propositions
|
||||
@ -478,6 +478,10 @@ div.ficheaddleft {
|
||||
<?php if (empty($conf->dol_optimize_smallscreen)) { print "padding-left: 16px;\n"; }
|
||||
else print "margin-top: 10px;\n"; ?>
|
||||
}
|
||||
.containercenter {
|
||||
display : table;
|
||||
margin : 0px auto;
|
||||
}
|
||||
|
||||
|
||||
/* ============================================================================== */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user