From db9498262bc73bcec75466bb344247ca33b880e7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 27 Mar 2023 15:26:54 +0200 Subject: [PATCH] NEW Add statistics by amount on statistics of products. --- htdocs/langs/en_US/other.lang | 19 ++------- htdocs/product/class/product.class.php | 28 ++++++++---- htdocs/product/stats/card.php | 59 +++++++++++++++++--------- 3 files changed, 64 insertions(+), 42 deletions(-) diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index b03d35a68da..e2d46564ea2 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -187,23 +187,12 @@ AuthenticationDoesNotAllowSendNewPassword=Authentication mode is %s.
I EnableGDLibraryDesc=Install or enable GD library on your PHP installation to use this option. ProfIdShortDesc=Prof Id %s is an information depending on third party country.
For example, for country %s, it's code %s. DolibarrDemo=Dolibarr ERP/CRM demo +StatsByAmount=Statistics on amount of products/services StatsByNumberOfUnits=Statistics for sum of qty of products/services StatsByNumberOfEntities=Statistics for number of referring entities (no. of invoices, or orders...) -NumberOfProposals=Number of proposals -NumberOfCustomerOrders=Number of sales orders -NumberOfCustomerInvoices=Number of customer invoices -NumberOfSupplierProposals=Number of vendor proposals -NumberOfSupplierOrders=Number of purchase orders -NumberOfSupplierInvoices=Number of vendor invoices -NumberOfContracts=Number of contracts -NumberOfMos=Number of manufacturing orders -NumberOfUnitsProposals=Number of units on proposals -NumberOfUnitsCustomerOrders=Number of units on sales orders -NumberOfUnitsCustomerInvoices=Number of units on customer invoices -NumberOfUnitsSupplierProposals=Number of units on vendor proposals -NumberOfUnitsSupplierOrders=Number of units on purchase orders -NumberOfUnitsSupplierInvoices=Number of units on vendor invoices -NumberOfUnitsContracts=Number of units on contracts +NumberOf=Number of %s +NumberOfUnits=Number of units on %s +AmountIn=Amount in %s NumberOfUnitsMos=Number of units to produce in manufacturing orders EMailTextInterventionAddedContact=A new intervention %s has been assigned to you. EMailTextInterventionValidated=The intervention %s has been validated. diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 0d7b4675bcf..c726ae0a8ac 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3753,6 +3753,11 @@ class Product extends CommonObject $tab[$keyfortab] = (empty($tab[$keyfortab]) ? 0 : $tab[$keyfortab]) + $arr[0]; // 1st field } elseif ($mode == 'bynumber') { $tab[$keyfortab] = (empty($tab[$keyfortab]) ? 0 : $tab[$keyfortab]) + $arr[2]; // 3rd field + } elseif ($mode == 'byamount') { + $tab[$keyfortab] = (empty($tab[$keyfortab]) ? 0 : $tab[$keyfortab]) + $arr[2]; // 3rd field + } else { + // Bad value for $mode + return -1; } $i++; } @@ -3812,10 +3817,11 @@ class Product extends CommonObject global $conf; global $user; - $sql = "SELECT sum(d.qty), date_format(f.datef, '%Y%m')"; + $sql = "SELECT sum(d.qty) as qty, date_format(f.datef, '%Y%m')"; if ($mode == 'bynumber') { $sql .= ", count(DISTINCT f.rowid)"; } + $sql .= ", sum(d.total_ht) as total_ht"; $sql .= " FROM ".$this->db->prefix()."facturedet as d, ".$this->db->prefix()."facture as f, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { $sql .= ", ".$this->db->prefix()."product as p"; @@ -3865,10 +3871,11 @@ class Product extends CommonObject global $conf; global $user; - $sql = "SELECT sum(d.qty), date_format(f.datef, '%Y%m')"; + $sql = "SELECT sum(d.qty) as qty, date_format(f.datef, '%Y%m')"; if ($mode == 'bynumber') { $sql .= ", count(DISTINCT f.rowid)"; } + $sql .= ", sum(d.total_ht) as total_ht"; $sql .= " FROM ".$this->db->prefix()."facture_fourn_det as d, ".$this->db->prefix()."facture_fourn as f, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { $sql .= ", ".$this->db->prefix()."product as p"; @@ -3905,7 +3912,7 @@ class Product extends CommonObject * Return nb of units in proposals in which product is included * * @param int $socid Limit count on a particular third party id - * @param string $mode 'byunit'=number of unit, 'bynumber'=nb of entities + * @param string $mode 'byunit'=number of unit, 'bynumber'=nb of entities, 'byamount'=amount * @param int $filteronproducttype 0=To filter on product only, 1=To filter on services only * @param int $year Year (0=last 12 month, -1=all years) * @param string $morefilter More sql filters @@ -3916,10 +3923,11 @@ class Product extends CommonObject // phpcs:enable global $conf, $user; - $sql = "SELECT sum(d.qty), date_format(p.datep, '%Y%m')"; + $sql = "SELECT sum(d.qty) as qty, date_format(p.datep, '%Y%m')"; if ($mode == 'bynumber') { $sql .= ", count(DISTINCT p.rowid)"; } + $sql .= ", sum(d.total_ht) as total_ht"; $sql .= " FROM ".$this->db->prefix()."propaldet as d, ".$this->db->prefix()."propal as p, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { $sql .= ", ".$this->db->prefix()."product as prod"; @@ -3968,10 +3976,11 @@ class Product extends CommonObject global $conf; global $user; - $sql = "SELECT sum(d.qty), date_format(p.date_valid, '%Y%m')"; + $sql = "SELECT sum(d.qty) as qty, date_format(p.date_valid, '%Y%m')"; if ($mode == 'bynumber') { $sql .= ", count(DISTINCT p.rowid)"; } + $sql .= ", sum(d.total_ht) as total_ht"; $sql .= " FROM ".$this->db->prefix()."supplier_proposaldet as d, ".$this->db->prefix()."supplier_proposal as p, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { $sql .= ", ".$this->db->prefix()."product as prod"; @@ -4019,10 +4028,11 @@ class Product extends CommonObject // phpcs:enable global $conf, $user; - $sql = "SELECT sum(d.qty), date_format(c.date_commande, '%Y%m')"; + $sql = "SELECT sum(d.qty) as qty, date_format(c.date_commande, '%Y%m')"; if ($mode == 'bynumber') { $sql .= ", count(DISTINCT c.rowid)"; } + $sql .= ", sum(d.total_ht) as total_ht"; $sql .= " FROM ".$this->db->prefix()."commandedet as d, ".$this->db->prefix()."commande as c, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { $sql .= ", ".$this->db->prefix()."product as p"; @@ -4070,10 +4080,11 @@ class Product extends CommonObject // phpcs:enable global $conf, $user; - $sql = "SELECT sum(d.qty), date_format(c.date_commande, '%Y%m')"; + $sql = "SELECT sum(d.qty) as qty, date_format(c.date_commande, '%Y%m')"; if ($mode == 'bynumber') { $sql .= ", count(DISTINCT c.rowid)"; } + $sql .= ", sum(d.total_ht) as total_ht"; $sql .= " FROM ".$this->db->prefix()."commande_fournisseurdet as d, ".$this->db->prefix()."commande_fournisseur as c, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { $sql .= ", ".$this->db->prefix()."product as p"; @@ -4121,10 +4132,11 @@ class Product extends CommonObject // phpcs:enable global $conf, $user; - $sql = "SELECT sum(d.qty), date_format(c.date_contrat, '%Y%m')"; + $sql = "SELECT sum(d.qty) as qty, date_format(c.date_contrat, '%Y%m')"; if ($mode == 'bynumber') { $sql .= ", count(DISTINCT c.rowid)"; } + $sql .= ", sum(d.total_ht) as total_ht"; $sql .= " FROM ".$this->db->prefix()."contratdet as d, ".$this->db->prefix()."contrat as c, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { $sql .= ", ".$this->db->prefix()."product as p"; diff --git a/htdocs/product/stats/card.php b/htdocs/product/stats/card.php index 3133f83e6d8..ab7020a5df8 100644 --- a/htdocs/product/stats/card.php +++ b/htdocs/product/stats/card.php @@ -254,17 +254,18 @@ if ($result || !($id > 0)) { } // Choice of stats mode (byunit or bynumber) + if (!empty($conf->dol_use_jmobile)) { print "\n".'
'."\n"; } - if ($mode == 'bynumber') { + if ($mode != 'byunit') { print ''; } else { print ''; } print $langs->trans("StatsByNumberOfUnits"); - if ($mode == 'bynumber') { + if ($mode != 'byunit') { print ''; } else { print ''; @@ -274,18 +275,35 @@ if ($result || !($id > 0)) { print '
'."\n".'
'."\n"; } - if ($mode == 'byunit') { + if ($mode != 'bynumber') { print ''; } else { print ''; } print $langs->trans("StatsByNumberOfEntities"); - if ($mode == 'byunit') { + if ($mode != 'bynumber') { print ''; } else { print ''; } + if (!empty($conf->dol_use_jmobile)) { + print '
'."\n".'
'."\n"; + } + + if ($mode != 'byamount') { + print ''; + } else { + print ''; + } + print $langs->trans("StatsByAmount"); + if ($mode != 'byamount') { + print ''; + } else { + print ''; + } + + // End of choices if (!empty($conf->dol_use_jmobile)) { print '
'; } else { @@ -304,52 +322,55 @@ if ($result || !($id > 0)) { } } + $arrayforlabel = array('byunit' => 'NumberOfUnits', 'bynumber' => 'NumberOf', 'byamount' => 'AmountIn'); + if (isModEnabled('propal')) { $graphfiles['propal'] = array('modulepart'=>'productstats_proposals', - 'file' => $object->id.'/propal12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', - 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsProposals") : $langs->transnoentitiesnoconv("NumberOfProposals"))); + 'file' => $object->id.'/propal12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', + 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("Proposals"))); } if (isModEnabled('supplier_proposal')) { + $langs->load("supplier_proposal"); $graphfiles['proposalssuppliers'] = array('modulepart'=>'productstats_proposalssuppliers', - 'file' => $object->id.'/proposalssuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', - 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsSupplierProposals") : $langs->transnoentitiesnoconv("NumberOfSupplierProposals"))); + 'file' => $object->id.'/proposalssuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', + 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("SupplierProposals"))); } if (isModEnabled('order')) { $graphfiles['orders'] = array('modulepart'=>'productstats_orders', - 'file' => $object->id.'/orders12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', - 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsCustomerOrders") : $langs->transnoentitiesnoconv("NumberOfCustomerOrders"))); + 'file' => $object->id.'/orders12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', + 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("Orders"))); } if (isModEnabled('supplier_order')) { $graphfiles['orderssuppliers'] = array('modulepart'=>'productstats_orderssuppliers', - 'file' => $object->id.'/orderssuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', - 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsSupplierOrders") : $langs->transnoentitiesnoconv("NumberOfSupplierOrders"))); + 'file' => $object->id.'/orderssuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', + 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("SuppliersOrders"))); } if (isModEnabled('facture')) { $graphfiles['invoices'] = array('modulepart'=>'productstats_invoices', - 'file' => $object->id.'/invoices12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', - 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsCustomerInvoices") : $langs->transnoentitiesnoconv("NumberOfCustomerInvoices"))); + 'file' => $object->id.'/invoices12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', + 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("Invoices"))); } if (isModEnabled('supplier_invoice')) { $graphfiles['invoicessuppliers'] = array('modulepart'=>'productstats_invoicessuppliers', - 'file' => $object->id.'/invoicessuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', - 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsSupplierInvoices") : $langs->transnoentitiesnoconv("NumberOfSupplierInvoices"))); + 'file' => $object->id.'/invoicessuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', + 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("SupplierInvoices"))); } if (isModEnabled('contrat')) { $graphfiles['contracts'] = array('modulepart'=>'productstats_contracts', 'file' => $object->id.'/contracts12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', - 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsContracts") : $langs->transnoentitiesnoconv("NumberOfContracts"))); + 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("Contracts"))); } - if (isModEnabled('mrp')) { + if (isModEnabled('mrp') && $mode != 'byamount') { $graphfiles['mrp'] = array('modulepart'=>'productstats_mrp', 'file' => $object->id.'/mos12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png', - 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsMos") : $langs->transnoentitiesnoconv("NumberOfMos"))); + 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode]."Mos")); } $px = new DolGraph();