24if (!defined(
'NOREQUIRESOC')) {
25 define(
'NOREQUIRESOC',
'1');
27if (!defined(
'NOCSRFCHECK')) {
28 define(
'NOCSRFCHECK', 1);
30if (!defined(
'NOTOKENRENEWAL')) {
31 define(
'NOTOKENRENEWAL', 1);
33if (!defined(
'NOLOGIN')) {
36if (!defined(
'NOREQUIREMENU')) {
37 define(
'NOREQUIREMENU', 1);
39if (!defined(
'NOREQUIREHTML')) {
40 define(
'NOREQUIREHTML', 1);
42if (!defined(
'NOREQUIREAJAX')) {
43 define(
'NOREQUIREAJAX',
'1');
46session_cache_limiter(
'public');
48require_once
'../../main.inc.php';
53if (empty($dolibarr_nocache)) {
54 header(
'Cache-Control: max-age=10800, public, must-revalidate');
56 header(
'Cache-Control: no-cache');
68function addDispatchLine(index,
type, mode)
70 mode = mode ||
'qtymissing'
72 console.log(
"mrp/js/lib_dispatch.js.php Split line type="+
type+
" index="+index+
" mode="+mode);
73 if(mode ==
'qtymissingconsume' || mode ==
'allmissingconsume') {
74 var inputId =
'qtytoconsume';
75 var warehouseId =
'idwarehouse';
78 var inputId =
'qtytoproduce';
79 var warehouseId =
'idwarehousetoproduce';
81 var nbrTrs = $(
"tr[name^='"+
type+
"_"+index+
"']").length;
82 var $row = $(
"tr[name='"+
type+
'_'+index+
"_1']").clone(
true);
83 var qtyOrdered = parseFloat($(
"#qty_ordered_"+index).val());
84 var qty = parseFloat($(
"#"+inputId+
"-"+index+
"-"+nbrTrs).val());
87 if (mode ===
'lessone')
89 qtyDispatched = parseFloat($(
"#qty_dispatched_"+index).val()) + 1;
93 qtyDispatched = parseFloat($(
"#qty_dispatched_"+index).val()) + qty;
94 console.log($(
"#qty_dispatched_"+index).val());
96 if (qtyDispatched == qtyOrdered && qtyDispatched > 1) {
97 qtyDispatched = parseFloat($(
"#qty_dispatched_" + index).val()) + 1;
100 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
101 var qtymax = parseFloat($($row).data(
'max-qty'));
102 if(qtymax ===
'undefined') qtymax = 1;
107 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
109 var qtyalreadyused = 0;
112 while (qtyalreadyused < qty) {
114 if ((qtyalreadyused + qtymax) > qty) qtymax = qty - qtyalreadyused;
117 $(
"#"+inputId+
"-"+index+
"-"+nbrTrs).val(qtymax);
119 var res = addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qtymax, mode, $row);
126 qtyalreadyused = qtyalreadyused + qtymax;
128 $row = $(
"tr[name='" +
type +
'_' + index +
"_1']").clone(
true);
132 addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type,
'', mode, $row);
135 else addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qty, mode, $row)
154function addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qty, mode, $row) {
155 if (qtyOrdered <= 1) {
156 window.alert(
"Quantity can't be split");
158 }
else if (qtyDispatched >= qtyOrdered) {
159 window.alert(
"No remain qty to dispatch");
161 }
else if (qtyDispatched < qtyOrdered) {
163 var re1 =
new RegExp(
'_'+index+
'_1',
'g');
164 var re2 =
new RegExp(
'-'+index+
'-1',
'g');
165 $row.html($row.html().replace(re1,
'_'+index+
'_'+(nbrTrs+1)));
166 $row.html($row.html().replace(re2,
'-'+index+
'-'+(nbrTrs+1)));
168 $row.find(
"select[name='"+warehouseId+
'-'+index+
'-'+(nbrTrs+1)+
"']").select2();
172 $row.find(
"input[id^='"+inputId+
"']").val(
'');
174 $row.attr(
'name',
type+
'_'+index+
'_'+(nbrTrs+1));
176 $(
"tr[name^='"+
type+
"_"+index+
"_"+nbrTrs+
"']:last").after($row);
179 $(
"#s2id_entrepot_"+nbrTrs+
'_'+index).detach();
180 $(
".csswarehouse_"+index+
"_"+(nbrTrs+1)+
":first-child").parent(
"span.selection").parent(
".select2").detach();
183 $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs+1)).focus();
184 if ($(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val() == 0) {
185 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val(qty);
186 else $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val(1);
188 var totalonallines = 0;
189 for (let i = 1; i <= nbrTrs; i++) {
190 console.log(i+
" = "+parseFloat($(
"#"+inputId+
"-"+index+
"-"+i).val()));
191 totalonallines = totalonallines + parseFloat($(
"#"+inputId+
"-"+index+
"-"+i).val());
194 if(mode !=
'allmissingconsume' && mode !=
'alltoproduce') {
195 if (totalonallines == qtyOrdered && qtyOrdered > 1) {
196 var prevouslineqty = $(
"#" + inputId +
"-" + index +
"-" + nbrTrs).val();
197 $(
"#" + inputId +
"-" + index +
"-" + (nbrTrs)).val(1);
198 $(
"#" + inputId +
"-" + index +
"-" + (nbrTrs + 1)).val(prevouslineqty - 1);
201 $(
"#qty_dispatched_"+index).val(qtyDispatched);
204 $(
"tr[name^='"+
type+
"_"+index+
"_'] .splitbutton").hide();
205 $(
"tr[name^='"+
type+
"_"+index+
"_']:last .splitbutton").show();
207 if (mode ===
'lessone')
210 $(
"#qty_"+(nbrTrs-1)+
"_"+index).val(qty);
213 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'qty', qty);
214 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'type',
type);
215 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'index', index);
216 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
217 let currentQtyDispatched = qtyDispatched+qty;
218 $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