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';
51$langs->loadLangs(array(
"mrp"));
56if (empty($dolibarr_nocache)) {
57 header(
'Cache-Control: max-age=10800, public, must-revalidate');
59 header(
'Cache-Control: no-cache');
71function addDispatchLine(index,
type, mode)
73 mode = mode ||
'qtymissing'
75 console.log(
"mrp/js/lib_dispatch.js.php Split line type="+
type+
" index="+index+
" mode="+mode);
76 if(mode ==
'qtymissingconsume' || mode ==
'allmissingconsume') {
77 var inputId =
'qtytoconsume';
78 var warehouseId =
'idwarehouse';
81 var inputId =
'qtytoproduce';
82 var warehouseId =
'idwarehousetoproduce';
84 var nbrTrs = $(
"tr[name^='"+
type+
"_"+index+
"']").length;
85 var $row = $(
"tr[name='"+
type+
'_'+index+
"_1']").clone(
true);
86 var qtyOrdered = parseFloat($(
"#qty_ordered_"+index).val());
87 var qty = parseFloat($(
"#"+inputId+
"-"+index+
"-"+nbrTrs).val());
90 if (mode ===
'lessone')
92 qtyDispatched = parseFloat($(
"#qty_dispatched_"+index).val()) + 1;
96 qtyDispatched = parseFloat($(
"#qty_dispatched_"+index).val()) + qty;
97 console.log($(
"#qty_dispatched_"+index).val());
99 if (qtyDispatched == qtyOrdered && qtyDispatched > 1) {
100 qtyDispatched = parseFloat($(
"#qty_dispatched_" + index).val()) + 1;
103 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
104 var qtymax = parseFloat($($row).data(
'max-qty'));
105 if(qtymax ===
'undefined') qtymax = 1;
110 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
112 var qtyalreadyused = 0;
115 while (qtyalreadyused < qty) {
117 if ((qtyalreadyused + qtymax) > qty) qtymax = qty - qtyalreadyused;
120 $(
"#"+inputId+
"-"+index+
"-"+nbrTrs).val(qtymax);
122 var res = addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qtymax, mode, $row);
129 qtyalreadyused = qtyalreadyused + qtymax;
131 $row = $(
"tr[name='" +
type +
'_' + index +
"_1']").clone(
true);
135 addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type,
'', mode, $row);
138 else addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qty, mode, $row)
157function addDispatchTR(qtyOrdered, qtyDispatched, index, nbrTrs, warehouseId, inputId,
type, qty, mode, $row) {
158 if (qtyOrdered <= 1) {
159 let errormsg =
'<?php echo dol_escape_js($langs->trans('QtyCantBeSplit
')); ?>';
160 $.jnotify(errormsg,
'error',
true);
162 }
else if (qtyDispatched >= qtyOrdered) {
163 let errormsg =
'<?php echo dol_escape_js($langs->trans('NoRemainQtyToDispatch
')); ?>';
164 $.jnotify(errormsg,
'error',
true);
166 }
else if (qtyDispatched < qtyOrdered) {
168 var re1 =
new RegExp(
'_'+index+
'_1',
'g');
169 var re2 =
new RegExp(
'-'+index+
'-1',
'g');
170 $row.html($row.html().replace(re1,
'_'+index+
'_'+(nbrTrs+1)));
171 $row.html($row.html().replace(re2,
'-'+index+
'-'+(nbrTrs+1)));
173 $row.find(
"select[name='"+warehouseId+
'-'+index+
'-'+(nbrTrs+1)+
"']").select2();
177 $row.find(
"input[id^='"+inputId+
"']").val(
'');
179 $row.attr(
'name',
type+
'_'+index+
'_'+(nbrTrs+1));
181 $(
"tr[name^='"+
type+
"_"+index+
"_"+nbrTrs+
"']:last").after($row);
184 $(
"#s2id_entrepot_"+nbrTrs+
'_'+index).detach();
185 $(
".csswarehouse_"+index+
"_"+(nbrTrs+1)+
":first-child").parent(
"span.selection").parent(
".select2").detach();
188 $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs+1)).focus();
189 if ($(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val() == 0) {
190 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val(qty);
191 else $(
"#"+inputId+
"-"+index+
"-"+(nbrTrs)).val(1);
193 var totalonallines = 0;
194 for (let i = 1; i <= nbrTrs; i++) {
195 console.log(i+
" = "+parseFloat($(
"#"+inputId+
"-"+index+
"-"+i).val()));
196 totalonallines = totalonallines + parseFloat($(
"#"+inputId+
"-"+index+
"-"+i).val());
199 if(mode !=
'allmissingconsume' && mode !=
'alltoproduce') {
200 if (totalonallines == qtyOrdered && qtyOrdered > 1) {
201 var prevouslineqty = $(
"#" + inputId +
"-" + index +
"-" + nbrTrs).val();
202 $(
"#" + inputId +
"-" + index +
"-" + (nbrTrs)).val(1);
203 $(
"#" + inputId +
"-" + index +
"-" + (nbrTrs + 1)).val(prevouslineqty - 1);
206 $(
"#qty_dispatched_"+index).val(qtyDispatched);
209 $(
"tr[name^='"+
type+
"_"+index+
"_'] .splitbutton").hide();
210 $(
"tr[name^='"+
type+
"_"+index+
"_']:last .splitbutton").show();
212 if (mode ===
'lessone')
215 $(
"#qty_"+(nbrTrs-1)+
"_"+index).val(qty);
218 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'qty', qty);
219 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'type',
type);
220 $(
"#"+inputId+
"-"+index+(nbrTrs)).data(
'index', index);
221 if(mode ==
'allmissingconsume' || mode ==
'alltoproduce') {
222 let currentQtyDispatched = qtyDispatched+qty;
223 $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