FIX mode de calcul splitall
This commit is contained in:
parent
17af973da3
commit
4a6b854963
@ -107,22 +107,30 @@ function addDispatchLine(index, type, mode)
|
|||||||
if(mode == 'allmissingconsume' || mode == 'alltoproduce') {
|
if(mode == 'allmissingconsume' || mode == 'alltoproduce') {
|
||||||
var count = 0;
|
var count = 0;
|
||||||
var qtyalreadyused = 0;
|
var qtyalreadyused = 0;
|
||||||
|
var error = 0;
|
||||||
|
|
||||||
while (count < qty) {
|
while (qtyalreadyused < qty) {
|
||||||
//If remaining qty needed is inferior to qtymax, qtymax = remaining qty needed
|
//If remaining qty needed is inferior to qty asked, qtymax = qty asked - qty already used
|
||||||
if ((qtyalreadyused + qtymax) > qtyOrdered) qtymax = qtyOrdered - qtyalreadyused;
|
if ((qtyalreadyused + qtymax) > qty) qtymax = qty - qtyalreadyused;
|
||||||
//If first line, we replace value, not add line
|
//If first line, we replace value, not add line
|
||||||
if(count === 0){
|
if(count === 0){
|
||||||
$("#"+inputId+"-"+index+"-"+nbrTrs).val(qtymax);
|
$("#"+inputId+"-"+index+"-"+nbrTrs).val(qtymax);
|
||||||
} else {
|
} else {
|
||||||
addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId, type, qtymax, mode, $row);
|
var res = addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId, type, qtymax, mode, $row);
|
||||||
|
if(res === -1){
|
||||||
|
error = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
nbrTrs++;
|
nbrTrs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
qtyalreadyused = qtyalreadyused + qtymax;
|
qtyalreadyused = qtyalreadyused + qtymax;
|
||||||
count++;
|
count++;
|
||||||
$row = $("tr[name='" + type + '_' + index + "_1']").clone(true);
|
$row = $("tr[name='" + type + '_' + index + "_1']").clone(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(error === 0) {
|
||||||
|
addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId, type, '', mode, $row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId, type, qty, mode, $row)
|
else addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId, type, qty, mode, $row)
|
||||||
|
|
||||||
@ -146,8 +154,10 @@ function addDispatchLine(index, type, mode)
|
|||||||
function addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId, type, qty, mode, $row) {
|
function addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId, type, qty, mode, $row) {
|
||||||
if (qtyOrdered <= 1) {
|
if (qtyOrdered <= 1) {
|
||||||
window.alert("Quantity can't be split");
|
window.alert("Quantity can't be split");
|
||||||
|
return -1;
|
||||||
} else if (qtyDispatched >= qtyOrdered) {
|
} else if (qtyDispatched >= qtyOrdered) {
|
||||||
window.alert("No remain qty to dispatch");
|
window.alert("No remain qty to dispatch");
|
||||||
|
return -1;
|
||||||
} else if (qtyDispatched < qtyOrdered) {
|
} else if (qtyDispatched < qtyOrdered) {
|
||||||
//replace tr suffix nbr
|
//replace tr suffix nbr
|
||||||
var re1 = new RegExp('_'+index+'_1', 'g');
|
var re1 = new RegExp('_'+index+'_1', 'g');
|
||||||
@ -205,8 +215,6 @@ function addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, in
|
|||||||
$("#"+inputId+"-"+index+(nbrTrs)).data('index', index);
|
$("#"+inputId+"-"+index+(nbrTrs)).data('index', index);
|
||||||
if(mode == 'allmissingconsume' || mode == 'alltoproduce') {
|
if(mode == 'allmissingconsume' || mode == 'alltoproduce') {
|
||||||
let currentQtyDispatched = qtyDispatched+qty;
|
let currentQtyDispatched = qtyDispatched+qty;
|
||||||
console.log( $row.find("input[id^='"+inputId+"']"));
|
|
||||||
if((currentQtyDispatched+qty) > qtyOrdered) $row.find("input[id^='"+inputId+"']").val(qtyOrdered - currentQtyDispatched);
|
|
||||||
$row.find("input[id^='"+inputId+"']").val(qty);
|
$row.find("input[id^='"+inputId+"']").val(qty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user