Skip to content

Commit

Permalink
FIX Supplier orders : delete dispatched lines on supplier order delet…
Browse files Browse the repository at this point in the history
…ion (#25292)

* Add 2 entries for DispatchedLines on Delete

* Delete dispatched lined on order deletion

* add choice on deletion while dispatched lines exists

* fix indent

* fix begin, rollback and commit locations

* fix indent

* Update card.php

---------

Co-authored-by: Laurent Destailleur <[email protected]>
  • Loading branch information
ibuiv and eldy authored Nov 12, 2024
1 parent 9730a83 commit 369fb8b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
101 changes: 92 additions & 9 deletions htdocs/fourn/commande/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
}

if (isModEnabled('stock')) {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
}

/**
* @var Conf $conf
Expand All @@ -83,21 +87,22 @@


// Get Parameters
$id = GETPOSTINT('id');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'purchaseordercard'; // To manage different context of search
$cancel = GETPOST('cancel', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');

$id = GETPOSTINT('id');
$ref = GETPOST('ref', 'alpha');
$socid = GETPOSTINT('socid');
$projectid = GETPOSTINT('projectid');
$cancel = GETPOST('cancel', 'alpha');
$lineid = GETPOSTINT('lineid');
$origin = GETPOST('origin', 'alpha');
$originid = (GETPOSTINT('originid') ? GETPOSTINT('originid') : GETPOSTINT('origin_id')); // For backward compatibility
$rank = (GETPOSTINT('rank') > 0) ? GETPOSTINT('rank') : -1;
$stockDelete = GETPOST('stockDelete', 'int');

// PDF
$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
Expand Down Expand Up @@ -1128,12 +1133,63 @@


if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) {
$result = $object->delete($user);
if ($result > 0) {
header("Location: ".DOL_URL_ROOT.'/fourn/commande/list.php?restore_lastsearch_values=1');
exit;
// Delete existing dispatched lines
$errOnDelete = 0;

Check failure on line 1138 in htdocs/fourn/commande/card.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Whitespace found at end of line
$db->begin();

Check failure on line 1140 in htdocs/fourn/commande/card.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Whitespace found at end of line
if ($stockDelete) {
$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++;
}
}
}
}
}
}
}

Check failure on line 1179 in htdocs/fourn/commande/card.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Whitespace found at end of line
if (empty($errOnDelete)) {
$result = $object->delete($user);
if ($result > 0) {
$db->commit();
header("Location: " . DOL_URL_ROOT . '/fourn/commande/list.php?restore_lastsearch_values=1');
exit;
} else {
$db->rollback();
setEventMessages($object->error, $object->errors, 'errors');
}
} else {
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
setEventMessages('', $errorsOnDelete, 'errors');
}
}

Expand Down Expand Up @@ -1902,7 +1958,34 @@

// Confirmation de la suppression de la commande
if ($action == 'delete') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2);
$arrayAjouts = array();
$heightModal = 0;
$widthModal = 500;
if (!empty($object->getDispachedLines())) {
$arrayAjouts = array(
array(
'type' => 'other',
'value' => img_warning() . " " . $langs->trans('ExistingDipatchLines')
),
array('type' => 'separator'),
array(
'type' => 'select',
'id' => 'stockDeleteSelect',
'name' => 'stockDelete',
'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);
}

// Clone confirmation
Expand Down
4 changes: 4 additions & 0 deletions htdocs/langs/en_US/orders.lang
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,8 @@ 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 ?
SupplierOrderDeletion = Supplier order %s Deletion
OrderStatusMakeOperationForbidden = Order status forbidden for this operation.

0 comments on commit 369fb8b

Please sign in to comment.