From b184e3461122c6c345743f9464310eb9a0ee7edc Mon Sep 17 00:00:00 2001 From: NextGestion Date: Sat, 13 May 2023 09:53:45 +0100 Subject: [PATCH 01/14] Fix| Products not removed from stock when deleting the supplier invoice --- .../fourn/class/fournisseur.facture.class.php | 3 +- htdocs/fourn/facture/card.php | 34 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 8563dd96d7c..58a809fc245 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1927,9 +1927,10 @@ class FactureFournisseur extends CommonInvoice * * @param User $user Object user that modify * @param int $idwarehouse Id warehouse to use for stock change. + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function setDraft($user, $idwarehouse = -1) + public function setDraft($user, $idwarehouse = -1, $notrigger = 0) { // phpcs:enable global $conf, $langs; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index e98bc12cba2..f56d4a6c93b 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -260,12 +260,36 @@ if (empty($reshook)) { $isErasable = $object->is_erasable(); if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) { - $result = $object->delete($user); - if ($result > 0) { - header('Location: list.php?restore_lastsearch_values=1'); - exit; + + $idwarehouse = GETPOST('idwarehouse'); + + $qualified_for_stock_change = 0; + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { - setEventMessages($object->error, $object->errors, 'errors'); + $qualified_for_stock_change = $object->hasProductsOrServices(1); + } + + // Check parameters + if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) { + $langs->load("stocks"); + if (!$idwarehouse || $idwarehouse == -1) { + $error++; + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); + $action = 'delete'; + } else { + $object->setDraft($user, $idwarehouse, 1); + } + } + + if(!$error) { + $result = $object->delete($user); + if ($result > 0) { + header('Location: list.php?restore_lastsearch_values=1'); + exit; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } } } } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { From 68b75d7b2762af7bea34e954f8d62f6d526e97c4 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 13 May 2023 08:56:17 +0000 Subject: [PATCH 02/14] Fixing style errors. --- htdocs/fourn/facture/card.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index f56d4a6c93b..90d0a480814 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -260,7 +260,6 @@ if (empty($reshook)) { $isErasable = $object->is_erasable(); if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) { - $idwarehouse = GETPOST('idwarehouse'); $qualified_for_stock_change = 0; @@ -282,7 +281,7 @@ if (empty($reshook)) { } } - if(!$error) { + if (!$error) { $result = $object->delete($user); if ($result > 0) { header('Location: list.php?restore_lastsearch_values=1'); From 46eb222407302b5f0fff5f408aa7de2bf52a85bf Mon Sep 17 00:00:00 2001 From: NextGestion Date: Sat, 13 May 2023 10:54:41 +0100 Subject: [PATCH 03/14] Fix| Header title in user card --- htdocs/user/card.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 570b78f7604..f29b4e79768 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -772,7 +772,19 @@ if (isModEnabled('stock')) { $formproduct = new FormProduct($db); } -if ($object->id > 0) { +if (GETPOSTINT('id') > 0) { + $res = $object->fetch($id, '', '', 1); + if ($res < 0) { + dol_print_error($db, $object->error); + exit; + } + + if ($res == 0) { + $langs->load("errors"); + print($langs->trans('ErrorRecordNotFound')); + exit; + } + $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname; $title = $person_name." - ".$langs->trans('Card'); } else { @@ -1380,12 +1392,7 @@ if ($action == 'create' || $action == 'adduserldap') { print ""; } else { // View and edit mode - if ($id > 0) { - $res = $object->fetch($id, '', '', 1); - if ($res < 0) { - dol_print_error($db, $object->error); - exit; - } + if ($object->id > 0) { $res = $object->fetch_optionals(); // Check if user has rights From ccc03f6c76f868ae8538b19b88c61976aa81c22a Mon Sep 17 00:00:00 2001 From: NextGestion Date: Sat, 13 May 2023 13:35:30 +0100 Subject: [PATCH 04/14] Handle stock movement in supplier invoice when the option "Stock can be negative" activated --- htdocs/fourn/class/fournisseur.facture.class.php | 5 +++++ htdocs/fourn/facture/card.php | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 58a809fc245..800645b87db 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1848,6 +1848,11 @@ class FactureFournisseur extends CommonInvoice $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num)); } if ($result < 0) { + if (count($mouvP->errors)) { + setEventMessages(null, $mouvP->errors, 'errors'); + } else { + setEventMessages($mouvP->error, $mouvP->errors, 'errors'); + } $error++; } } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 90d0a480814..61cca9415c8 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -277,7 +277,10 @@ if (empty($reshook)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $action = 'delete'; } else { - $object->setDraft($user, $idwarehouse, 1); + $result = $object->setDraft($user, $idwarehouse); + if($result < 0) { + $error++; + } } } From 92adfd2826420e28adfc0a3649dc8615bae9af21 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 13 May 2023 12:37:05 +0000 Subject: [PATCH 05/14] Fixing style errors. --- htdocs/fourn/facture/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 61cca9415c8..8c9b005ffb4 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -278,7 +278,7 @@ if (empty($reshook)) { $action = 'delete'; } else { $result = $object->setDraft($user, $idwarehouse); - if($result < 0) { + if ($result < 0) { $error++; } } From 12471dcb0606fb0dd14a24b28eca523962b9d888 Mon Sep 17 00:00:00 2001 From: NextGestion Date: Mon, 15 May 2023 09:48:45 +0100 Subject: [PATCH 06/14] Processing a return from @eldy "So we should not have setEventMessage inside such method" --- htdocs/fourn/class/fournisseur.facture.class.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 800645b87db..919894ce582 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1848,12 +1848,11 @@ class FactureFournisseur extends CommonInvoice $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num)); } if ($result < 0) { + $this->error = $mouvP->error; if (count($mouvP->errors)) { - setEventMessages(null, $mouvP->errors, 'errors'); - } else { - setEventMessages($mouvP->error, $mouvP->errors, 'errors'); + $this->errors = $mouvP->errors; } - $error++; + return -2; } } } From c9427cef8bc3c99abe01b81c2788f27694ac614f Mon Sep 17 00:00:00 2001 From: NextGestion Date: Mon, 15 May 2023 10:25:20 +0100 Subject: [PATCH 07/14] Processing a return from @eldy "The fetch is using $id so the test should be on $id" --- htdocs/user/card.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 4b79d4c78a2..e40068b3d27 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -772,7 +772,7 @@ if (isModEnabled('stock')) { $formproduct = new FormProduct($db); } -if (GETPOSTINT('id') > 0) { +if ($id > 0) { $res = $object->fetch($id, '', '', 1); if ($res < 0) { dol_print_error($db, $object->error); @@ -784,12 +784,15 @@ if (GETPOSTINT('id') > 0) { print($langs->trans('ErrorRecordNotFound')); exit; } +} +if ($action == 'create' || $action == 'adduserldap') { + $title = $langs->trans("NewUser"); +} else { $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname; $title = $person_name." - ".$langs->trans('Card'); -} else { - $title = $langs->trans("NewUser"); } + $help_url = ''; llxHeader('', $title, $help_url); From 30cc76b0742847028735487ded0d486ac094f0da Mon Sep 17 00:00:00 2001 From: NextGestion Date: Thu, 25 May 2023 12:15:50 +0100 Subject: [PATCH 08/14] Stock modification when deleting an invoice supplier : add a question during action to ask if stock must be reverted or not --- htdocs/fourn/facture/card.php | 86 +++++++++++++++++++++++++++------- htdocs/langs/en_US/stocks.lang | 1 + htdocs/langs/fr_FR/stocks.lang | 1 + 3 files changed, 71 insertions(+), 17 deletions(-) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 275ef936a58..4b43b3d3f51 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -261,28 +261,35 @@ if (empty($reshook)) { $isErasable = $object->is_erasable(); if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) { - $idwarehouse = GETPOST('idwarehouse'); - $qualified_for_stock_change = 0; - if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { - $qualified_for_stock_change = $object->hasProductsOrServices(2); - } else { - $qualified_for_stock_change = $object->hasProductsOrServices(1); - } + $revertstock = GETPOST('revertstock'); + + if ($revertstock) { - // Check parameters - if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) { - $langs->load("stocks"); - if (!$idwarehouse || $idwarehouse == -1) { - $error++; - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); - $action = 'delete'; + $idwarehouse = GETPOST('idwarehouse'); + + $qualified_for_stock_change = 0; + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { - $result = $object->setDraft($user, $idwarehouse); - if ($result < 0) { + $qualified_for_stock_change = $object->hasProductsOrServices(1); + } + + // Check parameters + if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) { + $langs->load("stocks"); + if (!$idwarehouse || $idwarehouse == -1) { $error++; + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); + $action = 'delete'; + } else { + $result = $object->setDraft($user, $idwarehouse); + if ($result < 0) { + $error++; + } } } + } if (!$error) { @@ -3038,7 +3045,52 @@ if ($action == 'create') { // Confirmation de la suppression de la facture fournisseur if ($action == 'delete') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1); + + $formquestion = array(); + + $qualified_for_stock_change = 0; + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $qualified_for_stock_change = $object->hasProductsOrServices(2); + } else { + $qualified_for_stock_change = $object->hasProductsOrServices(1); + } + + if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) { + $langs->load("stocks"); + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct = new FormProduct($db); + $warehouse = new Entrepot($db); + $warehouse_array = $warehouse->list_array(); + + $selectwarehouse = ''; + + print ''; + + $formquestion = array( + array('type' => 'checkbox', 'name' => 'revertstock', 'label' => $langs->trans('RevertProductsToStock'), 'value' => 'false'), + array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $selectwarehouse, 'tdclass' => 'questionrevertstock hidden') + ); + } + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', $formquestion, 1, 1); } if ($action == 'deletepayment') { $payment_id = GETPOST('paiement_id'); diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index d0696e53c1a..01cc5e49135 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -119,6 +119,7 @@ PersonalStock=Personal stock %s ThisWarehouseIsPersonalStock=This warehouse represents personal stock of %s %s SelectWarehouseForStockDecrease=Choose warehouse to use for stock decrease SelectWarehouseForStockIncrease=Choose warehouse to use for stock increase +RevertProductsToStock=Revert products to stock ? NoStockAction=No stock action DesiredStock=Desired Stock DesiredStockDesc=This stock amount will be the value used to fill the stock by replenishment feature. diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index 481ca5f312d..350d1a1fa18 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -119,6 +119,7 @@ PersonalStock=Stock personnel %s ThisWarehouseIsPersonalStock=Cet entrepôt représente le stock personnel de %s %s SelectWarehouseForStockDecrease=Sélectionner l'entrepôt à utiliser pour la décrémentation du stock SelectWarehouseForStockIncrease=Sélectionner l'entrepôt à utiliser pour l'incrémentation du stock +RevertProductsToStock=Remettre les produits en stock ? NoStockAction=Pas d'action sur l'entrepôt DesiredStock=Stock désiré optimal DesiredStockDesc=Le stock optimal sera la valeur utilisée pour remplir le stock avec la fonction de réapprovisionnement From a66d0e26838ff5afea53c745843c46c8349abd78 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 25 May 2023 11:22:03 +0000 Subject: [PATCH 09/14] Fixing style errors. --- htdocs/fourn/facture/card.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 4b43b3d3f51..3ba13ca8a91 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -261,11 +261,9 @@ if (empty($reshook)) { $isErasable = $object->is_erasable(); if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) { - $revertstock = GETPOST('revertstock'); - - if ($revertstock) { + if ($revertstock) { $idwarehouse = GETPOST('idwarehouse'); $qualified_for_stock_change = 0; @@ -289,7 +287,6 @@ if (empty($reshook)) { } } } - } if (!$error) { @@ -3045,7 +3042,6 @@ if ($action == 'create') { // Confirmation de la suppression de la facture fournisseur if ($action == 'delete') { - $formquestion = array(); $qualified_for_stock_change = 0; From d2e2c51970d0ba9f964f94a501ac93bfb3207a79 Mon Sep 17 00:00:00 2001 From: NextGestion Date: Thu, 25 May 2023 12:54:27 +0100 Subject: [PATCH 10/14] Revert user card.php --- htdocs/user/card.php | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 3c1a8cbb217..f8eb7e73899 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -775,25 +775,11 @@ if (isModEnabled('stock')) { $formproduct = new FormProduct($db); } -if ($id > 0) { - $res = $object->fetch($id, '', '', 1); - if ($res < 0) { - dol_print_error($db, $object->error); - exit; - } - - if ($res == 0) { - $langs->load("errors"); - print($langs->trans('ErrorRecordNotFound')); - exit; - } -} - -if ($action == 'create' || $action == 'adduserldap') { - $title = $langs->trans("NewUser"); -} else { +if ($object->id > 0) { $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname; $title = $person_name." - ".$langs->trans('Card'); +} else { + $title = $langs->trans("NewUser"); } $help_url = ''; @@ -1398,7 +1384,12 @@ if ($action == 'create' || $action == 'adduserldap') { print ""; } else { // View and edit mode - if ($object->id > 0) { + if ($id > 0) { + $res = $object->fetch($id, '', '', 1); + if ($res < 0) { + dol_print_error($db, $object->error); + exit; + } $res = $object->fetch_optionals(); // Check if user has rights From 2faded0f2116c087c7a1c04c007fac9cb8482097 Mon Sep 17 00:00:00 2001 From: NextGestion Date: Thu, 25 May 2023 14:59:04 +0100 Subject: [PATCH 11/14] Revert user card.php --- htdocs/user/card.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index f8eb7e73899..df1ab5b3f09 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -781,7 +781,6 @@ if ($object->id > 0) { } else { $title = $langs->trans("NewUser"); } - $help_url = ''; llxHeader('', $title, $help_url); From 5a47f1f009ac31722faec2e78eef3370e289d650 Mon Sep 17 00:00:00 2001 From: NextGestion Date: Thu, 25 May 2023 16:52:15 +0100 Subject: [PATCH 12/14] Revert products to stock : No or Yes --- htdocs/fourn/facture/card.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 3ba13ca8a91..e6fcd90d98f 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -3068,10 +3068,12 @@ if ($action == 'create') { } $selectwarehouse .= ''; + $selectyesno = array(0 => $langs->trans('No'), 1 => $langs->trans('Yes')); + print ''; $formquestion = array( - array('type' => 'checkbox', 'name' => 'revertstock', 'label' => $langs->trans('RevertProductsToStock'), 'value' => 'false'), + array('type' => 'select', 'name' => 'revertstock', 'label' => $langs->trans("RevertProductsToStock"), 'select_show_empty' => 0, 'values' => $selectyesno), array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $selectwarehouse, 'tdclass' => 'questionrevertstock hidden') ); } From 99e7abced31a6e8961f89f287254969cd47bcba0 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 25 May 2023 16:01:00 +0000 Subject: [PATCH 13/14] Fixing style errors. --- htdocs/fourn/facture/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index e6fcd90d98f..20280c543bd 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -3069,7 +3069,7 @@ if ($action == 'create') { $selectwarehouse .= ''; $selectyesno = array(0 => $langs->trans('No'), 1 => $langs->trans('Yes')); - + print '