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';
54$langs->loadLangs(array(
"productbatch"));
59header(
'Cache-Control: max-age=10800, public, must-revalidate');
71function addDispatchLine(index,
type, mode, lotnumber) {
72 mode = mode ||
'qtymissing'
73 lotnumber = lotnumber ||
''
75 console.log(
"fourn/js/lib_dispatch.js.php addDispatchLine Split line type="+
type+
" index="+index+
" mode="+mode);
77 var $row0 = $(
"tr[name='"+
type+
'_0_'+index+
"']");
78 var $dpopt = $row0.find(
'.hasDatepicker').first().datepicker(
'option',
'all');
79 var $row = $row0.clone(
true);
80 var nbrTrs = $(
"tr[name^='"+
type+
"_'][name$='_"+index+
"']").length;
81 var qtyOrdered = parseFloat($(
"#qty_ordered_0_"+index).val());
83 var qty = parseFloat($(
"#qty_"+(nbrTrs - 1)+
"_"+index).val());
88 console.log(
"fourn/js/lib_dispatch.js.php addDispatchLine Split line nbrTrs="+nbrTrs+
" qtyOrdered="+qtyOrdered+
" qty="+qty);
92 if (mode ===
'lessone') {
93 qtyDispatched = parseFloat($(
"#qty_dispatched_0_" + index).val()) + 1;
96 qtyDispatched = parseFloat($(
"#qty_dispatched_0_" + index).val()) + qty;
98 if (lotnumber ===
'' && qtyDispatched == qtyOrdered && qtyDispatched > 1) {
99 qtyDispatched = parseFloat($(
"#qty_dispatched_0_" + index).val()) + 1;
103 console.log(
"qtyDispatched=" + qtyDispatched +
" qtyOrdered=" + qtyOrdered+
" qty=" + qty);
105 if (qty <= 1 && lotnumber ===
'') {
106 window.alert(
"Remain quantity to dispatch is too low to be split");
108 var oldlineqty = qtyDispatched;
109 var newlineqty = qtyOrdered - qtyDispatched;
110 if (lotnumber !==
'') {
112 }
else if (newlineqty <= 0) {
113 newlineqty = qty - 1;
115 $(
"#qty_"+(nbrTrs - 1)+
"_"+index).val(oldlineqty);
119 $row.html($row.html().replace(/_0_/g,
"_" + nbrTrs +
"_"));
124 $row.find(
'.hasDatepicker').each((i, dp) => {
126 .removeClass(
'hasDatepicker');
127 $(dp).next(
'img.ui-datepicker-trigger').remove();
128 $(dp).datepicker($dpopt);
133 $row.find(
"select[name='" +
'entrepot_' + nbrTrs +
'_' + index +
"']").select2();
135 let $prevRow = $(
"tr[name^='" +
type +
"_'][name$='_" + index +
"']:last")
136 let $prevEntr = Number($prevRow.find("select[
name='" + 'entrepot_' + (nbrTrs-1) + '_' + index + "']").val())
137 $row.find("select[
name='" + 'entrepot_' + nbrTrs + '_' + index + "']").val($prevEntr)
140 $row.find("input[
name^='qty']").val('');
142 $row.attr('
name',
type + '_' + nbrTrs + '_' + index);
144 $("tr[
name^='" +
type + "_'][name$='_" + index + "']:last").after($row);
147 $("
#s2id_entrepot_" + nbrTrs + '_' + index).detach(); // old way to find duplicated select2 component
148 $(".csswarehouse_" + nbrTrs + "_" + index + ":first-child").parent("span.selection").parent(".select2").detach();
150 /* Suffix of lines are: _ trs.length _ index */
151 $("#qty_"+nbrTrs+"_"+index).focus();
152 $("#qty_dispatched_0_"+index).val(oldlineqty);
154 //hide all buttons then show only the last one
155 $("tr[name^='" + type + "_'][name$='_" + index + "'] .splitbutton").hide();
156 $("tr[name^='" + type + "_'][name$='_" + index + "']:last .splitbutton").show();
158 $("#reset_" + (nbrTrs) + "_" + index).click(function (event) {
159 event.preventDefault();
160 id = $(this).attr("id");
161 id = id.split("reset_");
163 idlast = $("tr[name^='" + type + "_'][name$='_" + index + "']:last .qtydispatchinput").attr("id");
164 if (idlast == $("#qty_" + idrow).attr("id")) {
165 console.log("Remove trigger for tr name = " + type + "_" + idrow);
166 $('tr[name="' + type + '_' + idrow + '"').remove();
167 $("tr[name^='" + type + "_'][name$='_" + index + "']:last .splitbutton").show();
169 console.log("fourn/js/lib_dispatch.js.php Reset trigger for id = qty_" + idrow);
170 $("#qty_" + idrow).val("");
174 if (mode === 'lessone')
176 qty = 1; // keep 1 in old line
177 $("#qty_"+(nbrTrs-1)+"_"+index).val(qty);
179 $("#qty_"+nbrTrs+"_"+index).val(newlineqty);
180 // Store arbitrary data for dispatch qty input field change event
181 $("#qty_" + (nbrTrs - 1) + "_" + index).data('qty', qty);
182 $("#qty_" + (nbrTrs - 1) + "_" + index).data('type', type);
183 $("#qty_" + (nbrTrs - 1) + "_" + index).data('index', index);
184 // Update dispatched qty when value dispatch qty input field changed
185 //$("#qty_" + (nbrTrs - 1) + "_" + index).change(this.onChangeDispatchLineQty);
186 //set focus on lot of new line (if it exists)
187 $("#lot_number_" + (nbrTrs) + "_" + index).focus();
189 $("tr[name^='" + type + "_'][name$='_" + index + "']:last").data("remove", "remove");
190 $("#lot_number_" + (nbrTrs) + "_" + index).val(lotnumber)
191 $("#idline_" + (nbrTrs) + "_" + index).val("-1")
192 $("#qty_" + (nbrTrs) + "_" + index).data('expected', "0");
193 $("#lot_number_" + (nbrTrs) + "_" + index).removeAttr("disabled");
206function addDispatchLinesFromSerialList(index, type) {
207 console.log("fourn/js/lib_dispatch.js.php addDispatchLinesFromSerialList type="+type+" index="+index);
209 var $dialog = jQuery("#dialogforpopup");
210 var html = '<textarea id="seriallist" class="centpercent" rows="10" placeholder="<?php echo dol_escape_js(dol_escape_htmltag($langs->transnoentitiesnoconv("EnterOneSerialNumberPerLine"))); ?>"></textarea>';
211 html += '<div id="seriallistmessage" class="opacitymedium paddingtop"></div>';
214 // Return the list of non empty trimmed lines
215 var getSerialList = function() {
216 return jQuery("#seriallist").val().split(/\r\n|\r|\n/).map(function(s) { return s.trim(); }).filter(function(s) { return s !== ''; });
219 jQuery("#seriallist").on("input", function() {
220 jQuery("#seriallistmessage").removeClass("error").text('<?php echo dol_escape_js($langs->transnoentitiesnoconv("NbOfSerialNumbersDetected", "%s")); ?>'.replace('%s', getSerialList().length));
224 title: '<?php echo dol_escape_js($langs->transnoentitiesnoconv("EnterMultipleSerialNumbers")); ?>',
230 text: '<?php echo dol_escape_js($langs->transnoentitiesnoconv("Apply")); ?>',
232 var serials = getSerialList();
233 if (serials.length == 0) {
236 // Cheap early check of duplicates inside the list. Uniqueness in stock is still checked by MouvementStock.
238 for (var n = 0; n < serials.length; n++) {
239 if (seen[serials[n]]) {
240 jQuery("#seriallistmessage").addClass("error").text('<?php echo dol_escape_js($langs->transnoentitiesnoconv("ErrorDuplicateSerialNumberInList", "%s")); ?>'.replace('%s', serials[n]));
243 seen[serials[n]] = true;
246 var nbrTrs = $("tr[name^='"+type+"_'][name$='_"+index+"']").length;
247 var $lastlot = $("#lot_number_"+(nbrTrs - 1)+"_"+index);
249 // Reuse the last line if it is still empty (not a saved line and no lot/serial entered yet)
250 if (!$lastlot.prop('disabled') && $lastlot.val().trim() === '') {
251 $lastlot.val(serials[0]);
252 $("#qty_"+(nbrTrs - 1)+"_"+index).val(1);
255 for (; k < serials.length; k++) {
256 addDispatchLine(index, type, 'qtymissing', serials[k]);
259 jQuery(this).dialog("close");
263 text: '<?php echo dol_escape_js($langs->transnoentitiesnoconv("Cancel")); ?>',
265 jQuery(this).dialog("close");
270 jQuery("#seriallist").focus();
282function onChangeDispatchLineQty(element) {
283 var type = $(element).data('type'),
284 qty = parseFloat($(element).data('expected')),
285 changedQty, nbrTrs, dispatchingQty, qtyOrdered, qtyDispatched;
286 id = $(element).attr("id");
290 if (index >= 0 && type && qty >= 0) {
291 nbrTrs = $("tr[name^='" + type + "_'][name$='_" + index + "']").length;
292 qtyChanged = parseFloat($(element).val()) - qty; // qty changed
293 qtyDispatching = parseFloat($(element).val()); // qty currently being dispatched
294 qtyOrdered = parseFloat($("#qty_ordered_0_" + index).val()); // qty ordered
295 qtyDispatched = parseFloat($("#qty_dispatched_0_" + index).val()); // qty already dispatched
297 console.log("onChangeDispatchLineQty qtyChanged: " + qtyChanged + " qtyDispatching: " + qtyDispatching + " qtyOrdered: " + qtyOrdered + " qtyDispatched: " + qtyDispatched);
299 if ((qtyChanged) <= (qtyOrdered - (qtyDispatched + qtyDispatching))) {
300 $("#qty_dispatched_0_" + index).val(qtyDispatched + qtyChanged);
302 /*console.log("eee");
303 $(element).val($(element).data('expected'));*/
305 $(element).data('expected', $(element).val());
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|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
$conf db name
Only used if Module[ID]Name translation string is not found.