From 84d446cf73ec1e14432253ebd2ff3ebc7b5b2d57 Mon Sep 17 00:00:00 2001 From: Quentin VIAL-GOUTEYRON Date: Fri, 21 Jan 2022 15:31:30 +0100 Subject: [PATCH 1/2] NEW possibility to consume multiple batch --- htdocs/mrp/js/lib_dispatch.js.php | 6 ++++-- htdocs/mrp/mo_production.php | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/htdocs/mrp/js/lib_dispatch.js.php b/htdocs/mrp/js/lib_dispatch.js.php index 8a5eef60211..aa29b38c5fb 100644 --- a/htdocs/mrp/js/lib_dispatch.js.php +++ b/htdocs/mrp/js/lib_dispatch.js.php @@ -70,10 +70,12 @@ function addDispatchLine(index, type, mode) mode = mode || 'qtymissing' console.log("fourn/js/lib_dispatch.js.php Split line type="+type+" index="+index+" mode="+mode); + if(mode == 'qtymissingconsume') var inputId = 'qtytoconsume'; + else var inputId = 'qtytoproduce'; var nbrTrs = $("tr[name^='"+type+"_"+index+"']").length; // position of line for batch var $row = $("tr[name='"+type+'_'+index+"_1']").clone(true); // clone last batch line to jQuery object var qtyOrdered = parseFloat($("#qty_ordered_"+index).val()); // Qty ordered is same for all rows - var qty = parseFloat($("#qtytoproduce-"+index+"-"+nbrTrs).val()); + var qty = parseFloat($("#"+inputId+"-"+index+"-"+nbrTrs).val()); var qtyDispatched; if (mode === 'lessone') @@ -83,7 +85,7 @@ function addDispatchLine(index, type, mode) else { qtyDispatched = parseFloat($("#qty_dispatched_"+index).val()) + qty; - console.log(qty); + console.log($("#qty_dispatched_"+index).val()); // If user did not reduced the qty to dispatch on old line, we keep only 1 on old line and the rest on new line if (qtyDispatched == qtyOrdered && qtyDispatched > 1) { qtyDispatched = parseFloat($("#qty_dispatched_"+index).val()) + 1; diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index ca9480eb1ae..fa5897bb5f0 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -811,6 +811,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $alreadyconsumed += $line2['qty']; } + $suffix = '_'.$line->id; + print ''."\n"; + // hidden fields for js function + print ''; + print ''; + print ''; print ''.$tmpproduct->getNomUrl(1); print '
'.$tmpproduct->label.''; @@ -914,13 +920,13 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) { $i = 1; print ''."\n"; - print ''; + print ''; print ''.$langs->trans("ToConsume").''; $preselected = (GETPOSTISSET('qty-'.$line->id.'-'.$i) ? GETPOST('qty-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyconsumed)); if ($action == 'consumeorproduce' && !GETPOSTISSET('qty-'.$line->id.'-'.$i)) { $preselected = 0; } - print ''; + print ''; if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) { print ''; } @@ -945,6 +951,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; } print ''; + print ''; + if ($tmpproduct->status_batch) { + $type = 'batch'; + print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$line->id.', \''.$type.'\', \'qtymissingconsume\')"'); + } + print ''; } print ''; } From 4de5ee97b35dd4a18297b9bff18a692d9c3e7ef7 Mon Sep 17 00:00:00 2001 From: Quentin VIAL-GOUTEYRON Date: Tue, 25 Jan 2022 16:37:33 +0100 Subject: [PATCH 2/2] NEW : split consumption line on MO --- htdocs/mrp/js/lib_dispatch.js.php | 36 ++++++++++++++++++------------- htdocs/mrp/mo_production.php | 2 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/htdocs/mrp/js/lib_dispatch.js.php b/htdocs/mrp/js/lib_dispatch.js.php index aa29b38c5fb..d8285ac75c1 100644 --- a/htdocs/mrp/js/lib_dispatch.js.php +++ b/htdocs/mrp/js/lib_dispatch.js.php @@ -70,8 +70,14 @@ function addDispatchLine(index, type, mode) mode = mode || 'qtymissing' console.log("fourn/js/lib_dispatch.js.php Split line type="+type+" index="+index+" mode="+mode); - if(mode == 'qtymissingconsume') var inputId = 'qtytoconsume'; - else var inputId = 'qtytoproduce'; + if(mode == 'qtymissingconsume') { + var inputId = 'qtytoconsume'; + var warehouseId = 'idwarehouse'; + } + else { + var inputId = 'qtytoproduce'; + var warehouseId = 'idwarehousetoproduce'; + } var nbrTrs = $("tr[name^='"+type+"_"+index+"']").length; // position of line for batch var $row = $("tr[name='"+type+'_'+index+"_1']").clone(true); // clone last batch line to jQuery object var qtyOrdered = parseFloat($("#qty_ordered_"+index).val()); // Qty ordered is same for all rows @@ -105,11 +111,11 @@ function addDispatchLine(index, type, mode) $row.html($row.html().replace(re1, '_'+index+'_'+(nbrTrs+1))); $row.html($row.html().replace(re2, '-'+index+'-'+(nbrTrs+1))); //create new select2 to avoid duplicate id of cloned one - $row.find("select[name='"+'idwarehousetoproduce-'+index+'-'+(nbrTrs+1)+"']").select2(); + $row.find("select[name='"+warehouseId+'-'+index+'-'+(nbrTrs+1)+"']").select2(); // TODO find solution to copy selected option to new select // TODO find solution to keep new tr's after page refresh //clear value - $row.find("input[name^='qtytoproduce']").val(''); + $row.find("input[id^='"+inputId+"']").val(''); //change name of new row $row.attr('name',type+'_'+index+'_'+(nbrTrs+1)); //insert new row before last row @@ -120,20 +126,20 @@ function addDispatchLine(index, type, mode) $(".csswarehouse_"+index+"_"+(nbrTrs+1)+":first-child").parent("span.selection").parent(".select2").detach(); /* Suffix of lines are: index _ trs.length */ - $("#qtytoproduce-"+index+"-"+(nbrTrs+1)).focus(); - if ($("#qtytoproduce-"+index+"-"+(nbrTrs)).val() == 0) { - $("#qtytoproduce-"+index+"-"+(nbrTrs)).val(1); + $("#"+inputId+"-"+index+"-"+(nbrTrs+1)).focus(); + if ($("#"+inputId+"-"+index+"-"+(nbrTrs)).val() == 0) { + $("#"+inputId+"-"+index+"-"+(nbrTrs)).val(1); } var totalonallines = 0; for (let i = 1; i <= nbrTrs; i++) { - console.log(i+" = "+parseFloat($("#qtytoproduce-"+index+"-"+i).val())); - totalonallines = totalonallines + parseFloat($("#qtytoproduce-"+index+"-"+i).val()); + console.log(i+" = "+parseFloat($("#"+inputId+"-"+index+"-"+i).val())); + totalonallines = totalonallines + parseFloat($("#"+inputId+"-"+index+"-"+i).val()); } console.log("totalonallines="+totalonallines); if (totalonallines == qtyOrdered && qtyOrdered > 1) { - var prevouslineqty = $("#qtytoproduce-"+index+"-"+nbrTrs).val(); - $("#qtytoproduce-"+index+"-"+(nbrTrs)).val(1); - $("#qtytoproduce-"+index+"-"+(nbrTrs+1)).val(prevouslineqty - 1); + var prevouslineqty = $("#"+inputId+"-"+index+"-"+nbrTrs).val(); + $("#"+inputId+"-"+index+"-"+(nbrTrs)).val(1); + $("#"+inputId+"-"+index+"-"+(nbrTrs+1)).val(prevouslineqty - 1); } $("#qty_dispatched_"+index).val(qtyDispatched); @@ -147,9 +153,9 @@ function addDispatchLine(index, type, mode) $("#qty_"+(nbrTrs-1)+"_"+index).val(qty); } // Store arbitrary data for dispatch qty input field change event - $("#qtytoproduce-"+index+(nbrTrs)).data('qty', qty); - $("#qtytoproduce-"+index+(nbrTrs)).data('type', type); - $("#qtytoproduce-"+index+(nbrTrs)).data('index', index); + $("#"+inputId+"-"+index+(nbrTrs)).data('qty', qty); + $("#"+inputId+"-"+index+(nbrTrs)).data('type', type); + $("#"+inputId+"-"+index+(nbrTrs)).data('index', index); } } diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index f83b32f1c99..6a5c41b77c5 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -1010,7 +1010,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($tmpproduct->type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { if (empty($line->disable_stock_change)) { $preselected = (GETPOSTISSET('idwarehouse-'.$line->id.'-'.$i) ? GETPOST('idwarehouse-'.$line->id.'-'.$i) : ($tmpproduct->fk_default_warehouse > 0 ? $tmpproduct->fk_default_warehouse : 'ifone')); - print $formproduct->selectWarehouses($preselected, 'idwarehouse-'.$line->id.'-'.$i, '', 1, 0, $line->fk_product, '', 1, 0, null, 'maxwidth200'); + print $formproduct->selectWarehouses($preselected, 'idwarehouse-'.$line->id.'-'.$i, '', 1, 0, $line->fk_product, '', 1, 0, null, 'maxwidth200 csswarehouse_'.$line->id.'_'.$i); } else { print ''.$langs->trans("DisableStockChange").''; }