From 7d72d11b8d7ea15f174cc8e4cb73274ebdcfaad2 Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Wed, 4 Oct 2023 17:30:08 +0200 Subject: [PATCH 1/7] Added the possibility of editing lines --- htdocs/mrp/mo_production.php | 274 +++++++++++++++++++++++------------ 1 file changed, 180 insertions(+), 94 deletions(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index c01866efca761..2fa874a9a5c40 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -434,6 +434,15 @@ setEventMessages($object->error, $object->errors, 'errors'); } } + + if ($action == 'confirm_editline' && $permissiontoadd) { + $moline = new MoLine($db); + $moline->fetch(GETPOST('lineid', 'int')); + $moline->qty = GETPOST('qty_lineProduce', 'int'); + $moline->update($user); + + header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id); + } } @@ -685,7 +694,7 @@ print ''; } - if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline', 'addproduceline'))) { + if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline', 'addproduceline', 'editline'))) { print '
'; print ''; print ''; @@ -808,6 +817,11 @@ // SplitAll print ''; + //Edit Line + if ($object->status == Mo::STATUS_DRAFT){ + print ''; + } + print ''; if ($action == 'addconsumeline') { @@ -890,116 +904,188 @@ $alreadyconsumed += $line2['qty']; } - $suffix = '_'.$line->id; - print ''."\n"; - // hidden fields for js function - print ''; - print ''; + if ($action == 'editline' && $lineid == $line->id){ - print ''; - // Product - print ''.$tmpproduct->getNomUrl(1); - print '
'.$tmpproduct->label.'
'; - print ''; - // Qty - print ''; - $help = ''; $picto = 'help'; - if ($line->qty_frozen) { - $help = ($help ? '
' : '').''.$langs->trans("QuantityFrozen").': '.yn(1).' ('.$langs->trans("QuantityConsumedInvariable").')'; - print $form->textwithpicto('', $help, -1, 'lock').' '; - } - if ($line->disable_stock_change) { - $help = ($help ? '
' : '').''.$langs->trans("DisableStockChange").': '.yn(1).' ('.(($tmpproduct->type == Product::TYPE_SERVICE && empty($conf->global->STOCK_SUPPORTS_SERVICES)) ? $langs->trans("NoStockChangeOnServices") : $langs->trans("DisableStockChangeHelp")).')'; - print $form->textwithpicto('', $help, -1, 'help').' '; - } - print price2num($line->qty, 'MS'); - print ''; - // Cost price - if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) { + $linecost = price2num($tmpproduct->pmp, 'MT'); + + $arrayoflines = $object->fetchLinesLinked('consumed', $line->id); + $alreadyconsumed = 0; + if (is_array($arrayoflines) && !empty($arrayoflines)) { + foreach ($arrayoflines as $line2) { + $alreadyconsumed += $line2['qty']; + } + } + $suffix = '_' . $line->id; + print '' . "\n"; + // hidden fields for js function + print ''; + // Duration - Time spent + print ''; + print ''; + print ''; + + // Product + print '' . $tmpproduct->getNomUrl(1); + print '
' . $tmpproduct->label . ''; + print ''; + + // Qty print ''; - print price($linecost); + print ''; print ''; - } - // Already consumed - print ''; - if ($alreadyconsumed) { - print ''; - if (empty($conf->use_javascript_ajax)) { - print 'id.'">'; + print ''. $tmpproduct->stock_reel .' '; + print ''; + // Batch + print ''; + print ''; + + // Action delete line + print ''; + print ''; + print ''; + print ''; + + // Action delete line + if ($permissiontodelete) { + print ''; } - print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expandtoproduce'.$line->id.'"'); - if (empty($conf->use_javascript_ajax)) { - print ''; + print ''; + print ''; + + }else { + $suffix = '_' . $line->id; + print '' . "\n"; + // hidden fields for js function + print ''; + print ''; + + print ''; + // Product + print '' . $tmpproduct->getNomUrl(1); + print '
' . $tmpproduct->label . '
'; + print ''; + // Qty + print ''; + $help = ''; + $picto = 'help'; + if ($line->qty_frozen) { + $help = ($help ? '
' : '') . '' . $langs->trans("QuantityFrozen") . ': ' . yn(1) . ' (' . $langs->trans("QuantityConsumedInvariable") . ')'; + print $form->textwithpicto('', $help, -1, 'lock') . ' '; } - } else { - if ($nblinetoconsume == $nblinetoconsumecursor) { // If it is the last line - print ''; + if ($line->disable_stock_change) { + $help = ($help ? '
' : '') . '' . $langs->trans("DisableStockChange") . ': ' . yn(1) . ' (' . (($tmpproduct->type == Product::TYPE_SERVICE && empty($conf->global->STOCK_SUPPORTS_SERVICES)) ? $langs->trans("NoStockChangeOnServices") : $langs->trans("DisableStockChangeHelp")) . ')'; + print $form->textwithpicto('', $help, -1, 'help') . ' '; } - } - print ' '.price2num($alreadyconsumed, 'MS'); - print ''; - // Warehouse - print ''; - if (!empty($conf->global->STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE) && $tmpwarehouse->id > 0) { - print img_picto('', $tmpwarehouse->picto)." ".$tmpwarehouse->label; - } - print ''; - // Stock - if (isModEnabled('stock')) { - print ''; - if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $tmpproduct->type != Product::TYPE_SERVICE) { - if (!$line->disable_stock_change && $tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) { - print img_warning($langs->trans('StockTooLow')) . ' '; + print price2num($line->qty, 'MS'); + print ''; + // Cost price + if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) { + print ''; + print price($linecost); + print ''; + } + // Already consumed + print ''; + if ($alreadyconsumed) { + print ''; + if (empty($conf->use_javascript_ajax)) { + print 'id . '">'; + } + print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expandtoproduce' . $line->id . '"'); + if (empty($conf->use_javascript_ajax)) { + print ''; + } + } else { + if ($nblinetoconsume == $nblinetoconsumecursor) { // If it is the last line + print ''; + } + } + print ' ' . price2num($alreadyconsumed, 'MS'); + print ''; + // Warehouse + print ''; + if (!empty($conf->global->STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE) && $tmpwarehouse->id > 0) { + print img_picto('', $tmpwarehouse->picto) . " " . $tmpwarehouse->label; + } + print ''; + // Stock + if (isModEnabled('stock')) { + print ''; + if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $tmpproduct->type != Product::TYPE_SERVICE) { + if (!$line->disable_stock_change && $tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) { + print img_warning($langs->trans('StockTooLow')) . ' '; + } + if (empty($conf->global->STOCK_CONSUMPTION_FROM_MANUFACTURING_WAREHOUSE) || empty($tmpwarehouse->id)) { + print price2num($tmpproduct->stock_reel, 'MS'); // Available } else { - print "0"; + // Print only the stock in the selected warehouse + $tmpproduct->load_stock(); + $wh_stock = $tmpproduct->stock_warehouse[$tmpwarehouse->id]; + if (!empty($wh_stock)) { + print price2num($wh_stock->real, 'MS'); + } else { + print "0"; + } } } + print ''; + } + // Lot + if (isModEnabled('productbatch')) { + print ''; } - print ''; - } - // Lot - if (isModEnabled('productbatch')) { - print ''; - } - // Split - print ''; + // Split + print ''; - // Split All - print ''; + // Split All + print ''; - // Action delete line - if ($permissiontodelete) { - $href = $_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=deleteline&token='.newToken().'&lineid='.((int) $line->id); - print ''; - print ''; - print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete'); - print ''; - print ''; - } + // Action Edit line + if ($object->status == Mo::STATUS_DRAFT) { + $href = $_SERVER["PHP_SELF"] . '?id=' . ((int)$object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int)$line->id); + print ''; + print ''; + print img_picto($langs->trans('TooltipEditAndRevertStockMovement'), 'edit'); + print ''; + print ''; + } - print ''; + // Action delete line + if ($permissiontodelete) { + $href = $_SERVER["PHP_SELF"] . '?id=' . ((int)$object->id) . '&action=deleteline&token=' . newToken() . '&lineid=' . ((int)$line->id); + print ''; + print ''; + print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete'); + print ''; + print ''; + } + print ''; + } // Show detailed of already consumed with js code to collapse foreach ($arrayoflines as $line2) { print ''; From 3976f986734ae1db85f3e1697fd808680f5e78a1 Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Fri, 6 Oct 2023 16:40:50 +0200 Subject: [PATCH 2/7] Review code --- htdocs/mrp/mo_production.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 2fa874a9a5c40..5d305e0f478fc 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -437,11 +437,12 @@ if ($action == 'confirm_editline' && $permissiontoadd) { $moline = new MoLine($db); - $moline->fetch(GETPOST('lineid', 'int')); - $moline->qty = GETPOST('qty_lineProduce', 'int'); - $moline->update($user); - - header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id); + $res = $moline->fetch(GETPOST('lineid', 'int')); + if ($result > 0){ + $moline->qty = GETPOST('qty_lineProduce', 'int'); + $moline->update($user); + header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id); + } } } @@ -818,7 +819,7 @@ print ''; //Edit Line - if ($object->status == Mo::STATUS_DRAFT){ + if ($object->status == Mo::STATUS_DRAFT) { print ''; } @@ -904,8 +905,7 @@ $alreadyconsumed += $line2['qty']; } - if ($action == 'editline' && $lineid == $line->id){ - + if ($action == 'editline' && $lineid == $line->id) { $linecost = price2num($tmpproduct->pmp, 'MT'); $arrayoflines = $object->fetchLinesLinked('consumed', $line->id); @@ -963,8 +963,7 @@ } print ''; print ''; - - }else { + } else { $suffix = '_' . $line->id; print '' . "\n"; // hidden fields for js function From 68add0956de433f9d4b2ce15d8a12a57673b8b00 Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Mon, 16 Oct 2023 14:36:34 +0200 Subject: [PATCH 3/7] add exit --- htdocs/mrp/mo_production.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 5d305e0f478fc..3b2f88b6c1111 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -438,10 +438,11 @@ if ($action == 'confirm_editline' && $permissiontoadd) { $moline = new MoLine($db); $res = $moline->fetch(GETPOST('lineid', 'int')); - if ($result > 0){ + if ($result > 0) { $moline->qty = GETPOST('qty_lineProduce', 'int'); $moline->update($user); header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; } } } @@ -1065,7 +1066,7 @@ // Action Edit line if ($object->status == Mo::STATUS_DRAFT) { - $href = $_SERVER["PHP_SELF"] . '?id=' . ((int)$object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int)$line->id); + $href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int) $line->id); print ''; print ''; print img_picto($langs->trans('TooltipEditAndRevertStockMovement'), 'edit'); @@ -1075,7 +1076,7 @@ // Action delete line if ($permissiontodelete) { - $href = $_SERVER["PHP_SELF"] . '?id=' . ((int)$object->id) . '&action=deleteline&token=' . newToken() . '&lineid=' . ((int)$line->id); + $href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=deleteline&token=' . newToken() . '&lineid=' . ((int) $line->id); print ''; print ''; print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete'); From e29e6415bb4fbced04fbbbeefbcd8e5d77ef3f11 Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Tue, 17 Oct 2023 14:45:36 +0200 Subject: [PATCH 4/7] Add same action --- htdocs/mrp/mo_production.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 3b2f88b6c1111..389c31905544d 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -1139,6 +1139,16 @@ // Split All print ''; + // Action Edit line + if ($object->status == Mo::STATUS_DRAFT) { + $href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int) $line->id); + print ''; + print ''; + print img_picto($langs->trans('TooltipEditAndRevertStockMovement'), 'edit'); + print ''; + print ''; + } + // Action delete line if ($permissiontodelete) { $href = $_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=deleteline&token='.newToken().'&lineid='.((int) $line->id).'&fk_movement='.((int) $line2['fk_stock_movement']); From 41cf64f6f8aaa3d3a7652c3f5487b286938c0512 Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Mon, 23 Oct 2023 11:41:34 +0200 Subject: [PATCH 5/7] check Travis --- htdocs/mrp/mo_production.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 389c31905544d..44f7928ca88a0 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -1141,7 +1141,7 @@ // Action Edit line if ($object->status == Mo::STATUS_DRAFT) { - $href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int) $line->id); + $href = $_SERVER["PHP_SELF"] . '?id=' . ((int)$object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int)$line->id); print ''; print ''; print img_picto($langs->trans('TooltipEditAndRevertStockMovement'), 'edit'); From 7f015181a5903e0c1f7bf1f735ea8b96cc3024dd Mon Sep 17 00:00:00 2001 From: ATM-Lucas Date: Mon, 23 Oct 2023 12:00:36 +0200 Subject: [PATCH 6/7] Travis --- htdocs/mrp/mo_production.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 44f7928ca88a0..330fc08cdb189 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -1141,7 +1141,7 @@ // Action Edit line if ($object->status == Mo::STATUS_DRAFT) { - $href = $_SERVER["PHP_SELF"] . '?id=' . ((int)$object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int)$line->id); + $href = $_SERVER["PHP_SELF"] . '?id=' . ((int) $object->id) . '&action=editline&token=' . newToken() . '&lineid=' . ((int) $line->id); print ''; print ''; print img_picto($langs->trans('TooltipEditAndRevertStockMovement'), 'edit'); @@ -1183,7 +1183,7 @@ print ''; // Qty - print ''; + print ''; // Cost if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) { From 79636b93efe588b88d1ae729949bd5e8d7f03c6e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 26 Oct 2023 14:10:54 +0200 Subject: [PATCH 7/7] Update mo_production.php --- htdocs/mrp/mo_production.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 330fc08cdb189..5e1ee1e0a60e3 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -1236,6 +1236,11 @@ } print ''; + // Edit Line + if ($object->status == Mo::STATUS_DRAFT) { + print ''; + } + // Action delete line if ($permissiontodelete) { print '';