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());
100 if (mode ===
'lessone')
102 qtyDispatched = parseFloat($(
"#qty_dispatched_"+index).val()) + 1;
106 qtyDispatched = parseFloat($(
"#qty_dispatched_"+index).val()) + qty;
107 console.log($(
"#qty_dispatched_"+index).val());
109 if (qtyDispatched == qtyOrdered && qtyDispatched > 1) {
110 qtyDispatched = parseFloat($(
"#qty_dispatched_" + index).val()) + 1;
113 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
114 var qtymax = parseFloat($($row).data(
'max-qty'));
115 if(qtymax ===
'undefined') qtymax = 1;
120 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
122 var qtyalreadyused = 0;
125 while (qtyalreadyused < qty) {
127 if ((qtyalreadyused + qtymax) > qty) qtymax = qty - qtyalreadyused;
130 $(
"#"+inputId+
"-"+index+
"-"+nbrTrs).val(qtymax);
132 var res = addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qtymax, mode, $row);
139 qtyalreadyused = qtyalreadyused + qtymax;
141 $row = $(
"tr[name='" +
type +
'_' + index +
"_1']").clone(
true);
145 addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type,
'', mode, $row);
148 else addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qty, mode, $row)
167function addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qty, mode, $row) {
168 if (qtyOrdered <= 1) {
169 let errormsg =
'<?php echo dol_escape_js($langs->trans('QtyCantBeSplit
')); ?>';
170 $.jnotify(errormsg,
'error',
true);
172 }
else if (qtyDispatched >= qtyOrdered) {
173 let errormsg =
'<?php echo dol_escape_js($langs->trans('NoRemainQtyToDispatch
')); ?>';
174 $.jnotify(errormsg,
'error',
true);
176 }
else if (qtyDispatched < qtyOrdered) {
178 var re1 =
new RegExp(
'_'+index+
'_1',
'g');
179 var re2 =
new RegExp(
'-'+index+
'-1',
'g');
180 $row.html($row.html().replace(re1,
'_'+index+
'_'+(nbrTrs+1)));
181 $row.html($row.html().replace(re2,
'-'+index+
'-'+(nbrTrs+1)));
183 $row.find(
"select[name='"+warehouseId+
'-'+index+
'-'+(nbrTrs+1)+
"']").select2();
187 $row.find(
"input[id^='"+inputId+
"']").val(
'');
189 $row.attr(
'name',
type+
'_'+index+
'_'+(nbrTrs+1));
191 $(
"tr[name^='"+
type+
"_"+index+
"_"+nbrTrs+
"']:last").after($row);
194 $(
"#s2id_entrepot_"+nbrTrs+
'_'+index).detach();
195 $(
".csswarehouse_"+index+
"_"+(nbrTrs+1)+
":first-child").parent(
"span.selection").parent(
".select2").detach();
198 $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs+1)).focus();
199 if ($(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val() == 0) {
200 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val(qty);
201 else $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val(1);
203 var totalonallines = 0;
204 for (let i = 1; i <= nbrTrs; i++) {
205 console.log(i+
" = "+parseFloat($(
"#"+inputId+
"-"+index+
"-"+i).val()));
206 totalonallines = totalonallines + parseFloat($(
"#"+inputId+
"-"+index+
"-"+i).val());
209 if(mode !=
'allmissingconsume' && mode !=
'alltoproduce') {
210 if (totalonallines == qtyOrdered && qtyOrdered > 1) {
211 var prevouslineqty = $(
"#" + inputId +
"-" + index +
"-" + nbrTrs).val();
212 $(
"#" + inputId +
"-" + index +
"-" + (nbrTrs)).val(1);
213 $(
"#" + inputId +
"-" + index +
"-" + (nbrTrs + 1)).val(prevouslineqty - 1);
216 $(
"#qty_dispatched_"+index).val(qtyDispatched);
219 $(
"tr[name^='"+
type+
"_"+index+
"_'] .splitbutton").hide();
220 $(
"tr[name^='"+
type+
"_"+index+
"_']:last .splitbutton").show();
222 if (mode ===
'lessone')
225 $(
"#qty_"+(nbrTrs-1)+
"_"+index).val(qty);
228 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'qty', qty);
229 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'type',
type);
230 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'index', index);
231 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
232 let currentQtyDispatched = qtyDispatched+qty;
233 $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