26if (!defined(
'NOREQUIRESOC')) {
27 define(
'NOREQUIRESOC',
'1');
29if (!defined(
'NOCSRFCHECK')) {
30 define(
'NOCSRFCHECK', 1);
32if (!defined(
'NOTOKENRENEWAL')) {
33 define(
'NOTOKENRENEWAL', 1);
35if (!defined(
'NOLOGIN')) {
38if (!defined(
'NOREQUIREMENU')) {
39 define(
'NOREQUIREMENU', 1);
41if (!defined(
'NOREQUIREHTML')) {
42 define(
'NOREQUIREHTML', 1);
44if (!defined(
'NOREQUIREAJAX')) {
45 define(
'NOREQUIREAJAX',
'1');
48session_cache_limiter(
'public');
50require_once
'../../main.inc.php';
61$langs->loadLangs(array(
"mrp"));
66if (empty($dolibarr_nocache)) {
67 header(
'Cache-Control: max-age=10800, public, must-revalidate');
69 header(
'Cache-Control: no-cache');
81function addDispatchLine(index,
type, mode)
83 mode = mode ||
'qtymissing'
85 console.log(
"mrp/js/lib_dispatch.js.php Split line type="+
type+
" index="+index+
" mode="+mode);
86 if (mode ==
'qtymissingconsume' || mode ==
'allmissingconsume') {
87 var inputId =
'qtytoconsume';
88 var warehouseId =
'idwarehouse';
91 var inputId =
'qtytoproduce';
92 var warehouseId =
'idwarehousetoproduce';
94 var nbrTrs = $(
"tr[name^='"+
type+
"_"+index+
"']").length;
95 var $row = $(
"tr[name='"+
type+
'_'+index+
"_1']").clone(
true);
96 var qtyOrdered = parseFloat($(
"#qty_ordered_"+index).val());
97 var qty = parseFloat($(
"#"+inputId+
"-"+index+
"-"+nbrTrs).val());
99 console.log(
"#"+inputId+
"-"+index+
"-"+nbrTrs+
" => "+qty);
103 if (mode ===
'lessone')
105 qtyDispatched = parseFloat($(
"#qty_dispatched_"+index).val()) + 1;
109 console.log($(
"#qty_dispatched_"+index).val());
110 qtyDispatched = parseFloat($(
"#qty_dispatched_"+index).val()) + qty;
112 if (qtyDispatched == qtyOrdered && qtyDispatched > 1) {
113 qtyDispatched = parseFloat($(
"#qty_dispatched_" + index).val()) + 1;
115 if (mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
116 var qtymax = parseFloat($($row).data(
'max-qty'));
117 if (qtymax ===
'undefined') {
124 if (mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
126 var qtyalreadyused = 0;
129 while (qtyalreadyused < qty) {
131 if ((qtyalreadyused + qtymax) > qty) qtymax = qty - qtyalreadyused;
134 $(
"#"+inputId+
"-"+index+
"-"+nbrTrs).val(qtymax);
136 var res = addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qtymax, mode, $row);
143 qtyalreadyused = qtyalreadyused + qtymax;
145 $row = $(
"tr[name='" +
type +
'_' + index +
"_1']").clone(
true);
149 addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type,
'', mode, $row);
152 addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qty, mode, $row);
172function addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qty, mode, $row) {
173 if (qtyOrdered <= 1) {
174 let errormsg =
'<?php echo dol_escape_js($langs->trans('QtyCantBeSplit
')); ?>';
175 $.jnotify(errormsg,
'error',
true);
177 }
else if (qtyDispatched >= qtyOrdered) {
178 let errormsg =
'<?php echo dol_escape_js($langs->trans('NoRemainQtyToDispatch
')); ?>';
179 $.jnotify(errormsg,
'error',
true);
181 }
else if (qtyDispatched < qtyOrdered) {
183 var re1 =
new RegExp(
'_'+index+
'_1',
'g');
184 var re2 =
new RegExp(
'-'+index+
'-1',
'g');
185 $row.html($row.html().replace(re1,
'_'+index+
'_'+(nbrTrs+1)));
186 $row.html($row.html().replace(re2,
'-'+index+
'-'+(nbrTrs+1)));
188 $row.find(
"select[name='"+warehouseId+
'-'+index+
'-'+(nbrTrs+1)+
"']").select2();
192 $row.find(
"input[id^='"+inputId+
"']").val(
'');
194 $row.attr(
'name',
type+
'_'+index+
'_'+(nbrTrs+1));
196 $(
"tr[name^='"+
type+
"_"+index+
"_"+nbrTrs+
"']:last").after($row);
199 $(
"#s2id_entrepot_"+nbrTrs+
'_'+index).detach();
200 $(
".csswarehouse_"+index+
"_"+(nbrTrs+1)+
":first-child").parent(
"span.selection").parent(
".select2").detach();
203 $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs+1)).focus();
204 if ($(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val() == 0) {
205 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val(qty);
206 else $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val(1);
208 var totalonallines = 0;
209 for (let i = 1; i <= nbrTrs; i++) {
210 console.log(i+
" = "+parseFloat($(
"#"+inputId+
"-"+index+
"-"+i).val()));
211 totalonallines = totalonallines + parseFloat($(
"#"+inputId+
"-"+index+
"-"+i).val());
214 if(mode !=
'allmissingconsume' && mode !=
'alltoproduce') {
215 if (totalonallines == qtyOrdered && qtyOrdered > 1) {
216 var prevouslineqty = $(
"#" + inputId +
"-" + index +
"-" + nbrTrs).val();
217 $(
"#" + inputId +
"-" + index +
"-" + (nbrTrs)).val(1);
218 $(
"#" + inputId +
"-" + index +
"-" + (nbrTrs + 1)).val(prevouslineqty - 1);
221 $(
"#qty_dispatched_"+index).val(qtyDispatched);
224 $(
"tr[name^='"+
type+
"_"+index+
"_'] .splitbutton").hide();
225 $(
"tr[name^='"+
type+
"_"+index+
"_']:last .splitbutton").show();
227 if (mode ===
'lessone')
230 $(
"#qty_"+(nbrTrs-1)+
"_"+index).val(qty);
233 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'qty', qty);
234 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'type',
type);
235 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'index', index);
236 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
237 let currentQtyDispatched = qtyDispatched+qty;
238 $row.find(
"input[id^='"+inputId+
"']").val(qty);
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type