dolibarr
13.0.2
Main Page
Related Pages
Modules
Classes
Files
Examples
File List
File Members
htdocs
mrp
js
lib_dispatch.js.php
Go to the documentation of this file.
1
<?php
2
// Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
3
// Copyright (C) 2017 Francis Appels <francis.appels@z-application.com>
4
//
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
// or see https://www.gnu.org/
18
24
if
(!defined(
'NOREQUIRESOC'
)) define(
'NOREQUIRESOC'
,
'1'
);
25
if
(!defined(
'NOCSRFCHECK'
)) define(
'NOCSRFCHECK'
, 1);
26
if
(!defined(
'NOTOKENRENEWAL'
)) define(
'NOTOKENRENEWAL'
, 1);
27
if
(!defined(
'NOLOGIN'
)) define(
'NOLOGIN'
, 1);
28
if
(!defined(
'NOREQUIREMENU'
)) define(
'NOREQUIREMENU'
, 1);
29
if
(!defined(
'NOREQUIREHTML'
)) define(
'NOREQUIREHTML'
, 1);
30
if
(!defined(
'NOREQUIREAJAX'
)) define(
'NOREQUIREAJAX'
,
'1'
);
31
32
session_cache_limiter(
'public'
);
33
34
require_once
'../../main.inc.php'
;
35
36
// Define javascript type
37
top_httphead
(
'text/javascript; charset=UTF-8'
);
38
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
39
if
(empty($dolibarr_nocache)) header(
'Cache-Control: max-age=10800, public, must-revalidate'
);
40
else
header(
'Cache-Control: no-cache'
);
41
42
?>
51
function
addDispatchLine(index,
type
, mode)
52
{
53
mode = mode ||
'qtymissing'
54
55
console.log(
"fourn/js/lib_dispatch.js.php Split line type="
+
type
+
" index="
+index+
" mode="
+mode);
56
var nbrTrs = $(
"tr[name^='"
+
type
+
"_"
+index+
"']"
).length;
// position of line for batch
57
var $row = $(
"tr[name='"
+
type
+
'_'
+index+
"_1']"
).clone(
true
);
// clone last batch line to jQuery object
58
var qtyOrdered = parseFloat($(
"#qty_ordered_"
+index).val());
// Qty ordered is same for all rows
59
var qty = parseFloat($(
"#qtytoproduce-"
+index+
"-"
+nbrTrs).val());
60
var qtyDispatched;
61
62
if
(mode ===
'lessone'
)
63
{
64
qtyDispatched = parseFloat($(
"#qty_dispatched_"
+index).val()) + 1;
65
}
66
else
67
{
68
qtyDispatched = parseFloat($(
"#qty_dispatched_"
+index).val()) + qty;
69
console.log(qty);
70
// If user did not reduced the qty to dispatch on old line, we keep only 1 on old line and the rest on new line
71
if
(qtyDispatched == qtyOrdered && qtyDispatched > 1) {
72
qtyDispatched = parseFloat($(
"#qty_dispatched_"
+index).val()) + 1;
73
mode =
'lessone'
;
74
}
75
}
76
console.log(
"qtyDispatched="
+qtyDispatched+
" qtyOrdered="
+qtyOrdered);
77
78
if
(qtyOrdered <= 1) {
79
window.alert(
"Quantity can't be split"
);
80
}
81
if
(qtyDispatched < qtyOrdered)
82
{
83
//replace tr suffix nbr
84
var re1 =
new
RegExp(
'_'
+index+
'_1'
,
'g'
);
85
var re2 =
new
RegExp(
'-'
+index+
'-1'
,
'g'
);
86
$row.html($row.html().replace(re1,
'_'
+index+
'_'
+(nbrTrs+1)));
87
$row.html($row.html().replace(re2,
'-'
+index+
'-'
+(nbrTrs+1)));
88
//create new select2 to avoid duplicate id of cloned one
89
$row.find(
"select[name='"
+
'idwarehousetoproduce-'
+index+
'-'
+(nbrTrs+1)+
"']"
).select2();
90
// TODO find solution to copy selected option to new select
91
// TODO find solution to keep new tr's after page refresh
92
//clear value
93
$row.find(
"input[name^='qtytoproduce']"
).val(
''
);
94
//change name of new row
95
$row.attr(
'name'
,
type
+
'_'
+index+
'_'
+(nbrTrs+1));
96
//insert new row before last row
97
$(
"tr[name^='"
+
type
+
"_"
+index+
"_"
+nbrTrs+
"']:last"
).after($row);
98
99
//remove cloned select2 with duplicate id.
100
$(
"#s2id_entrepot_"
+nbrTrs+
'_'
+index).detach();
// old way to find duplicated select2 component
101
$(
".csswarehouse_"
+index+
"_"
+(nbrTrs+1)+
":first-child"
).parent(
"span.selection"
).parent(
".select2"
).detach();
102
103
/* Suffix of lines are: index _ trs.length */
104
$(
"#qtytoproduce-"
+index+
"-"
+(nbrTrs+1)).focus();
105
if
($(
"#qtytoproduce-"
+index+
"-"
+(nbrTrs)).val() == 0) {
106
$(
"#qtytoproduce-"
+index+
"-"
+(nbrTrs)).val(1);
107
}
108
var totalonallines = 0;
109
for
(let i = 1; i <= nbrTrs; i++) {
110
console.log(i+
" = "
+parseFloat($(
"#qtytoproduce-"
+index+
"-"
+i).val()));
111
totalonallines = totalonallines + parseFloat($(
"#qtytoproduce-"
+index+
"-"
+i).val());
112
}
113
console.log(
"totalonallines="
+totalonallines);
114
if
(totalonallines == qtyOrdered && qtyOrdered > 1) {
115
var prevouslineqty = $(
"#qtytoproduce-"
+index+
"-"
+nbrTrs).val();
116
$(
"#qtytoproduce-"
+index+
"-"
+(nbrTrs)).val(1);
117
$(
"#qtytoproduce-"
+index+
"-"
+(nbrTrs+1)).val(prevouslineqty - 1);
118
}
119
$(
"#qty_dispatched_"
+index).val(qtyDispatched);
120
121
//hide all buttons then show only the last one
122
$(
"tr[name^='"
+
type
+
"_'][name$='_"
+index+
"'] .splitbutton"
).hide();
123
$(
"tr[name^='"
+
type
+
"_'][name$='_"
+index+
"']:last .splitbutton"
).show();
124
125
if
(mode ===
'lessone'
)
126
{
127
qty = 1;
// keep 1 in old line
128
$(
"#qty_"
+(nbrTrs-1)+
"_"
+index).val(qty);
129
}
130
// Store arbitrary data for dispatch qty input field change event
131
$(
"#qtytoproduce-"
+index+(nbrTrs)).data(
'qty'
, qty);
132
$(
"#qtytoproduce-"
+index+(nbrTrs)).data(
'type'
,
type
);
133
$(
"#qtytoproduce-"
+index+(nbrTrs)).data(
'index'
, index);
134
}
135
}
136
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
Definition:
main.inc.php:1214
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition:
repair.php:105
Generated on Sat Aug 23 2025 13:17:29 for
dolibarr
by Doxygen 1.8.5