From c52fab09e608d7eede0ece3f314304db147234d8 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Fri, 13 Jan 2023 09:01:31 +0100 Subject: [PATCH 1/3] FIX re-open supplier order should not be allowed when there is a reception. --- htdocs/fourn/commande/card.php | 46 ++++++++++++++++++++-------------- htdocs/langs/en_US/orders.lang | 1 + 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 644469a257d..ffb2e834db7 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -2440,6 +2440,19 @@ if ($action == 'create') { if (empty($reshook)) { $object->fetchObjectLinked(); // Links are used to show or not button, so we load them now. + // check if reception + $hasreception = 0; + if ($conf->reception->enabled) { + if (!empty($object->linkedObjects['reception'])) { + foreach ($object->linkedObjects['reception'] as $element) { + if ($element->statut >= 0) { + $hasreception = 1; + break; + } + } + } + } + // Validate if ($object->statut == 0 && $num > 0) { if ($usercanvalidate) { @@ -2515,17 +2528,21 @@ if ($action == 'create') { // Reopen if (in_array($object->statut, array(CommandeFournisseur::STATUS_ACCEPTED))) { $buttonshown = 0; - if (!$buttonshown && $usercanapprove) { - if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) - || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) { - print ''.$langs->trans("Disapprove").''; - $buttonshown++; + if ($hasreception) { + print ''.$langs->trans("Disapprove").''; + } else { + if (!$buttonshown && $usercanapprove) { + if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) + || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) { + print ''.$langs->trans("Disapprove").''; + $buttonshown++; + } } - } - if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) { - if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) - || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2)) { - print ''.$langs->trans("Disapprove").''; + if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) { + if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) + || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2)) { + print ''.$langs->trans("Disapprove").''; + } } } } @@ -2536,19 +2553,10 @@ if ($action == 'create') { } // Ship - $hasreception = 0; if (isModEnabled('stock') && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) { $labelofbutton = $langs->trans('ReceiveProducts'); if ($conf->reception->enabled) { $labelofbutton = $langs->trans("CreateReception"); - if (!empty($object->linkedObjects['reception'])) { - foreach ($object->linkedObjects['reception'] as $element) { - if ($element->statut >= 0) { - $hasreception = 1; - break; - } - } - } } if (in_array($object->statut, array(3, 4, 5))) { diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index f988cd62f19..0accaadfa62 100644 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -204,3 +204,4 @@ StatusSupplierOrderApproved=Approved StatusSupplierOrderRefused=Refused StatusSupplierOrderReceivedPartially=Partially received StatusSupplierOrderReceivedAll=All products received +NeedAtLeastOneInvoice = There has to be at least one Invoice From d842d0394d28db95428f5057dfdd6755a624d23f Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 15 Jan 2023 12:51:21 +0100 Subject: [PATCH 2/3] Revert "FIX re-open supplier order should not be allowed when there is a reception." This reverts commit c52fab09e608d7eede0ece3f314304db147234d8. --- htdocs/fourn/commande/card.php | 46 ++++++++++++++-------------------- htdocs/langs/en_US/orders.lang | 1 - 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index ffb2e834db7..644469a257d 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -2440,19 +2440,6 @@ if ($action == 'create') { if (empty($reshook)) { $object->fetchObjectLinked(); // Links are used to show or not button, so we load them now. - // check if reception - $hasreception = 0; - if ($conf->reception->enabled) { - if (!empty($object->linkedObjects['reception'])) { - foreach ($object->linkedObjects['reception'] as $element) { - if ($element->statut >= 0) { - $hasreception = 1; - break; - } - } - } - } - // Validate if ($object->statut == 0 && $num > 0) { if ($usercanvalidate) { @@ -2528,21 +2515,17 @@ if ($action == 'create') { // Reopen if (in_array($object->statut, array(CommandeFournisseur::STATUS_ACCEPTED))) { $buttonshown = 0; - if ($hasreception) { - print ''.$langs->trans("Disapprove").''; - } else { - if (!$buttonshown && $usercanapprove) { - if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) - || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) { - print ''.$langs->trans("Disapprove").''; - $buttonshown++; - } + if (!$buttonshown && $usercanapprove) { + if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) + || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER_ONLY) && $user->id == $object->user_approve_id)) { + print ''.$langs->trans("Disapprove").''; + $buttonshown++; } - if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) { - if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) - || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2)) { - print ''.$langs->trans("Disapprove").''; - } + } + if (!$buttonshown && $usercanapprovesecond && !empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) { + if (empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) + || (!empty($conf->global->SUPPLIER_ORDER_REOPEN_BY_APPROVER2_ONLY) && $user->id == $object->user_approve_id2)) { + print ''.$langs->trans("Disapprove").''; } } } @@ -2553,10 +2536,19 @@ if ($action == 'create') { } // Ship + $hasreception = 0; if (isModEnabled('stock') && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) { $labelofbutton = $langs->trans('ReceiveProducts'); if ($conf->reception->enabled) { $labelofbutton = $langs->trans("CreateReception"); + if (!empty($object->linkedObjects['reception'])) { + foreach ($object->linkedObjects['reception'] as $element) { + if ($element->statut >= 0) { + $hasreception = 1; + break; + } + } + } } if (in_array($object->statut, array(3, 4, 5))) { diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index 0accaadfa62..f988cd62f19 100644 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -204,4 +204,3 @@ StatusSupplierOrderApproved=Approved StatusSupplierOrderRefused=Refused StatusSupplierOrderReceivedPartially=Partially received StatusSupplierOrderReceivedAll=All products received -NeedAtLeastOneInvoice = There has to be at least one Invoice From f45ec82904c9fc4c0aabe40760535675d687ee20 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sun, 15 Jan 2023 13:13:49 +0100 Subject: [PATCH 3/3] Disallow line delete if already dispatched --- htdocs/fourn/class/fournisseur.commande.class.php | 13 ++++++++++++- htdocs/langs/en_US/orders.lang | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index a08f2046790..8b539138bfb 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2139,6 +2139,16 @@ class CommandeFournisseur extends CommonOrder return 0; } + // check if not yet received + $dispatchedLines = $this->getDispachedLines(); + foreach ($dispatchedLines as $dispatchLine) { + if ($dispatchLine['orderlineid'] == $idline) { + $this->error = "LineAlreadyDispatched"; + $this->errors[] = $this->error; + return -3; + } + } + if ($line->delete($notrigger) > 0) { $this->update_price(1); return 1; @@ -2327,7 +2337,7 @@ class CommandeFournisseur extends CommonOrder // List of already dispatched lines $sql = "SELECT p.ref, p.label,"; $sql .= " e.rowid as warehouse_id, e.ref as entrepot,"; - $sql .= " cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status"; + $sql .= " cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_commandefourndet"; $sql .= " FROM ".MAIN_DB_PREFIX."product as p,"; $sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid"; @@ -2351,6 +2361,7 @@ class CommandeFournisseur extends CommonOrder 'productid' => $objp->fk_product, 'warehouseid' => $objp->warehouse_id, 'qty' => $objp->qty, + 'orderlineid' => $objp->fk_commandefourndet ); } diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index f988cd62f19..4be2b34fd73 100644 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -204,3 +204,5 @@ StatusSupplierOrderApproved=Approved StatusSupplierOrderRefused=Refused StatusSupplierOrderReceivedPartially=Partially received StatusSupplierOrderReceivedAll=All products received +NeedAtLeastOneInvoice = There has to be at least one Invoice +LineAlreadyDispatched = The order line is already received. \ No newline at end of file