diff --git a/htdocs/mrp/js/lib_dispatch.js.php b/htdocs/mrp/js/lib_dispatch.js.php index 8a5eef60211..d8285ac75c1 100644 --- a/htdocs/mrp/js/lib_dispatch.js.php +++ b/htdocs/mrp/js/lib_dispatch.js.php @@ -70,10 +70,18 @@ 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'; + 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 - var qty = parseFloat($("#qtytoproduce-"+index+"-"+nbrTrs).val()); + var qty = parseFloat($("#"+inputId+"-"+index+"-"+nbrTrs).val()); var qtyDispatched; if (mode === 'lessone') @@ -83,7 +91,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; @@ -103,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 @@ -118,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); @@ -145,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 bc1a0457325..6a5c41b77c5 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -838,6 +838,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 '