From ef734aeb58297d004245e8d88aceffa501c270d6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 1 May 2021 16:33:05 +0200 Subject: [PATCH] Debug module inventory --- ChangeLog | 1 + htdocs/langs/en_US/main.lang | 1 + htdocs/product/inventory/card.php | 14 ++-- htdocs/product/inventory/inventory.php | 93 ++++++++++++++++++++------ 4 files changed, 81 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index c5f75ecbe89..2f37db92cc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ English Dolibarr ChangeLog For users: ---------- +NEW: Feature to make inventories NEW: Several security issues after a second private bug bounty campaign. NEW: Add a security center page with all information and advices related to the security of your instance NEW: Add a performance center page with all information and advices related to the performance of your instance diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index de0ab6a15d9..b6d2e4c4ef8 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1131,3 +1131,4 @@ ConfirmAffectTagQuestion=Are you sure you want to affect tags to the %s selected CategTypeNotFound=No tag type found for type of records CopiedToClipboard=Copied to clipboard InformationOnLinkToContract=This amount is only the total of all the lines of the contract. No notion of time is taken into consideration. +ConfirmCancel=Are you sure you want to cancel \ No newline at end of file diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index dda16746398..6a29a414ed7 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -398,35 +398,35 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if (empty($reshook)) { // Send if (empty($user->socid)) { - print ''.$langs->trans('SendMail').''."\n"; + print ''.$langs->trans('SendMail').''."\n"; } // Back to draft if ($object->status == $object::STATUS_VALIDATED) { if ($permissiontoadd) { - print ''.$langs->trans("SetToDraft").''; + print ''.$langs->trans("SetToDraft").''; } } // Back to validate if ($object->status == $object::STATUS_RECORDED) { if ($permissiontoadd) { - print ''.$langs->trans("ReOpen").''; + print ''.$langs->trans("ReOpen").''; } } // Modify if ($object->status == $object::STATUS_DRAFT) { if ($permissiontoadd) { - print ''.$langs->trans("Modify").''."\n"; + print ''.$langs->trans("Modify").''."\n"; } else { print ''.$langs->trans('Modify').''."\n"; } } // Validate - if ($object->status == $object::STATUS_DRAFT) { + if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_CANCELED) { if ($permissiontoadd) { - print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; + print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'; } } @@ -438,7 +438,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Delete (need delete permission, or if draft, just need create/modify permission) if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) { - print ''.$langs->trans('Delete').''."\n"; + print ''.$langs->trans('Delete').''."\n"; } else { print ''.$langs->trans('Delete').''."\n"; } diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index bc927a06c50..baf0cd45591 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -160,27 +160,55 @@ if ($action == 'update' && $user->rights->stock->mouvement->creer) { } } -if ($action =='updateinventorylines' && $permissiontoadd) { +if (($action == 'record' || $action =='updateinventorylines') && $permissiontoadd) { $sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,'; $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 = '.$object->id; + $db->begin(); + $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $totalarray = array(); + $inventoryline = new InventoryLine($db); + while ($i < $num) { $line = $db->fetch_object($resql); $lineid = $line->rowid; - $inventoryline = new InventoryLine($db); - $inventoryline->fetch($lineid); - $inventoryline->qty_view = GETPOST("id_".$inventoryline->id); - $inventoryline->update($user); + + if (GETPOST("id_".$lineid, 'alpha') != '') { // If a value was set ('0' or something else) + $qtytoupdate = price2num(GETPOST("id_".$lineid, 'alpha'), 'MS'); + + $result = $inventoryline->fetch($lineid); + if ($result > 0) { + $inventoryline->qty_view = $qtytoupdate; + $resultupdate = $inventoryline->update($user); + } + } else { + // Delete record + $result = $inventoryline->fetch($lineid); + if ($result > 0) { + $inventoryline->qty_view = null; + $resultupdate = $inventoryline->update($user); + } + } + + if ($result < 0 || $resultupdate < 0) { + $error++; + } + $i++; } } + + if (!$error) { + $db->commit(); + } else { + $db->rollback(); + } } $parameters = array(); @@ -270,6 +298,23 @@ $help_url = ''; llxHeader('', $langs->trans('Inventory'), $help_url); +// Disable button Generate movement if data were not saved +print ''; + + // Part to show record if ($object->id > 0) { $res = $object->fetch_optionals(); @@ -411,7 +456,7 @@ if ($object->id > 0) { if (empty($reshook)) { if ($object->status == Inventory::STATUS_DRAFT) { if ($permissiontoadd) { - print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'."\n"; + print ''.$langs->trans("Validate").' ('.$langs->trans("Start").')'."\n"; } else { print ''.$langs->trans('Validate').' ('.$langs->trans("Start").')'."\n"; } @@ -419,16 +464,14 @@ if ($object->id > 0) { // Save if ($object->status == $object::STATUS_VALIDATED) { - if ($object->status == Inventory::STATUS_VALIDATED) { - if ($permissiontoadd) { - print ''.$langs->trans("MakeMovementsAndClose").''."\n"; - } else { - print ''.$langs->trans('MakeMovementsAndClose').''."\n"; - } + if ($permissiontoadd) { + print ''.$langs->trans("MakeMovementsAndClose").''."\n"; + } else { + print ''.$langs->trans('MakeMovementsAndClose').''."\n"; } if ($permissiontoadd) { - print ''.$langs->trans("Cancel").''."\n"; + print ''.$langs->trans("Cancel").''."\n"; } } } @@ -458,14 +501,17 @@ if ($object->id > 0) { print ''; } @@ -617,13 +663,16 @@ if ($object->id > 0) { print ''; } + // Expected quantity print ''; print $obj->qty_stock; print ''; + + // Real quantity print ''; if ($object->status == $object::STATUS_VALIDATED) { $qty_view = GETPOST("id_".$obj->rowid) ? GETPOST("id_".$obj->rowid) : $obj->qty_view; - print ''; + print ''; print ''; print ''; print ''.img_delete().''; @@ -644,7 +693,9 @@ if ($object->id > 0) { print ''; - print '
'; + if ($object->status == $object::STATUS_VALIDATED) { + print '
'; + } print '';