From 22dddb8e8784e68308b73b71ca400b519e02273e Mon Sep 17 00:00:00 2001 From: Florian Mortgat <50440633+atm-florianm@users.noreply.github.com> Date: Wed, 15 May 2024 15:07:29 +0200 Subject: [PATCH] FIX: Backport page inventory.php from v18 to fix pagination bugs causing data loss (#29688) --- htdocs/product/inventory/inventory.php | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 4b2ea3e93c0..b924b9c442c 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -97,11 +97,10 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ //$result = restrictedArea($user, 'mymodule', $id); //Parameters Page -$param = '&id='.$object->id; +$paramwithsearch = ''; if ($limit > 0 && $limit != $conf->liste_limit) { - $param .= '&limit='.urlencode($limit); + $paramwithsearch .= '&limit='.((int) $limit); } -$paramwithsearch = $param; if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { @@ -265,6 +264,7 @@ if (empty($reshook)) { $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated'; $sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id'; $sql .= ' WHERE id.fk_inventory = '.((int) $object->id); + $sql .= $db->order('id.rowid', 'ASC'); $sql .= $db->plimit($limit, $offset); $db->begin(); @@ -297,7 +297,7 @@ if (empty($reshook)) { $inventoryline->pmp_expected = price2num(GETPOST('expectedpmp_'.$lineid, 'alpha'), 'MS'); $resultupdate = $inventoryline->update($user); } - } else { + } elseif (GETPOSTISSET('id_' . $lineid)) { // Delete record $result = $inventoryline->fetch($lineid); if ($result > 0) { @@ -415,7 +415,6 @@ if (empty($reshook)) { - /* * View */ @@ -459,7 +458,7 @@ if ($action == 'clone') { // Confirmation to close if ($action == 'record') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Close'), $langs->trans('ConfirmFinish'), 'update', '', 0, 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&page='.$page.$paramwithsearch, $langs->trans('Close'), $langs->trans('ConfirmFinish'), 'update', '', 0, 1); $action = 'view'; } @@ -494,7 +493,7 @@ $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $ // Thirdparty $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); // Project -if (!empty($conf->project->enabled)) +if (isModEnabled('project')) { $langs->load("projects"); $morehtmlref.='
'.$langs->trans('Project') . ' '; @@ -583,13 +582,13 @@ if ($action != 'record') { // Save if ($object->status == $object::STATUS_VALIDATED) { if ($permissiontoadd) { - print ''.$langs->trans("MakeMovementsAndClose").''."\n"; + print ''.$langs->trans("MakeMovementsAndClose").''."\n"; } else { print ''.$langs->trans('MakeMovementsAndClose').''."\n"; } if ($permissiontoadd) { - print ''.$langs->trans("Cancel").''."\n"; + print ''.$langs->trans("Cancel").''."\n"; } } } @@ -990,7 +989,7 @@ if ($resql) { $num = $db->num_rows($resql); if (!empty($limit != 0) || $num > $limit || $page) { - print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num >= $limit), '', '', $limit); + print_fleche_navigation($page, $_SERVER["PHP_SELF"], '&id='.$object->id.$paramwithsearch, ($num >= $limit), '', '', $limit); } $i = 0; @@ -1046,8 +1045,9 @@ if ($resql) { // Expected quantity = Quantity in stock when we start inventory print ''; $valuetoshow = $obj->qty_stock; + // For inventory not yet close, we overwrite with the real value in stock now - if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) { + if (($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) && !getDolGlobalString('DISABLE_QTY_OVERWRITE')) { if (isModEnabled('productbatch') && $product_static->hasbatch()) { $valuetoshow = $product_static->stock_warehouse[$obj->fk_warehouse]->detail_batch[$obj->batch]->qty; } else { @@ -1206,38 +1206,38 @@ print '