diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 5b5b0dd7279..1b1b5d2e045 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -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); + } } ?> diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index 9609a4e9440..a1c976db6a5 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -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); + } + } ?> \ No newline at end of file diff --git a/htdocs/core/boxes/box_graph_product_distribution.php b/htdocs/core/boxes/box_graph_product_distribution.php index 8fccc4fd8a0..c92b9100e1f 100644 --- a/htdocs/core/boxes/box_graph_product_distribution.php +++ b/htdocs/core/boxes/box_graph_product_distribution.php @@ -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.='
'; $stringtoshow.=''; - if ($showinvoicenb && $showpropalnb) - { - $stringtoshow.='