mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-18 15:31:28 +01:00
Traitement du splitall
This commit is contained in:
@@ -70,7 +70,7 @@ function addDispatchLine(index, type, mode)
|
|||||||
mode = mode || 'qtymissing'
|
mode = mode || 'qtymissing'
|
||||||
|
|
||||||
console.log("fourn/js/lib_dispatch.js.php Split line type="+type+" index="+index+" mode="+mode);
|
console.log("fourn/js/lib_dispatch.js.php Split line type="+type+" index="+index+" mode="+mode);
|
||||||
if(mode == 'qtymissingconsume') {
|
if(mode == 'qtymissingconsume' || mode == 'allmissingconsume') {
|
||||||
var inputId = 'qtytoconsume';
|
var inputId = 'qtytoconsume';
|
||||||
var warehouseId = 'idwarehouse';
|
var warehouseId = 'idwarehouse';
|
||||||
}
|
}
|
||||||
@@ -94,12 +94,56 @@ function addDispatchLine(index, type, mode)
|
|||||||
console.log($("#qty_dispatched_"+index).val());
|
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 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) {
|
if (qtyDispatched == qtyOrdered && qtyDispatched > 1) {
|
||||||
qtyDispatched = parseFloat($("#qty_dispatched_"+index).val()) + 1;
|
qtyDispatched = parseFloat($("#qty_dispatched_" + index).val()) + 1;
|
||||||
mode = 'lessone';
|
if (mode != 'allmissingconsume' || mode != 'alltoproduce') mode = 'lessone';
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log("qtyDispatched="+qtyDispatched+" qtyOrdered="+qtyOrdered);
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if(mode == 'allmissingconsume' || mode == 'alltoproduce') {
|
||||||
|
var qtymax = parseFloat($($row).data('max-qty'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mode == 'allmissingconsume' || mode == 'alltoproduce') {
|
||||||
|
var count = 0;
|
||||||
|
var qtyalreadyused = 0;
|
||||||
|
|
||||||
|
while (count < qty) {
|
||||||
|
//If remaining qty needed is inferior to qtymax, qtymax = remaining qty needed
|
||||||
|
if ((qtyalreadyused + qtymax) > qtyOrdered) qtymax = qtyOrdered - qtyalreadyused;
|
||||||
|
|
||||||
|
//If first line, we replace value, not add line
|
||||||
|
if(count === 0){
|
||||||
|
$("#"+inputId+"-"+index+"-"+nbrTrs).val(qtymax);
|
||||||
|
} else {
|
||||||
|
addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId, type, qtymax, mode, $row);
|
||||||
|
nbrTrs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
qtyalreadyused = qtyalreadyused + qtymax;
|
||||||
|
count++;
|
||||||
|
$row = $("tr[name='" + type + '_' + index + "_1']").clone(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId, type, qty, mode, $row)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* addDispatchTR
|
||||||
|
* Adds new table row for dispatching to multiple stock locations or multiple lot/serial
|
||||||
|
*
|
||||||
|
* @param qtyOrdered double
|
||||||
|
* @param qtyDispatched double
|
||||||
|
* @param index int
|
||||||
|
* @param nbrTrs int
|
||||||
|
* @param warehouseId int
|
||||||
|
* @param inputId int
|
||||||
|
* @param type string
|
||||||
|
* @param qty double
|
||||||
|
* @param mode string
|
||||||
|
* @param $row object
|
||||||
|
*/
|
||||||
|
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");
|
||||||
} else if (qtyDispatched >= qtyOrdered) {
|
} else if (qtyDispatched >= qtyOrdered) {
|
||||||
@@ -128,24 +172,27 @@ function addDispatchLine(index, type, mode)
|
|||||||
/* Suffix of lines are: index _ trs.length */
|
/* Suffix of lines are: index _ trs.length */
|
||||||
$("#"+inputId+"-"+index+"-"+(nbrTrs+1)).focus();
|
$("#"+inputId+"-"+index+"-"+(nbrTrs+1)).focus();
|
||||||
if ($("#"+inputId+"-"+index+"-"+(nbrTrs)).val() == 0) {
|
if ($("#"+inputId+"-"+index+"-"+(nbrTrs)).val() == 0) {
|
||||||
$("#"+inputId+"-"+index+"-"+(nbrTrs)).val(1);
|
if(mode == 'allmissingconsume' || mode == 'alltoproduce') $("#"+inputId+"-"+index+"-"+(nbrTrs)).val(qty);
|
||||||
|
else $("#"+inputId+"-"+index+"-"+(nbrTrs)).val(1);
|
||||||
}
|
}
|
||||||
var totalonallines = 0;
|
var totalonallines = 0;
|
||||||
for (let i = 1; i <= nbrTrs; i++) {
|
for (let i = 1; i <= nbrTrs; i++) {
|
||||||
console.log(i+" = "+parseFloat($("#"+inputId+"-"+index+"-"+i).val()));
|
console.log(i+" = "+parseFloat($("#"+inputId+"-"+index+"-"+i).val()));
|
||||||
totalonallines = totalonallines + parseFloat($("#"+inputId+"-"+index+"-"+i).val());
|
totalonallines = totalonallines + parseFloat($("#"+inputId+"-"+index+"-"+i).val());
|
||||||
}
|
}
|
||||||
console.log("totalonallines="+totalonallines);
|
|
||||||
|
if(mode != 'allmissingconsume' && mode != 'alltoproduce') {
|
||||||
if (totalonallines == qtyOrdered && qtyOrdered > 1) {
|
if (totalonallines == qtyOrdered && qtyOrdered > 1) {
|
||||||
var prevouslineqty = $("#"+inputId+"-"+index+"-"+nbrTrs).val();
|
var prevouslineqty = $("#" + inputId + "-" + index + "-" + nbrTrs).val();
|
||||||
$("#"+inputId+"-"+index+"-"+(nbrTrs)).val(1);
|
$("#" + inputId + "-" + index + "-" + (nbrTrs)).val(1);
|
||||||
$("#"+inputId+"-"+index+"-"+(nbrTrs+1)).val(prevouslineqty - 1);
|
$("#" + inputId + "-" + index + "-" + (nbrTrs + 1)).val(prevouslineqty - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$("#qty_dispatched_"+index).val(qtyDispatched);
|
$("#qty_dispatched_"+index).val(qtyDispatched);
|
||||||
|
|
||||||
//hide all buttons then show only the last one
|
//hide all buttons then show only the last one
|
||||||
$("tr[name^='"+type+"_'][name$='_"+index+"'] .splitbutton").hide();
|
$("tr[name^='"+type+"_"+index+"_'] .splitbutton").hide();
|
||||||
$("tr[name^='"+type+"_'][name$='_"+index+"']:last .splitbutton").show();
|
$("tr[name^='"+type+"_"+index+"_']:last .splitbutton").show();
|
||||||
|
|
||||||
if (mode === 'lessone')
|
if (mode === 'lessone')
|
||||||
{
|
{
|
||||||
@@ -156,6 +203,12 @@ function addDispatchLine(index, type, mode)
|
|||||||
$("#"+inputId+"-"+index+(nbrTrs)).data('qty', qty);
|
$("#"+inputId+"-"+index+(nbrTrs)).data('qty', qty);
|
||||||
$("#"+inputId+"-"+index+(nbrTrs)).data('type', type);
|
$("#"+inputId+"-"+index+(nbrTrs)).data('type', type);
|
||||||
$("#"+inputId+"-"+index+(nbrTrs)).data('index', index);
|
$("#"+inputId+"-"+index+(nbrTrs)).data('index', index);
|
||||||
|
if(mode == 'allmissingconsume' || mode == 'alltoproduce') {
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1071,7 +1071,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
print ' '.img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.((int) $line->id).', \''.dol_escape_js($type).'\', \'qtymissingconsume\')"');
|
print ' '.img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.((int) $line->id).', \''.dol_escape_js($type).'\', \'qtymissingconsume\')"');
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td align="right" class="splitall">';
|
print '<td align="right" class="splitall">';
|
||||||
if (($action == 'consumeorproduce' || $action == 'consumeandproduceall') && $tmpproduct->status_batch == 2) print img_picto($langs->trans('SplitAllQuantity'), 'split.png', 'class="splitbutton splitallbutton field-error-icon" data-max-qty="1" onClick="addDispatchLine('.$line->id.', \'batch\', \'allmissingconsume\')"');
|
if (($action == 'consumeorproduce' || $action == 'consumeandproduceall')) print img_picto($langs->trans('SplitAllQuantity'), 'split.png', 'class="splitbutton splitallbutton field-error-icon" data-max-qty="1" onClick="addDispatchLine('.$line->id.', \'batch\', \'allmissingconsume\')"');
|
||||||
print '</td>';
|
print '</td>';
|
||||||
}
|
}
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|||||||
Reference in New Issue
Block a user