diff --git a/ChangeLogTechPap.md b/ChangeLogTechPap.md index 38805800802cb..bd0f50cac9b8e 100644 --- a/ChangeLogTechPap.md +++ b/ChangeLogTechPap.md @@ -1,3 +1,4 @@ +- FIX : DA024318 - Backport PR 27668 : gestion de la donnée "stock virtuel par entrepôt" sur l'écran de réapprovisionnement - *12/02/2024* - FIX : DA024269 - Multilangs ne fonctionne pas avec les pdfs propal et facture [Ce dev devrait être ajouté au standard en v17, ainsi, il sera à supprimer lors de la MDV : PR 27159] - *19/12/2023* - FIX : DA023477 - Liens hypertext ne fonctionnent pas [Ce dev a été ajouté au standard en develop (pour V19), ainsi, il sera à supprimer lors de la MDV] - v17 - *18/07/2023* - FIX : DA023556 - Date de création non-fonctionnelle pour les numéros de lot/série [Ce dev a été ajouté au standard en develop (pour V19), ainsi, il sera à supprimer lors de la MDV] - v17 - *18/07/2023* diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 9c1f14e96b46e..7331b62830e00 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3350,9 +3350,10 @@ public function load_stats_reception($socid = 0, $filtrestatut = '', $forVirtual * @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 + * @param int $warehouseid Filter by a warehouse (BACKPORT STANDARD PR27668) * @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, $dateofvirtualstock = null) + public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirtualStock = 0, $dateofvirtualstock = null, $warehouseid = 0) { // phpcs:enable global $conf, $user, $hookmanager, $action; @@ -3380,16 +3381,27 @@ public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirt if (!empty($dateofvirtualstock)) { $sql .= " AND m.date_valid <= '".$this->db->idate($dateofvirtualstock)."'"; // better date to code ? end of production ? } + /** DEB : BACKPORT STANDARD PR27668 **/ + if (!empty($warehouseid)) { + $sql.= " AND m.fk_warehouse = ".((int) $warehouseid); + } + /** FIN : BACKPORT STANDARD PR27668 **/ $sql .= " GROUP BY role"; - $this->stats_mrptoconsume['customers'] = 0; - $this->stats_mrptoconsume['nb'] = 0; - $this->stats_mrptoconsume['rows'] = 0; - $this->stats_mrptoconsume['qty'] = 0; - $this->stats_mrptoproduce['customers'] = 0; - $this->stats_mrptoproduce['nb'] = 0; - $this->stats_mrptoproduce['rows'] = 0; - $this->stats_mrptoproduce['qty'] = 0; + /** DEB : BACKPORT STANDARD PR27668 **/ + if ($warehouseid) { + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] = 0; + } else { + $this->stats_mrptoconsume['customers'] = 0; + $this->stats_mrptoconsume['nb'] = 0; + $this->stats_mrptoconsume['rows'] = 0; + $this->stats_mrptoconsume['qty'] = 0; + $this->stats_mrptoproduce['customers'] = 0; + $this->stats_mrptoproduce['nb'] = 0; + $this->stats_mrptoproduce['rows'] = 0; + $this->stats_mrptoproduce['qty'] = 0; + } + /** FIN : BACKPORT STANDARD PR27668 **/ $result = $this->db->query($sql); if ($result) { @@ -3407,26 +3419,46 @@ public function load_stats_inproduction($socid = 0, $filtrestatut = '', $forVirt $this->stats_mrptoconsume['qty'] -= ($obj->qty ? $obj->qty : 0); } if ($obj->role == 'toproduce') { - $this->stats_mrptoproduce['customers'] += $obj->nb_customers; - $this->stats_mrptoproduce['nb'] += $obj->nb; - $this->stats_mrptoproduce['rows'] += $obj->nb_rows; - $this->stats_mrptoproduce['qty'] += ($obj->qty ? $obj->qty : 0); + /** DEB : BACKPORT STANDARD PR27668 **/ + if ($warehouseid) { + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] += ($obj->qty ? $obj->qty : 0); + } else { + $this->stats_mrptoproduce['customers'] += $obj->nb_customers; + $this->stats_mrptoproduce['nb'] += $obj->nb; + $this->stats_mrptoproduce['rows'] += $obj->nb_rows; + $this->stats_mrptoproduce['qty'] += ($obj->qty ? $obj->qty : 0); + } + /** FIN : BACKPORT STANDARD PR27668 **/ } if ($obj->role == 'produced') { //$this->stats_mrptoproduce['customers'] += $obj->nb_customers; //$this->stats_mrptoproduce['nb'] += $obj->nb; //$this->stats_mrptoproduce['rows'] += $obj->nb_rows; - $this->stats_mrptoproduce['qty'] -= ($obj->qty ? $obj->qty : 0); + /** DEB : BACKPORT STANDARD PR27668 **/ + if ($warehouseid) { + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] -= ($obj->qty ? $obj->qty : 0); + } else { + $this->stats_mrptoproduce['qty'] -= ($obj->qty ? $obj->qty : 0); + } + /** FIN : BACKPORT STANDARD PR27668 **/ } } // Clean data - if ($this->stats_mrptoconsume['qty'] < 0) { - $this->stats_mrptoconsume['qty'] = 0; - } - if ($this->stats_mrptoproduce['qty'] < 0) { - $this->stats_mrptoproduce['qty'] = 0; + /** DEB : BACKPORT STANDARD PR27668 **/ + if ($warehouseid) { + if ($this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] < 0) { + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] = 0; + } + } else { + if ($this->stats_mrptoconsume['qty'] < 0) { + $this->stats_mrptoconsume['qty'] = 0; + } + if ($this->stats_mrptoproduce['qty'] < 0) { + $this->stats_mrptoproduce['qty'] = 0; + } } + /** FIN : BACKPORT STANDARD PR27668 **/ $parameters = array('socid' => $socid, 'filtrestatut' => $filtrestatut, 'forVirtualStock' => $forVirtualStock); $reshook = $hookmanager->executeHooks('loadStatsInProduction', $parameters, $this, $action); @@ -5650,6 +5682,26 @@ public function load_virtual_stock($includedraftpoforvirtual = null, $dateofvirt $this->stock_theorique = $hookmanager->resArray['stock_theorique']; } + /** DEB : BACKPORT STANDARD PR27668 **/ + //Virtual Stock by Warehouse + if (!empty($this->stock_warehouse) && getDolGlobalString('STOCK_ALLOW_VIRTUAL_STOCK_PER_WAREHOUSE')) { + foreach ($this->stock_warehouse as $warehouseid => $stockwarehouse) { + if (isModEnabled('mrp')) { + $result = $this->load_stats_inproduction(0, '1,2', 1, $dateofvirtualstock, $warehouseid); + if ($result < 0) { + dol_print_error($this->db, $this->error); + } + } + + if ($this->fk_default_warehouse == $warehouseid) { + $this->stock_warehouse[$warehouseid]->virtual = $this->stock_warehouse[$warehouseid]->real + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] + $this->stats_commande_fournisseur['qty'] - ($this->stats_commande['qty'] + $this->stats_mrptoconsume['qty']); + } else { + $this->stock_warehouse[$warehouseid]->virtual = $this->stock_warehouse[$warehouseid]->real + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty']; + } + } + } + /** FIN : BACKPORT STANDARD PR27668 **/ + return 1; } diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index a3cac8adbc888..a9e64ecf0922c 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -826,7 +826,11 @@ if ($usevirtualstock) { // If option to increase/decrease is not on an object validation, virtual stock may differs from physical stock. $stock = $prod->stock_theorique; - //TODO $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->; + /** DEB : BACKPORT STANDARD PR27668 **/ + if (getDolGlobalString('STOCK_ALLOW_VIRTUAL_STOCK_PER_WAREHOUSE')) { + $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->virtual; + } + /** FIN : BACKPORT STANDARD PR27668 **/ } else { $stock = $prod->stock_reel; $stockwarehouse = $prod->stock_warehouse[$fk_entrepot]->real;