From 4de5ee97b35dd4a18297b9bff18a692d9c3e7ef7 Mon Sep 17 00:00:00 2001 From: Quentin VIAL-GOUTEYRON Date: Tue, 25 Jan 2022 16:37:33 +0100 Subject: [PATCH] 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").''; }