Merge pull request #19924 from atm-quentin/NEW_Multiple_batch_consume

NEW : split consumption line on MO
This commit is contained in:
Laurent Destailleur 2022-01-26 12:07:41 +01:00 committed by GitHub
commit ab610a90ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 18 deletions

View File

@ -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);
}
}

View File

@ -838,6 +838,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$alreadyconsumed += $line2['qty'];
}
$suffix = '_'.$line->id;
print '<!-- Line to dispatch '.$suffix.' -->'."\n";
// hidden fields for js function
print '<input id="qty_ordered'.$suffix.'" type="hidden" value="'.$line->qty.'">';
print '<input id="qty_dispatched'.$suffix.'" type="hidden" value="'.$alreadyconsumed.'">';
print '<tr>';
// Product
print '<td>'.$tmpproduct->getNomUrl(1);
@ -976,7 +982,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
$i = 1;
print '<!-- Enter line to consume -->'."\n";
print '<tr>';
print '<tr name="batch_'.$line->id.'_'.$i.'">';
print '<td><span class="opacitymedium">'.$langs->trans("ToConsume").'</span></td>';
$preselected = (GETPOSTISSET('qty-'.$line->id.'-'.$i) ? GETPOST('qty-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyconsumed));
if ($action == 'consumeorproduce' && !GETPOSTISSET('qty-'.$line->id.'-'.$i)) {
@ -989,7 +995,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}
// Qty
print '<td class="right"><input type="text" class="width50 right" name="qty-'.$line->id.'-'.$i.'" value="'.$preselected.'" '.$disable.' ></td>';
print '<td class="right"><input type="text" class="width50 right" id="qtytoconsume-'.$line->id.'-'.$i.'" name="qty-'.$line->id.'-'.$i.'" value="'.$preselected.'" '.$disable.'></td>';
// Cost
if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
@ -1004,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 '<span class="opacitymedium">'.$langs->trans("DisableStockChange").'</span>';
}
@ -1027,6 +1033,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 0, $line->fk_product, '', '');
}
print '</td>';
print '<td>';
if ($tmpproduct->status_batch) {
$type = 'batch';
print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$line->id.', \''.$type.'\', \'qtymissingconsume\')"');
}
print '</td>';
}
// Action delete line