From 7e7638792e71a8be1fd8a396c18ea719b3cd37b7 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Thu, 17 Feb 2022 16:20:35 +0100 Subject: [PATCH 01/19] NEW : Added of the field "include_sub_warehouse" in the table "llx_inventory" --- htdocs/install/mysql/migration/15.0.0-16.0.0.sql | 2 ++ htdocs/install/mysql/tables/llx_inventory-stock.sql | 3 ++- htdocs/product/stock/tpl/extrafields_add.tpl.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index b78e53bd287..56d5410a898 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -237,4 +237,6 @@ ALTER TABLE llx_advtargetemailing RENAME TO llx_mailing_advtarget; ALTER TABLE llx_mailing ADD UNIQUE uk_mailing(titre, entity); +ALTER TABLE llx_inventory ADD COLUMN include_sub_warehouse boolean NOT NULL DEFAULT FALSE; + diff --git a/htdocs/install/mysql/tables/llx_inventory-stock.sql b/htdocs/install/mysql/tables/llx_inventory-stock.sql index c25ccb9767b..4053aa971b1 100644 --- a/htdocs/install/mysql/tables/llx_inventory-stock.sql +++ b/htdocs/install/mysql/tables/llx_inventory-stock.sql @@ -30,7 +30,8 @@ CREATE TABLE llx_inventory fk_warehouse integer DEFAULT NULL, fk_product integer DEFAULT NULL, status integer DEFAULT 0, - title varchar(255) NOT NULL, + title varchar(255) NOT NULL, + include_sub_warehouse boolean NOT NULL DEFAULT FALSE, date_inventory datetime DEFAULT NULL, date_validation datetime DEFAULT NULL, import_key varchar(14) -- import key diff --git a/htdocs/product/stock/tpl/extrafields_add.tpl.php b/htdocs/product/stock/tpl/extrafields_add.tpl.php index 62921f0a6e0..4dcddcad672 100644 --- a/htdocs/product/stock/tpl/extrafields_add.tpl.php +++ b/htdocs/product/stock/tpl/extrafields_add.tpl.php @@ -37,13 +37,13 @@ if (empty($conf) || !is_object($conf)) { // Other attributes if (!isset($parameters)) $parameters = array(); - $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $movement, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; if (empty($reshook)) { $params = array(); if (isset($tpl_context)) $params['tpl_context'] = $tpl_context; $params['cols'] = $parameters['colspanvalue']; + var_dump($movement); print $movement->showOptionals($extrafields, 'create', $params); } From 16f6aaf1c8f24dcb22dbe90dd81db50d682d61a5 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Thu, 17 Feb 2022 17:24:04 +0100 Subject: [PATCH 02/19] NEW : Add new field into $fields array + Creation of the function getChildWarehouse() --- .../inventory/class/inventory.class.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 92061972e60..58ec8e05ca1 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -101,6 +101,7 @@ class Inventory extends CommonObject 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,), 'title' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>25, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax200'), 'fk_warehouse' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Warehouse', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'index'=>1, 'help'=>'InventoryForASpecificWarehouse', 'picto'=>'stock', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'), + 'include_sub_warehouse' => array('type'=>'boolean', 'label'=>'IncludeSubWarehouse', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'index'=>0, 'position'=>31), 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'visible'=>1, 'enabled'=>1, 'position'=>32, 'index'=>1, 'help'=>'InventoryForASpecificProduct', 'picto'=>'product', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'), 'date_inventory' => array('type'=>'date', 'label'=>'DateValue', 'visible'=>1, 'enabled'=>'$conf->global->STOCK_INVENTORY_ADD_A_VALUE_DATE', 'position'=>35), // This date is not used so disabled by default. 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500), @@ -691,6 +692,30 @@ class Inventory extends CommonObject $this->initAsSpecimenCommon(); $this->title = ''; } + + + /** + * Return the child warehouse of the current one + * + * @return int | array <0 if KO, >0 if OK + */ + public function getchildWarehouse() + { + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'entrepot'; + $sql.= ' WHERE fk_parent='.$this->id; + $sql.= ' ORDER BY rowid'; + $resql = $this->db->query($sql); + if($resql && $this->db->num_rows($resql)>0){ + $TChildWarehouse = array(); + while ($obj = $this->db->fetch_object($resql)){ + $TChildWarehouse[] = $obj->rowid; + } + return $TChildWarehouse; + } else { + return -1; + } + } + } /** From c60047b3c8ced7b79a6069fb50d5890181c92502 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Mon, 21 Feb 2022 17:18:05 +0100 Subject: [PATCH 03/19] NEW : Add recurring behaviour --- .../install/mysql/migration/15.0.0-16.0.0.sql | 2 +- .../mysql/tables/llx_inventory-stock.sql | 2 +- htdocs/langs/en_US/stocks.lang | 3 ++- htdocs/langs/fr_FR/stocks.lang | 1 + .../inventory/class/inventory.class.php | 18 +++++++++++++----- .../product/stock/tpl/extrafields_add.tpl.php | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index 56d5410a898..3aa6353c250 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -237,6 +237,6 @@ ALTER TABLE llx_advtargetemailing RENAME TO llx_mailing_advtarget; ALTER TABLE llx_mailing ADD UNIQUE uk_mailing(titre, entity); -ALTER TABLE llx_inventory ADD COLUMN include_sub_warehouse boolean NOT NULL DEFAULT FALSE; +ALTER TABLE llx_inventory ADD COLUMN include_sub_warehouse boolean DEFAULT FALSE; diff --git a/htdocs/install/mysql/tables/llx_inventory-stock.sql b/htdocs/install/mysql/tables/llx_inventory-stock.sql index 4053aa971b1..c6ac552de60 100644 --- a/htdocs/install/mysql/tables/llx_inventory-stock.sql +++ b/htdocs/install/mysql/tables/llx_inventory-stock.sql @@ -31,7 +31,7 @@ CREATE TABLE llx_inventory fk_product integer DEFAULT NULL, status integer DEFAULT 0, title varchar(255) NOT NULL, - include_sub_warehouse boolean NOT NULL DEFAULT FALSE, + include_sub_warehouse boolean DEFAULT FALSE, date_inventory datetime DEFAULT NULL, date_validation datetime DEFAULT NULL, import_key varchar(14) -- import key diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index ebd67df79c9..5d6ad811983 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -270,4 +270,5 @@ ErrorOnElementsInventory=Operation canceled for the following reason: ErrorCantFindCodeInInventory=Can't find the following code in inventory QtyWasAddedToTheScannedBarcode=Success !! The quantity was added to all the requested barcode. You can close the Scanner tool. StockChangeDisabled=Change on stock disabled -NoWarehouseDefinedForTerminal=No warehouse defined for terminal \ No newline at end of file +NoWarehouseDefinedForTerminal=No warehouse defined for terminal +IncludeSubWarehouse=Include sub-warehouse ? \ No newline at end of file diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index a907598ff61..44da826b36b 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -271,3 +271,4 @@ ErrorCantFindCodeInInventory=Impossible de trouver le code suivant dans l'invent QtyWasAddedToTheScannedBarcode=Succès !! La quantité a été ajoutée à tous les codes-barres demandés. Vous pouvez fermer l'outil Scanner. StockChangeDisabled=Changement sur stock désactivé NoWarehouseDefinedForTerminal=Aucun entrepôt défini pour le terminal +IncludeSubWarehouse=Inclure les sous-entrepôts ? \ No newline at end of file diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 58ec8e05ca1..b5f49e01076 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -290,8 +290,15 @@ class Inventory extends CommonObject $sql .= " AND ps.fk_product = ".((int) $this->fk_product); } if ($this->fk_warehouse > 0) { - $sql .= " AND ps.fk_entrepot = ".((int) $this->fk_warehouse); + $sql .= " AND (ps.fk_entrepot = ".((int) $this->fk_warehouse); } + if($this->include_sub_warehouse>0 && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE){ + $this->getchildWarehouse($this->fk_warehouse, $TChildWarehouses); + foreach ($TChildWarehouses as $childWarehouse){ + $sql .= " OR ps.fk_entrepot = ".((int) $childWarehouse); + } + } + $sql .= ')'; $inventoryline = new InventoryLine($this->db); @@ -699,18 +706,19 @@ class Inventory extends CommonObject * * @return int | array <0 if KO, >0 if OK */ - public function getchildWarehouse() + public function getchildWarehouse($id, &$TChildWarehouse) { $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'entrepot'; - $sql.= ' WHERE fk_parent='.$this->id; + $sql.= ' WHERE fk_parent='.$id; $sql.= ' ORDER BY rowid'; $resql = $this->db->query($sql); if($resql && $this->db->num_rows($resql)>0){ - $TChildWarehouse = array(); while ($obj = $this->db->fetch_object($resql)){ + $TChildWarehouse[] = $obj->rowid; + $this->getchildWarehouse($obj->rowid, $TChildWarehouse); } - return $TChildWarehouse; + return 1; } else { return -1; } diff --git a/htdocs/product/stock/tpl/extrafields_add.tpl.php b/htdocs/product/stock/tpl/extrafields_add.tpl.php index 4dcddcad672..d3c5f0e362c 100644 --- a/htdocs/product/stock/tpl/extrafields_add.tpl.php +++ b/htdocs/product/stock/tpl/extrafields_add.tpl.php @@ -43,7 +43,7 @@ if (empty($reshook)) { $params = array(); if (isset($tpl_context)) $params['tpl_context'] = $tpl_context; $params['cols'] = $parameters['colspanvalue']; - var_dump($movement); + print $movement->showOptionals($extrafields, 'create', $params); } From ab8cd6aa062d138187571211ed49a71e5d3385be Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Tue, 22 Feb 2022 14:50:25 +0100 Subject: [PATCH 04/19] FIX : Global conf --- htdocs/product/inventory/class/inventory.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index b5f49e01076..a15aadd243e 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -101,7 +101,7 @@ class Inventory extends CommonObject 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,), 'title' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>25, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax200'), 'fk_warehouse' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Warehouse', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'index'=>1, 'help'=>'InventoryForASpecificWarehouse', 'picto'=>'stock', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'), - 'include_sub_warehouse' => array('type'=>'boolean', 'label'=>'IncludeSubWarehouse', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'index'=>0, 'position'=>31), + 'include_sub_warehouse' => array('type'=>'boolean', 'label'=>'IncludeSubWarehouse', 'enabled'=>'$conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE', 'visible'=>1, 'notnull'=>0, 'index'=>0, 'position'=>31), 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'visible'=>1, 'enabled'=>1, 'position'=>32, 'index'=>1, 'help'=>'InventoryForASpecificProduct', 'picto'=>'product', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'), 'date_inventory' => array('type'=>'date', 'label'=>'DateValue', 'visible'=>1, 'enabled'=>'$conf->global->STOCK_INVENTORY_ADD_A_VALUE_DATE', 'position'=>35), // This date is not used so disabled by default. 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500), From e74e0ffada816a5843b329068efc85f1baf85106 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 22 Feb 2022 14:38:25 +0000 Subject: [PATCH 05/19] Fixing style errors. --- htdocs/product/inventory/class/inventory.class.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index a15aadd243e..4836f8c810a 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -292,9 +292,9 @@ class Inventory extends CommonObject if ($this->fk_warehouse > 0) { $sql .= " AND (ps.fk_entrepot = ".((int) $this->fk_warehouse); } - if($this->include_sub_warehouse>0 && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE){ + if ($this->include_sub_warehouse>0 && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE) { $this->getchildWarehouse($this->fk_warehouse, $TChildWarehouses); - foreach ($TChildWarehouses as $childWarehouse){ + foreach ($TChildWarehouses as $childWarehouse) { $sql .= " OR ps.fk_entrepot = ".((int) $childWarehouse); } } @@ -712,9 +712,8 @@ class Inventory extends CommonObject $sql.= ' WHERE fk_parent='.$id; $sql.= ' ORDER BY rowid'; $resql = $this->db->query($sql); - if($resql && $this->db->num_rows($resql)>0){ - while ($obj = $this->db->fetch_object($resql)){ - + if ($resql && $this->db->num_rows($resql)>0) { + while ($obj = $this->db->fetch_object($resql)) { $TChildWarehouse[] = $obj->rowid; $this->getchildWarehouse($obj->rowid, $TChildWarehouse); } @@ -723,7 +722,6 @@ class Inventory extends CommonObject return -1; } } - } /** From 62bf1e4273cd82ad21ec3d32992eaf4a5740e870 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Tue, 22 Feb 2022 15:54:45 +0100 Subject: [PATCH 06/19] FIX : Stickler errors --- htdocs/product/inventory/class/inventory.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index a15aadd243e..bc095c9c459 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -700,11 +700,11 @@ class Inventory extends CommonObject $this->title = ''; } - /** * Return the child warehouse of the current one - * - * @return int | array <0 if KO, >0 if OK + * @param int $id Id of warehouse + * @param $TChildWarehouse child warehouses + * @return int <0 if KO, >0 if OK */ public function getchildWarehouse($id, &$TChildWarehouse) { From 6807c53a0fe2acdc08444ebc5c7ca592f06aa6ec Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Tue, 22 Feb 2022 15:56:55 +0100 Subject: [PATCH 07/19] FIX : Travis errors --- htdocs/product/inventory/class/inventory.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index bc095c9c459..82eabc120fa 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -709,7 +709,7 @@ class Inventory extends CommonObject public function getchildWarehouse($id, &$TChildWarehouse) { $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'entrepot'; - $sql.= ' WHERE fk_parent='.$id; + $sql.= ' WHERE fk_parent='.(int) $id; $sql.= ' ORDER BY rowid'; $resql = $this->db->query($sql); if($resql && $this->db->num_rows($resql)>0){ From 02917f28df57f592c64f8213b2859d3a55cf833c Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Thu, 24 Feb 2022 10:41:46 +0100 Subject: [PATCH 08/19] FIX : PR Returns --- htdocs/product/inventory/class/inventory.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 675446dd2b6..97c11a0370d 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -294,9 +294,7 @@ class Inventory extends CommonObject } if ($this->include_sub_warehouse>0 && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE) { $this->getchildWarehouse($this->fk_warehouse, $TChildWarehouses); - foreach ($TChildWarehouses as $childWarehouse) { - $sql .= " OR ps.fk_entrepot = ".((int) $childWarehouse); - } + $sql .= " OR ps.fk_entrepot IN (".implode(',', $TChildWarehouses).")"; } $sql .= ')'; From 50028dadeffc73e07f9ec36168888cbd3ed7e259 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Thu, 24 Feb 2022 11:27:14 +0100 Subject: [PATCH 09/19] FIX : Travis returns --- htdocs/product/inventory/class/inventory.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 97c11a0370d..0ad970a7d40 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -294,7 +294,7 @@ class Inventory extends CommonObject } if ($this->include_sub_warehouse>0 && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE) { $this->getchildWarehouse($this->fk_warehouse, $TChildWarehouses); - $sql .= " OR ps.fk_entrepot IN (".implode(',', $TChildWarehouses).")"; + $sql .= " OR ps.fk_entrepot IN (".filter_var(implode(',', $TChildWarehouses),FILTER_SANITIZE_STRING).")"; } $sql .= ')'; From abc450e44ce6409d3031e2b9576694f9ae834faa Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 24 Feb 2022 10:30:48 +0000 Subject: [PATCH 10/19] Fixing style errors. --- htdocs/product/inventory/class/inventory.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 0ad970a7d40..fb2041b6b88 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -294,7 +294,7 @@ class Inventory extends CommonObject } if ($this->include_sub_warehouse>0 && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE) { $this->getchildWarehouse($this->fk_warehouse, $TChildWarehouses); - $sql .= " OR ps.fk_entrepot IN (".filter_var(implode(',', $TChildWarehouses),FILTER_SANITIZE_STRING).")"; + $sql .= " OR ps.fk_entrepot IN (".filter_var(implode(',', $TChildWarehouses), FILTER_SANITIZE_STRING).")"; } $sql .= ')'; From f9c5da4ae27ba7e1714d43bb48ad2175ee679b11 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Thu, 24 Feb 2022 16:49:13 +0100 Subject: [PATCH 11/19] NEW : Added of a popup on validation instead of a database fielld to know if the user wants to include subwarehouse --- htdocs/langs/en_US/stocks.lang | 4 +++- htdocs/product/inventory/card.php | 18 +++++++++++++++++- .../inventory/class/inventory.class.php | 12 ++++++------ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 5d6ad811983..905bd137350 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -271,4 +271,6 @@ ErrorCantFindCodeInInventory=Can't find the following code in inventory QtyWasAddedToTheScannedBarcode=Success !! The quantity was added to all the requested barcode. You can close the Scanner tool. StockChangeDisabled=Change on stock disabled NoWarehouseDefinedForTerminal=No warehouse defined for terminal -IncludeSubWarehouse=Include sub-warehouse ? \ No newline at end of file +ValidateInventory=Inventory validation +IncludeSubWarehouse=Include sub-warehouse ? +IncludeSubWarehouseExplanation=Check this box if you want to include all sub-warehouses of the associated warehouse in the inventory \ No newline at end of file diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index 23473545b11..14a107d3d6a 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -291,6 +291,18 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220); } + + if ($action == 'validate'){ + $form = new Form($db); + $formquestion = ''; + if($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)){ + $formquestion = array( + array('type' => 'checkbox', 'name' => 'include_sub_warehouse', 'label' => $langs->trans("IncludeSubWarehouse"), 'value' => 0, 'size' => '10'), + ); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateInventory'), $langs->trans('IncludeSubWarehouseExplanation'), 'confirm_validate', $formquestion, '', 1); + } + } + // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -414,7 +426,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Validate if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_CANCELED) { if ($permissiontoadd) { - print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; + if($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)){ + print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; + } else { + print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; + } } } diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index fb2041b6b88..8f79a6d8267 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -101,7 +101,6 @@ class Inventory extends CommonObject 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,), 'title' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>25, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax200'), 'fk_warehouse' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Warehouse', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'index'=>1, 'help'=>'InventoryForASpecificWarehouse', 'picto'=>'stock', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'), - 'include_sub_warehouse' => array('type'=>'boolean', 'label'=>'IncludeSubWarehouse', 'enabled'=>'$conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE', 'visible'=>1, 'notnull'=>0, 'index'=>0, 'position'=>31), 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'visible'=>1, 'enabled'=>1, 'position'=>32, 'index'=>1, 'help'=>'InventoryForASpecificProduct', 'picto'=>'product', 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist'=>'tdoverflowmax200'), 'date_inventory' => array('type'=>'date', 'label'=>'DateValue', 'visible'=>1, 'enabled'=>'$conf->global->STOCK_INVENTORY_ADD_A_VALUE_DATE', 'position'=>35), // This date is not used so disabled by default. 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500), @@ -265,6 +264,7 @@ class Inventory extends CommonObject $result = 0; + $this->include_sub_warehouse = GETPOST('include_sub_warehouse'); if ($this->status == self::STATUS_DRAFT) { // Delete inventory $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id); @@ -291,12 +291,12 @@ class Inventory extends CommonObject } if ($this->fk_warehouse > 0) { $sql .= " AND (ps.fk_entrepot = ".((int) $this->fk_warehouse); + if (!empty($this->include_sub_warehouse) && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE) { + $this->getchildWarehouse($this->fk_warehouse, $TChildWarehouses); + $sql .= " OR ps.fk_entrepot IN (".filter_var(implode(',', $TChildWarehouses), FILTER_SANITIZE_STRING).")"; + } + $sql .= ')'; } - if ($this->include_sub_warehouse>0 && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE) { - $this->getchildWarehouse($this->fk_warehouse, $TChildWarehouses); - $sql .= " OR ps.fk_entrepot IN (".filter_var(implode(',', $TChildWarehouses), FILTER_SANITIZE_STRING).")"; - } - $sql .= ')'; $inventoryline = new InventoryLine($this->db); From 168b1c7578552a9b0d2cd87fbf755af2676db9b1 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Thu, 24 Feb 2022 16:51:14 +0100 Subject: [PATCH 12/19] NEW : remove include_subwarehouse form llx_inventory database table --- htdocs/install/mysql/migration/15.0.0-16.0.0.sql | 2 -- htdocs/install/mysql/tables/llx_inventory-stock.sql | 1 - 2 files changed, 3 deletions(-) diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index 2e4c271a691..cbf3c8fadc5 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -237,8 +237,6 @@ ALTER TABLE llx_advtargetemailing RENAME TO llx_mailing_advtarget; ALTER TABLE llx_mailing ADD UNIQUE uk_mailing(titre, entity); -ALTER TABLE llx_inventory ADD COLUMN include_sub_warehouse boolean DEFAULT FALSE; - create table llx_inventory_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, diff --git a/htdocs/install/mysql/tables/llx_inventory-stock.sql b/htdocs/install/mysql/tables/llx_inventory-stock.sql index c6ac552de60..1f38469b300 100644 --- a/htdocs/install/mysql/tables/llx_inventory-stock.sql +++ b/htdocs/install/mysql/tables/llx_inventory-stock.sql @@ -31,7 +31,6 @@ CREATE TABLE llx_inventory fk_product integer DEFAULT NULL, status integer DEFAULT 0, title varchar(255) NOT NULL, - include_sub_warehouse boolean DEFAULT FALSE, date_inventory datetime DEFAULT NULL, date_validation datetime DEFAULT NULL, import_key varchar(14) -- import key From 23cd8bde29fdd0d5e81a01236b296a641476df75 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 24 Feb 2022 15:54:37 +0000 Subject: [PATCH 13/19] Fixing style errors. --- htdocs/product/inventory/card.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index 14a107d3d6a..901a4e2a399 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -292,10 +292,10 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } - if ($action == 'validate'){ + if ($action == 'validate') { $form = new Form($db); $formquestion = ''; - if($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)){ + if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) { $formquestion = array( array('type' => 'checkbox', 'name' => 'include_sub_warehouse', 'label' => $langs->trans("IncludeSubWarehouse"), 'value' => 0, 'size' => '10'), ); @@ -426,7 +426,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Validate if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_CANCELED) { if ($permissiontoadd) { - if($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)){ + if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) { print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; } else { print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; From 43428f622f789f07aead4cb494505bda2f4a86cd Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Thu, 31 Mar 2022 15:28:03 +0200 Subject: [PATCH 14/19] FIX : Add sub warehouse management on inventory.php file --- htdocs/product/inventory/inventory.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 6026e4316e4..ab3c0276051 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -435,6 +435,17 @@ if ($object->id > 0) { $action = 'view'; } + if ($action == 'validate') { + $form = new Form($db); + $formquestion = ''; + if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) { + $formquestion = array( + array('type' => 'checkbox', 'name' => 'include_sub_warehouse', 'label' => $langs->trans("IncludeSubWarehouse"), 'value' => 0, 'size' => '10'), + ); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateInventory'), $langs->trans('IncludeSubWarehouseExplanation'), 'confirm_validate', $formquestion, '', 1); + } + } + // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -541,7 +552,11 @@ if ($object->id > 0) { if (empty($reshook)) { if ($object->status == Inventory::STATUS_DRAFT) { if ($permissiontoadd) { - print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'."\n"; + if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) { + print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; + } else { + print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; + } } else { print ''.$langs->trans('Validate').' ('.$langs->trans("Start").')'."\n"; } From 468f4d18cb3634d7ee2b3cf266e86b6b6836bd29 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Thu, 7 Apr 2022 17:43:40 +0200 Subject: [PATCH 15/19] FIX : PR returns --- htdocs/core/actions_addupdatedelete.inc.php | 9 ++++++++- htdocs/product/inventory/class/inventory.class.php | 5 ++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index f97d4aa94ee..8b0f07c3274 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -366,7 +366,14 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto // Action validate object if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) { - $result = $object->validate($user); + if($object->element == 'inventory'){ + //Case of the conf INVENTORY_INCLUDE_SUB_WAREHOUSE + $include_sub_warehouse = !empty(GETPOST('include_sub_warehouse')) ? GETPOST('include_sub_warehouse') : 0; + $result = $object->validate($user, $include_sub_warehouse); + } else { + $result = $object->validate($user); + } + if ($result >= 0) { // Define output language if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 8f79a6d8267..ddb41813eae 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -257,14 +257,13 @@ class Inventory extends CommonObject * @param bool $notrigger false=launch triggers after, true=disable triggers * @return int <0 if KO, Id of created object if OK */ - public function validate(User $user, $notrigger = false) + public function validate(User $user, $include_sub_warehouse, $notrigger = false) { global $conf; $this->db->begin(); $result = 0; - $this->include_sub_warehouse = GETPOST('include_sub_warehouse'); if ($this->status == self::STATUS_DRAFT) { // Delete inventory $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id); @@ -291,7 +290,7 @@ class Inventory extends CommonObject } if ($this->fk_warehouse > 0) { $sql .= " AND (ps.fk_entrepot = ".((int) $this->fk_warehouse); - if (!empty($this->include_sub_warehouse) && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE) { + if (!empty($include_sub_warehouse) && $conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE) { $this->getchildWarehouse($this->fk_warehouse, $TChildWarehouses); $sql .= " OR ps.fk_entrepot IN (".filter_var(implode(',', $TChildWarehouses), FILTER_SANITIZE_STRING).")"; } From 2150c93f61344ef40585fc909c63336e94c4f7fa Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 7 Apr 2022 15:49:53 +0000 Subject: [PATCH 16/19] Fixing style errors. --- htdocs/core/actions_addupdatedelete.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 8b0f07c3274..45ca6074478 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -366,7 +366,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto // Action validate object if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) { - if($object->element == 'inventory'){ + if ($object->element == 'inventory') { //Case of the conf INVENTORY_INCLUDE_SUB_WAREHOUSE $include_sub_warehouse = !empty(GETPOST('include_sub_warehouse')) ? GETPOST('include_sub_warehouse') : 0; $result = $object->validate($user, $include_sub_warehouse); From 9323b366adde5aa602e30043dba83394ad64e0e3 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Fri, 22 Apr 2022 10:18:07 +0200 Subject: [PATCH 17/19] FIX : Retours PR --- htdocs/core/actions_addupdatedelete.inc.php | 5 ++--- htdocs/product/inventory/card.php | 1 + htdocs/product/inventory/class/inventory.class.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 8b0f07c3274..cb66cc97ca6 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -366,10 +366,9 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto // Action validate object if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) { - if($object->element == 'inventory'){ + if($object->element == 'inventory' && !empty($include_sub_warehouse)){ //Case of the conf INVENTORY_INCLUDE_SUB_WAREHOUSE - $include_sub_warehouse = !empty(GETPOST('include_sub_warehouse')) ? GETPOST('include_sub_warehouse') : 0; - $result = $object->validate($user, $include_sub_warehouse); + $result = $object->validate($user, false, $include_sub_warehouse); } else { $result = $object->validate($user); } diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index 390a57ea989..e2320d047fd 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -39,6 +39,7 @@ $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'inventorycard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); +$include_sub_warehouse = !empty(GETPOST('include_sub_warehouse')) ? GETPOST('include_sub_warehouse') : 0; if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $result = restrictedArea($user, 'stock', $id); diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index ddb41813eae..e8cd0c87c2c 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -257,7 +257,7 @@ class Inventory extends CommonObject * @param bool $notrigger false=launch triggers after, true=disable triggers * @return int <0 if KO, Id of created object if OK */ - public function validate(User $user, $include_sub_warehouse, $notrigger = false) + public function validate(User $user, $notrigger = false, $include_sub_warehouse = 0) { global $conf; $this->db->begin(); From 8f670ce96d832069de5b2df5af907904f500bfe5 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 22 Apr 2022 08:25:49 +0000 Subject: [PATCH 18/19] Fixing style errors. --- htdocs/core/actions_addupdatedelete.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index cb66cc97ca6..ec3f5a180b9 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -366,7 +366,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto // Action validate object if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) { - if($object->element == 'inventory' && !empty($include_sub_warehouse)){ + if ($object->element == 'inventory' && !empty($include_sub_warehouse)) { //Case of the conf INVENTORY_INCLUDE_SUB_WAREHOUSE $result = $object->validate($user, false, $include_sub_warehouse); } else { From a3be6a0c2cdc26e2902ec2bc7a15afc471bef686 Mon Sep 17 00:00:00 2001 From: Adrien Raze Date: Thu, 28 Apr 2022 12:11:59 +0200 Subject: [PATCH 19/19] FIX : When conf is active, option "include subwarehouse" must be checked by default --- htdocs/product/inventory/card.php | 2 +- htdocs/product/inventory/inventory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index e2320d047fd..e3e6cb4c1d3 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -295,7 +295,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $formquestion = ''; if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) { $formquestion = array( - array('type' => 'checkbox', 'name' => 'include_sub_warehouse', 'label' => $langs->trans("IncludeSubWarehouse"), 'value' => 0, 'size' => '10'), + array('type' => 'checkbox', 'name' => 'include_sub_warehouse', 'label' => $langs->trans("IncludeSubWarehouse"), 'value' => 1, 'size' => '10'), ); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateInventory'), $langs->trans('IncludeSubWarehouseExplanation'), 'confirm_validate', $formquestion, '', 1); } diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index ab3c0276051..82b3c6bc28e 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -440,7 +440,7 @@ if ($object->id > 0) { $formquestion = ''; if ($conf->global->INVENTORY_INCLUDE_SUB_WAREHOUSE && !empty($object->fk_warehouse)) { $formquestion = array( - array('type' => 'checkbox', 'name' => 'include_sub_warehouse', 'label' => $langs->trans("IncludeSubWarehouse"), 'value' => 0, 'size' => '10'), + array('type' => 'checkbox', 'name' => 'include_sub_warehouse', 'label' => $langs->trans("IncludeSubWarehouse"), 'value' => 1, 'size' => '10'), ); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateInventory'), $langs->trans('IncludeSubWarehouseExplanation'), 'confirm_validate', $formquestion, '', 1); }