From 6ff002405ef524d16adc8bf73cd39716917be281 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 7 Aug 2022 19:37:15 +0200 Subject: [PATCH 1/4] NEW manage virtual stock at future date --- htdocs/product/class/api_products.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 2566ca24919..e34b270562e 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -253,7 +253,7 @@ class Products extends DolibarrApi if (!$ids_only) { $product_static = new Product($this->db); if ($product_static->fetch($obj->rowid)) { - if ($includestockdata && DolibarrApiAccess::$user->rights->stock->lire) { + if (!empty($includestockdata) && DolibarrApiAccess::$user->rights->stock->lire) { $product_static->load_stock(); if (is_array($product_static->stock_warehouse)) { @@ -1644,10 +1644,10 @@ class Products extends DolibarrApi $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id); $combinations[$key] = $this->_cleanObjectDatas($combinations[$key]); - if ($includestock==1 && DolibarrApiAccess::$user->rights->stock->lire) { + if (!empty($includestock) && DolibarrApiAccess::$user->rights->stock->lire) { $productModel = new Product($this->db); $productModel->fetch((int) $combination->fk_product_child); - $productModel->load_stock(); + $productModel->load_stock($includestock); $combinations[$key]->stock_warehouse = $this->_cleanObjectDatas($productModel)->stock_warehouse; } } @@ -2040,8 +2040,8 @@ class Products extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if ($includestockdata && DolibarrApiAccess::$user->rights->stock->lire) { - $this->product->load_stock(); + if (!empty($includestockdata) && DolibarrApiAccess::$user->rights->stock->lire) { + $this->product->load_stock($includestockdata); if (is_array($this->product->stock_warehouse)) { foreach ($this->product->stock_warehouse as $keytmp => $valtmp) { From e55b45cdc8f1691b3d9ee82282163ed2c4f58849 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 7 Aug 2022 19:52:06 +0200 Subject: [PATCH 2/4] Update stockatdate.php --- htdocs/product/stock/stockatdate.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/htdocs/product/stock/stockatdate.php b/htdocs/product/stock/stockatdate.php index d4f1bbf4861..ef774081017 100644 --- a/htdocs/product/stock/stockatdate.php +++ b/htdocs/product/stock/stockatdate.php @@ -518,13 +518,9 @@ while ($i < ($limit ? min($num, $limit) : $num)) { } if ($mode == 'future') { - $prod->load_stock('warehouseopen, warehouseinternal', 0); // This call also ->load_virtual_stock() - - //$result = $prod->load_stats_reception(0, '4'); - //print $prod->stats_commande_fournisseur['qty'].'
'."\n"; - //print $prod->stats_reception['qty']; - - $stock = ''.$langs->trans("FeatureNotYetAvailable").''; + $prod->load_stock('warehouseopen, warehouseinternal', 0, $dateendofday); + $stock = $prod->stock_theorique; + $prod->load_stock('warehouseopen, warehouseinternal', 0); $virtualstock = $prod->stock_theorique; } else { if ($fk_warehouse > 0) { From 07f6ae34dcba035ffdbfd344557565ef690ca808 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 7 Aug 2022 17:52:32 +0000 Subject: [PATCH 3/4] Fixing style errors. --- htdocs/product/stock/stockatdate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/stockatdate.php b/htdocs/product/stock/stockatdate.php index ef774081017..82d818af2c9 100644 --- a/htdocs/product/stock/stockatdate.php +++ b/htdocs/product/stock/stockatdate.php @@ -518,7 +518,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) { } if ($mode == 'future') { - $prod->load_stock('warehouseopen, warehouseinternal', 0, $dateendofday); + $prod->load_stock('warehouseopen, warehouseinternal', 0, $dateendofday); $stock = $prod->stock_theorique; $prod->load_stock('warehouseopen, warehouseinternal', 0); $virtualstock = $prod->stock_theorique; From fcff96d43f85a5edd52fe7fbb108838700214782 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sun, 7 Aug 2022 20:00:25 +0200 Subject: [PATCH 4/4] Update product.class.php --- htdocs/product/class/product.class.php | 56 ++++++++++++++++---------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 6c249e6b3bd..f2611e80000 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3038,12 +3038,13 @@ class Product extends CommonObject /** * Charge tableau des stats commande fournisseur pour le produit/service * - * @param int $socid Id societe pour filtrer sur une societe - * @param string $filtrestatut Id des statuts pour filtrer sur des statuts - * @param int $forVirtualStock Ignore rights filter for virtual stock calculation. - * @return int Array of stats in $this->stats_commande_fournisseur, <0 if ko or >0 if ok + * @param int $socid Id societe pour filtrer sur une societe + * @param string $filtrestatut Id des statuts pour filtrer sur des statuts + * @param int $forVirtualStock Ignore rights filter for virtual stock calculation. + * @param int $dateofvirtualstock Date of virtual stock + * @return int Array of stats in $this->stats_commande_fournisseur, <0 if ko or >0 if ok */ - public function load_stats_commande_fournisseur($socid = 0, $filtrestatut = '', $forVirtualStock = 0) + public function load_stats_commande_fournisseur($socid = 0, $filtrestatut = '', $forVirtualStock = 0, $dateofvirtualstock = null) { // phpcs:enable global $conf, $user, $hookmanager, $action; @@ -3069,6 +3070,9 @@ class Product extends CommonObject if ($filtrestatut != '') { $sql .= " AND c.fk_statut in (".$this->db->sanitize($filtrestatut).")"; // Peut valoir 0 } + if (!empty($dateofvirtualstock)) { + $sql .= " AND c.date_livraison <= '".$this->db->idate($dateofvirtualstock)."'"; + } $result = $this->db->query($sql); if ($result) { @@ -3181,12 +3185,13 @@ class Product extends CommonObject /** * Charge tableau des stats réception fournisseur pour le produit/service * - * @param int $socid Id societe pour filtrer sur une societe - * @param string $filtrestatut Id statut pour filtrer sur un statut - * @param int $forVirtualStock Ignore rights filter for virtual stock calculation. + * @param int $socid Id societe pour filtrer sur une societe + * @param string $filtrestatut Id statut pour filtrer sur un statut + * @param int $forVirtualStock Ignore rights filter for virtual stock calculation. + * @param int $dateofvirtualstock Date of virtual stock * @return int Array of stats in $this->stats_reception, <0 if ko or >0 if ok */ - public function load_stats_reception($socid = 0, $filtrestatut = '', $forVirtualStock = 0) + public function load_stats_reception($socid = 0, $filtrestatut = '', $forVirtualStock = 0, $dateofvirtualstock = null) { // phpcs:enable global $conf, $user, $hookmanager, $action; @@ -3212,6 +3217,9 @@ class Product extends CommonObject if ($filtrestatut <> '') { $sql .= " AND cf.fk_statut IN (".$this->db->sanitize($filtrestatut).")"; } + if (!empty($dateofvirtualstock)) { + $sql .= " AND fd.datec <= '".$this->db->idate($dateofvirtualstock)."'"; + } $result = $this->db->query($sql); if ($result) { @@ -3238,12 +3246,13 @@ class Product extends CommonObject /** * Charge tableau des stats production pour le produit/service * - * @param int $socid Id societe pour filtrer sur une societe - * @param string $filtrestatut Id statut pour filtrer sur un statut - * @param int $forVirtualStock Ignore rights filter for virtual stock calculation. + * @param int $socid Id societe pour filtrer sur une societe + * @param string $filtrestatut Id statut pour filtrer sur un statut + * @param int $forVirtualStock Ignore rights filter for virtual stock calculation. + * @param int $dateofvirtualstock Date of virtual stock * @return integer Array of stats in $this->stats_mrptoproduce (nb=nb of order, qty=qty ordered), <0 if ko or >0 if ok */ - public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirtualStock = 0) + public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirtualStock = 0, $dateofvirtualstock = null) { // phpcs:enable global $conf, $user, $hookmanager, $action; @@ -3268,6 +3277,9 @@ class Product extends CommonObject if ($filtrestatut <> '') { $sql .= " AND m.status IN (".$this->db->sanitize($filtrestatut).")"; } + if (!empty($dateofvirtualstock)) { + $sql .= " AND m.date_valid <= '".$this->db->idate($dateofvirtualstock)."'"; // better date to code ? end of production ? + } $sql .= " GROUP BY role"; $this->stats_mrptoconsume['customers'] = 0; @@ -5346,10 +5358,11 @@ class Product extends CommonObject * @param string $option '' = Load all stock info, also from closed and internal warehouses, 'nobatch', 'novirtual' * You can also filter on 'warehouseclosed', 'warehouseopen', 'warehouseinternal' * @param int $includedraftpoforvirtual Include draft status of PO for virtual stock calculation + * @param int $dateofvirtualstock Date of virtual stock * @return int < 0 if KO, > 0 if OK * @see load_virtual_stock(), loadBatchInfo() */ - public function load_stock($option = '', $includedraftpoforvirtual = null) + public function load_stock($option = '', $includedraftpoforvirtual = null, $dateofvirtualstock = null) { // phpcs:enable global $conf; @@ -5407,7 +5420,7 @@ class Product extends CommonObject $this->db->free($result); if (!preg_match('/novirtual/', $option)) { - $this->load_virtual_stock($includedraftpoforvirtual); // This also load all arrays stats_xxx... + $this->load_virtual_stock($includedraftpoforvirtual, $dateofvirtualstock); // This also load all arrays stats_xxx... } return 1; @@ -5424,10 +5437,11 @@ class Product extends CommonObject * This function need a lot of load. If you use it on list, use a cache to execute it one for each product id. * * @param int $includedraftpoforvirtual Include draft status and not yet approved Purchase Orders for virtual stock calculation + * @param int $dateofvirtualstock Date of virtual stock * @return int < 0 if KO, > 0 if OK * @see load_stock(), loadBatchInfo() */ - public function load_virtual_stock($includedraftpoforvirtual = null) + public function load_virtual_stock($includedraftpoforvirtual = null, $dateofvirtualstock = null) { // phpcs:enable global $conf, $hookmanager, $action; @@ -5466,7 +5480,7 @@ class Product extends CommonObject if (isset($includedraftpoforvirtual)) { $filterStatus = '0,1,2,'.$filterStatus; // 1,2 may have already been inside $filterStatus but it is better to have twice than missing $filterStatus does not include them } - $result = $this->load_stats_commande_fournisseur(0, $filterStatus, 1); + $result = $this->load_stats_commande_fournisseur(0, $filterStatus, 1, $dateofvirtualstock); if ($result < 0) { dol_print_error($this->db, $this->error); } @@ -5478,7 +5492,7 @@ class Product extends CommonObject if (isset($includedraftpoforvirtual)) { $filterStatus = '0,'.$filterStatus; } - $result = $this->load_stats_reception(0, $filterStatus, 1); + $result = $this->load_stats_reception(0, $filterStatus, 1, $dateofvirtualstock); if ($result < 0) { dol_print_error($this->db, $this->error); } @@ -5490,14 +5504,14 @@ class Product extends CommonObject if (isset($includedraftpoforvirtual)) { $filterStatus = '0,'.$filterStatus; } - $result = $this->load_stats_reception(0, $filterStatus, 1); // Use same tables than when module reception is not used. + $result = $this->load_stats_reception(0, $filterStatus, 1, $dateofvirtualstock); // Use same tables than when module reception is not used. if ($result < 0) { dol_print_error($this->db, $this->error); } $stock_reception_fournisseur = $this->stats_reception['qty']; } if (!empty($conf->mrp->enabled)) { - $result = $this->load_stats_inproduction(0, '1,2', 1); + $result = $this->load_stats_inproduction(0, '1,2', 1, $dateofvirtualstock); if ($result < 0) { dol_print_error($this->db, $this->error); } @@ -6196,8 +6210,6 @@ class Product extends CommonObject } } - - /** * Class to manage products or services. * Do not use 'Service' as class name since it is already used by APIs.