From 56704e4029c6f848379eed0f14c01111335a4c39 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Feb 2020 19:26:52 +0100 Subject: [PATCH] Add stats of products in MO --- htdocs/core/lib/functions.lib.php | 2 +- htdocs/langs/en_US/other.lang | 2 + htdocs/product/class/product.class.php | 63 ++++++++++++++++++++++++-- htdocs/product/stats/card.php | 10 +++- 4 files changed, 70 insertions(+), 7 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 0b732f9372a..add951feb16 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -65,7 +65,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) * * @param string $element Current element * 'societe', 'socpeople', 'actioncomm', 'agenda', 'resource', - * 'product', 'productprice', 'stock', + * 'product', 'productprice', 'stock', 'bom', 'mo', * 'propal', 'supplier_proposal', 'invoice', 'facture_fourn', 'payment_various', * 'categorie', 'bank_account', 'bank_account', 'adherent', 'user', * 'commande', 'commande_fournisseur', 'expedition', 'intervention', 'survey', diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index b32dd7ed07e..534a89812f6 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -190,6 +190,7 @@ 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 @@ -197,6 +198,7 @@ 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 +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. EMailTextInvoiceValidated=Invoice %s has been validated. diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 1e73b31d502..0182d227963 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3261,7 +3261,7 @@ class Product extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Return nb of units or proposals in which product is included + * 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 @@ -3313,7 +3313,7 @@ class Product extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Return nb of units or proposals in which product is included + * 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 @@ -3365,7 +3365,7 @@ class Product extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Return nb of units or orders in which product is included + * Return nb of units in orders 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 @@ -3416,7 +3416,7 @@ class Product extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Return nb of units or orders in which product is included + * Return nb of units in orders 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 @@ -3467,7 +3467,7 @@ class Product extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Return nb of units or orders in which product is included + * Return nb of units in orders 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 @@ -3519,6 +3519,59 @@ class Product extends CommonObject return $this->_get_stats($sql, $mode, $year); } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return nb of units in orders 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 int $filteronproducttype 0=To filter on product only, 1=To filter on services only + * @param int $year Year (0=last 12 month) + * @param string $morefilter More sql filters + * @return array <0 if KO, result[month]=array(valuex,valuey) where month is 0 to 11 + */ + public function get_nb_mos($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter = '') + { + // phpcs:enable + global $conf, $user; + + $sql = "SELECT sum(c.qty), date_format(c.date_valid, '%Y%m')"; + if ($mode == 'bynumber') { + $sql .= ", count(DISTINCT c.rowid)"; + } + $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid"; + if ($filteronproducttype >= 0) { + $sql .= ", ".MAIN_DB_PREFIX."product as p"; + } + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } + + $sql .= " WHERE c.entity IN (".getEntity('mo').")"; + $sql .= " AND c.status > 0"; + + if ($this->id > 0) { + $sql .= " AND c.fk_product =".$this->id; + } else { + $sql .= " AND c.fk_product > 0"; + } + if ($filteronproducttype >= 0) { + $sql .= " AND p.rowid = c.fk_product AND p.fk_product_type =".$filteronproducttype; + } + + if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($socid > 0) { + $sql .= " AND c.fk_soc = ".$socid; + } + $sql .= $morefilter; + $sql .= " GROUP BY date_format(c.date_valid,'%Y%m')"; + $sql .= " ORDER BY date_format(c.date_valid,'%Y%m') DESC"; + + return $this->_get_stats($sql, $mode, $year); + } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Link a product/service to a parent product/service diff --git a/htdocs/product/stats/card.php b/htdocs/product/stats/card.php index c35d8401a8a..be244e32783 100644 --- a/htdocs/product/stats/card.php +++ b/htdocs/product/stats/card.php @@ -299,6 +299,12 @@ if ($result || empty($id)) 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsContracts") : $langs->transnoentitiesnoconv("NumberOfContracts"))); } + if ($conf->mrp->enabled) { + $graphfiles['mrp'] = array('modulepart'=>'productstats_mrp', + 'file' => $object->id.'/mos12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year ? '_year'.$search_year : '').'.png', + 'label' => ($mode == 'byunit' ? $langs->transnoentitiesnoconv("NumberOfUnitsMos") : $langs->transnoentitiesnoconv("NumberOfMos"))); + } + $px = new DolGraph(); if (!$error && count($graphfiles) > 0) @@ -338,6 +344,7 @@ if ($result || empty($id)) if ($key == 'invoicessuppliers') $graph_data = $object->get_nb_achat($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); if ($key == 'orderssuppliers') $graph_data = $object->get_nb_ordersupplier($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); if ($key == 'contracts') $graph_data = $object->get_nb_contract($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); + if ($key == 'mrp') $graph_data = $object->get_nb_mos($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters); // TODO Save cachefile $graphfiles[$key]['file'] } @@ -384,6 +391,7 @@ if ($result || empty($id)) if ($graphfiles == 'proposals_suppliers' && !$user->rights->supplier_proposal->lire) continue; if ($graphfiles == 'invoices_suppliers' && !$user->rights->fournisseur->facture->lire) continue; if ($graphfiles == 'orders_suppliers' && !$user->rights->fournisseur->commande->lire) continue; + if ($graphfiles == 'mrp' && empty($user->rights->mrp->mo->read)) continue; if ($i % 2 == 0) @@ -412,7 +420,7 @@ if ($result || empty($id)) // Label print ''; print $graphfiles[$key]['label']; - print ' ('.$graphfiles[$key]['total'].')'; + print ' ('.$graphfiles[$key]['total'].')'; print ''.$linktoregenerate.''; print ''; // Image