From ffd9bde1cdd3ef90a11917fa773cc2998f355bc3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Nov 2024 15:26:50 +0100 Subject: [PATCH] Disable bugged code and rewrite it in comment to show the way --- htdocs/fourn/commande/card.php | 80 ++++++++++++++++++++-------------- htdocs/langs/en_US/orders.lang | 5 +-- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index d53802c4b42..7c9e2631d7f 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1135,48 +1135,60 @@ if (empty($reshook)) { if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) { // Delete existing dispatched lines $errOnDelete = 0; - + $errorsOnDelete = ''; + $db->begin(); - + if ($stockDelete) { + // TODO We must find line already recorded in stock, not lines dispatched (stock recording may not have been done + // even if dispatched in llx_receptiondet_batch) + // For example to know if stock movement were already record, we may look at stock movements in llx_stock_movement linked to a reception + // that is linked to the purchase order. + + /* $dispatchedLines = $object->getDispachedLines(); + if (!empty($dispatchedLines)) { foreach ($dispatchedLines as $dispatchedLine) { $supplierorderdispatch = new CommandeFournisseurDispatch($db); $result = $supplierorderdispatch->fetch($dispatchedLine['id']); if ($result > 0) { - $qty = $supplierorderdispatch->qty; - $entrepot = $supplierorderdispatch->fk_entrepot; - $product = $supplierorderdispatch->fk_product; - $price = price2num(GETPOST('price', 'alpha'), 'MU'); - $comment = $langs->trans('SupplierOrderDeletion', $object->ref); - $eatby = $supplierorderdispatch->eatby; - $sellby = $supplierorderdispatch->sellby; - $batch = $supplierorderdispatch->batch; $result = $supplierorderdispatch->delete($user); } if ($result < 0) { $errorsOnDelete = $object->errors; $errOnDelete++; - } else { - // If module stock is enabled and the stock increase is done on purchase order dispatching - if ($entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) && empty($supplierorderdispatch->fk_reception)) { - $mouv = new MouvementStock($db); - if ($product > 0) { - $mouv->origin = &$object; - $mouv->setOrigin($object->element, $object->id); - $result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment, '', $eatby, $sellby, $batch); - if ($result < 0) { - $errorsOnDelete = $mouv->errors; - $errOnDelete++; - } - } + } + } + } + + if ($entrepot > 0 && $product > 0 && isModEnabled('enabled')) { + $stockMovementLines = $object->getstockMovementLines() + + if (!empty($stockMovementLines)) { + foreach($stockMovementLines as $stockmovementline) { + $qty = $stockmovementline->qty; + $entrepot = $stockmovementline->fk_entrepot; + $product = $stockmovementline->fk_product; + $price = $stockmovementline->price; + $comment = $langs->trans('SupplierOrderDeletion', $object->ref); + $eatby = $stockmovementline->eatby; + $sellby = $stockmovementline->sellby; + $batch = $stockmovementline->batch; + + $mouv = new MouvementStock($db); + $mouv->setOrigin($object->element, $object->id); + $result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment, '', $eatby, $sellby, $batch); + if ($result < 0) { + $errorsOnDelete = $mouv->errors; + $errOnDelete++; } } } } + */ } - + if (empty($errOnDelete)) { $result = $object->delete($user); if ($result > 0) { @@ -1961,7 +1973,14 @@ if ($action == 'create') { $arrayAjouts = array(); $heightModal = 0; $widthModal = 500; - if (!empty($object->getDispachedLines())) { + + // TODO We must find line already recorded in stock, not lines dispatched (stock recording may not have been done + // even if dispatched in llx_receptiondet_batch). + // For example to know if stock movement were already record, we may look at stock movements in llx_stock_movement linked to a reception + // that is linked to the purchase order. + /* $dispatchedLines = $object->getStockMovementLines(); + + if (!empty($dispatchedLines)) { $arrayAjouts = array( array( 'type' => 'other', @@ -1975,17 +1994,14 @@ if ($action == 'create') { 'label' => $langs->trans('ConfirmDeleteDispatchedLines'), 'values' => array(1 => $langs->trans('Yes'), 0 => $langs->trans('No')), 'select_show_empty' => false - ), - array( - 'type' => 'other', - 'value' => img_warning() . " " . $langs->trans('WarningDispatchedLinesWillNotBeAccessibles') - ), - array('type' => 'separator'), + ) ); $heightModal = 300; $widthModal = "70%"; } - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', $arrayAjouts, 0, 2, $heightModal, $widthModal); + */ + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.((int) $object->id), $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', $arrayAjouts, 0, 2, $heightModal, $widthModal); } // Clone confirmation diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index 692bd2c7714..9be6a9d9f9b 100644 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -206,8 +206,7 @@ StatusSupplierOrderReceivedPartially=Partially received StatusSupplierOrderReceivedAll=All products received NeedAtLeastOneInvoice = There has to be at least one Invoice LineAlreadyDispatched = The order line is already received. -ExistingDipatchLines = There are dispatched lines for this order. -WarningDispatchedLinesWillNotBeAccessibles = You will be unable to update/remove these dispatched lines if you decide to not delete them. -ConfirmDeleteDispatchedLines = Delete dispatched lines ? +ExistingDipatchLines = There are already lines that has generated stock movement for this order. +ConfirmDeleteDispatchedLines = Revert also all stock movements already done ? SupplierOrderDeletion = Supplier order %s Deletion OrderStatusMakeOperationForbidden = Order status forbidden for this operation.