dolibarr 21.0.0-beta
massstockmove.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2022 Laurent Destaileur <ely@users.sourceforge.net>
3 * Copyright (C) 2014 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/modules/import/import_csv.modules.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/import.lib.php';
39
48$confirm = GETPOST('confirm', 'alpha');
49$filetoimport = GETPOST('filetoimport');
50
51// Load translation files required by the page
52$langs->loadLangs(array('products', 'stocks', 'orders', 'productbatch'));
53
54//init Hook
55$hookmanager->initHooks(array('massstockmove'));
56
57// Security check
58if ($user->socid) {
59 $socid = $user->socid;
60}
61$result = restrictedArea($user, 'produit|service');
62
63//checks if a product has been ordered
64
65$action = GETPOST('action', 'aZ09');
66$id_product = GETPOSTINT('productid');
67$id_sw = GETPOSTINT('id_sw');
68$id_tw = GETPOSTINT('id_tw');
69$batch = GETPOST('batch');
70$qty = GETPOST('qty');
71$idline = GETPOST('idline');
72
73// Load variable for pagination
74$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
75$sortfield = GETPOST('sortfield', 'aZ09comma');
76$sortorder = GETPOST('sortorder', 'aZ09comma');
77$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
78if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
79 // If $page is not defined, or '' or -1 or if we click on clear filters
80 $page = 0;
81}
82$offset = $limit * $page;
83$pageprev = $page - 1;
84$pagenext = $page + 1;
85
86if (!$sortfield) {
87 $sortfield = 'p.ref';
88}
89if (!$sortorder) {
90 $sortorder = 'ASC';
91}
92
93if (GETPOST('init')) {
94 unset($_SESSION['massstockmove']);
95}
96$listofdata = array();
97if (!empty($_SESSION['massstockmove'])) {
98 $listofdata = json_decode($_SESSION['massstockmove'], true);
99 if (!is_array($listofdata)) {
100 $listofdata = array();
101 }
102}
103
104$error = 0;
105
106
107/*
108 * Actions
109 */
110
111if ($action == 'addline' && $user->hasRight('stock', 'mouvement', 'creer')) {
112 if (!($id_sw > 0)) {
113 //$error++;
114 //setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
115 if ($id_sw < 0) {
116 $id_sw = 0;
117 }
118 }
119 if (!($id_tw > 0)) {
120 $error++;
121 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
122 }
123 if ($id_sw > 0 && $id_tw == $id_sw) {
124 $error++;
125 $langs->load("errors");
126 setEventMessages($langs->trans("ErrorWarehouseMustDiffers"), null, 'errors');
127 }
128 if (!($id_product > 0)) {
129 $error++;
130 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
131 }
132 if (!$qty) {
133 $error++;
134 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
135 }
136
137 // Check a batch number is provided if product need it
138 if (!$error) {
139 $producttmp = new Product($db);
140 $producttmp->fetch($id_product);
141 if ($producttmp->hasbatch()) {
142 if (empty($batch)) {
143 $error++;
144 $langs->load("errors");
145 setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $producttmp->ref), null, 'errors');
146 }
147 }
148 }
149
150 // TODO Check qty is ok for stock move. Note qty may not be enough yet, but we make a check now to report a warning.
151 // What is more important is to have qty when doing action 'createmovements'
152 if (!$error) {
153 // Warning, don't forget lines already added into the $_SESSION['massstockmove']
154 if ($producttmp->hasbatch()) {
155 } else {
156 }
157 }
158
159 //var_dump($_SESSION['massstockmove']);exit;
160 if (!$error) {
161 if (count(array_keys($listofdata)) > 0) {
162 $id = max(array_keys($listofdata)) + 1;
163 } else {
164 $id = 1;
165 }
166 $listofdata[$id] = array('id' => $id, 'id_product' => $id_product, 'qty' => $qty, 'id_sw' => $id_sw, 'id_tw' => $id_tw, 'batch' => $batch);
167 $_SESSION['massstockmove'] = json_encode($listofdata);
168
169 //unset($id_sw);
170 //unset($id_tw);
171 unset($id_product);
172 unset($batch);
173 unset($qty);
174 }
175}
176
177if ($action == 'delline' && $idline != '' && $user->hasRight('stock', 'mouvement', 'creer')) {
178 if (!empty($listofdata[$idline])) {
179 unset($listofdata[$idline]);
180 }
181 if (count($listofdata) > 0) {
182 $_SESSION['massstockmove'] = json_encode($listofdata);
183 } else {
184 unset($_SESSION['massstockmove']);
185 }
186}
187
188if ($action == 'createmovements' && $user->hasRight('stock', 'mouvement', 'creer')) {
189 $error = 0;
190
191 if (!GETPOST("label")) {
192 $error++;
193 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MovementLabel")), null, 'errors');
194 }
195
196 $db->begin();
197
198 if (!$error) {
199 $product = new Product($db);
200
201 foreach ($listofdata as $key => $val) { // Loop on each movement to do
202 $id = $val['id'];
203 $id_product = $val['id_product'];
204 $id_sw = $val['id_sw'];
205 $id_tw = $val['id_tw'];
206 $qty = price2num($val['qty']);
207 $batch = $val['batch'];
208 $dlc = -1; // They are loaded later from serial
209 $dluo = -1; // They are loaded later from serial
210
211 if (!$error && $id_sw != $id_tw && is_numeric($qty) && $id_product) {
212 $result = $product->fetch($id_product);
213
214 $product->load_stock('novirtual'); // Load array product->stock_warehouse
215
216 // Define value of products moved
217 $pricesrc = 0;
218 if (!empty($product->pmp)) {
219 $pricesrc = $product->pmp;
220 }
221 $pricedest = $pricesrc;
222
223 //print 'price src='.$pricesrc.', price dest='.$pricedest;exit;
224
225 if (empty($conf->productbatch->enabled) || !$product->hasbatch()) { // If product does not need lot/serial
226 // Remove stock if source warehouse defined
227 if ($id_sw > 0) {
228 $result1 = $product->correct_stock(
229 $user,
230 $id_sw,
231 $qty,
232 1,
233 GETPOST("label"),
234 $pricesrc,
235 GETPOST("codemove")
236 );
237 if ($result1 < 0) {
238 $error++;
239 setEventMessages($product->error, $product->errors, 'errors');
240 }
241 }
242
243 // Add stock
244 $result2 = $product->correct_stock(
245 $user,
246 $id_tw,
247 $qty,
248 0,
249 GETPOST("label"),
250 $pricedest,
251 GETPOST("codemove")
252 );
253 if ($result2 < 0) {
254 $error++;
255 setEventMessages($product->error, $product->errors, 'errors');
256 }
257 } else {
258 $arraybatchinfo = $product->loadBatchInfo($batch);
259 if (count($arraybatchinfo) > 0) {
260 $firstrecord = array_shift($arraybatchinfo);
261 $dlc = $firstrecord['eatby'];
262 $dluo = $firstrecord['sellby'];
263 //var_dump($batch);
264 //var_dump($arraybatchinfo);
265 //var_dump($firstrecord);
266 //var_dump($dlc);
267 //var_dump($dluo); exit;
268 } else {
269 $dlc = '';
270 $dluo = '';
271 }
272
273 // Remove stock
274 if ($id_sw > 0) {
275 $result1 = $product->correct_stock_batch(
276 $user,
277 $id_sw,
278 $qty,
279 1,
280 GETPOST("label"),
281 $pricesrc,
282 $dlc,
283 $dluo,
284 $batch,
285 GETPOST("codemove")
286 );
287 if ($result1 < 0) {
288 $error++;
289 setEventMessages($product->error, $product->errors, 'errors');
290 }
291 }
292
293 // Add stock
294 $result2 = $product->correct_stock_batch(
295 $user,
296 $id_tw,
297 $qty,
298 0,
299 GETPOST("label"),
300 $pricedest,
301 $dlc,
302 $dluo,
303 $batch,
304 GETPOST("codemove")
305 );
306 if ($result2 < 0) {
307 $error++;
308 setEventMessages($product->error, $product->errors, 'errors');
309 }
310 }
311 } else {
312 // dol_print_error(null,"Bad value saved into sessions");
313 $error++;
314 }
315 }
316 }
317 //var_dump($_SESSION['massstockmove']);exit;
318
319 if (!$error) {
320 unset($_SESSION['massstockmove']);
321
322 $db->commit();
323 setEventMessages($langs->trans("StockMovementRecorded"), null, 'mesgs');
324 header("Location: ".DOL_URL_ROOT.'/product/stock/list.php'); // Redirect to avoid pb when using back
325 exit;
326 } else {
327 $db->rollback();
328 setEventMessages($langs->trans("Error"), null, 'errors');
329 }
330}
331
332if ($action == 'importCSV' && $user->hasRight('stock', 'mouvement', 'creer')) {
333 dol_mkdir($conf->stock->dir_temp);
334 $nowyearmonth = dol_print_date(dol_now(), '%Y%m%d%H%M%S');
335
336 $fullpath = $conf->stock->dir_temp."/".$user->id.'-csvfiletotimport.csv';
337 $resultupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $fullpath, 1);
338 if (is_numeric($resultupload) && $resultupload > 0) {
339 dol_syslog("File ".$fullpath." was added for import");
340 } else {
341 $error++;
342 $langs->load("errors");
343 if ($resultupload === 'ErrorDirNotWritable') {
344 setEventMessages($langs->trans("ErrorFailedToSaveFile").' - '.$langs->trans($resultupload, $fullpath), null, 'errors');
345 } else {
346 setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
347 }
348 }
349
350 if (!$error) {
351 $importcsv = new ImportCsv($db, 'massstocklist');
352 //print $importcsv->separator;
353
354 $nblinesrecord = $importcsv->import_get_nb_of_lines($fullpath) - 1;
355 $importcsv->import_open_file($fullpath);
356 $labelsrecord = $importcsv->import_read_record();
357
358 if ($nblinesrecord < 1) {
359 setEventMessages($langs->trans("BadNumberOfLinesMustHaveAtLeastOneLinePlusTitle"), null, 'errors');
360 } else {
361 $i = 0;
362 $data = array();
363 $productstatic = new Product($db);
364 $warehousestatics = new Entrepot($db);
365 $warehousestatict = new Entrepot($db);
366
367 // Loop on each line in CSV file
368 while (($i < $nblinesrecord) && !$error) {
369 $newrecord = $importcsv->import_read_record();
370
371 $data[$i] = $newrecord;
372 if (count($data[$i]) == 1) {
373 // Only 1 empty line
374 unset($data[$i]);
375 $i++;
376 continue;
377 }
378
379 $tmp_id_sw = $data[$i][0]['val'];
380 $tmp_id_tw = $data[$i][1]['val'];
381 $tmp_id_product = $data[$i][2]['val'];
382 $tmp_qty = $data[$i][3]['val'];
383 $tmp_batch = $data[$i][4]['val'];
384
385 $errorforproduct = 0;
386 $isidorref = 'ref';
387 if (!is_numeric($tmp_id_product) && $tmp_id_product != '' && preg_match('/^id:/i', $tmp_id_product)) {
388 $isidorref = 'id';
389 }
390 $tmp_id_product = preg_replace('/^(id|ref):/i', '', $tmp_id_product);
391
392 if ($isidorref === 'ref') {
393 $tmp_id_product = preg_replace('/^ref:/', '', $tmp_id_product);
394 $result = fetchref($productstatic, $tmp_id_product);
395 if ($result === -2) {
396 $error++;
397 $errorforproduct = 1;
398 $langs->load("errors");
399 setEventMessages($langs->trans("ErrorMultipleRecordFoundFromRef", $tmp_id_product), null, 'errors');
400 } elseif ($result <= 0) {
401 $error++;
402 $errorforproduct = 1;
403 $langs->load("errors");
404 setEventMessages($langs->trans("ErrorRefNotFound", $tmp_id_product), null, 'errors');
405 }
406 $tmp_id_product = $result;
407 }
408 $data[$i][2]['val'] = $tmp_id_product;
409 if (!$errorforproduct && !($tmp_id_product > 0)) {
410 $error++;
411 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
412 }
413
414 if ($tmp_id_sw !== '') {
415 // For source, we allow empty value
416 $errorforwarehouses = 0;
417 $isidorref = 'ref';
418 if (!is_numeric($tmp_id_sw) && $tmp_id_sw != '' && preg_match('/^id:/i', $tmp_id_sw)) {
419 $isidorref = 'id';
420 }
421 $tmp_id_sw = preg_replace('/^(id|ref):/i', '', $tmp_id_sw);
422 if ($isidorref === 'ref') {
423 $tmp_id_sw = preg_replace('/^ref:/', '', $tmp_id_sw);
424 $result = fetchref($warehousestatics, $tmp_id_sw);
425 if ($result === -2) {
426 $error++;
427 $errorforwarehouses = 1;
428 $langs->load("errors");
429 setEventMessages($langs->trans("ErrorMultipleRecordFoundFromRef", $tmp_id_sw), null, 'errors');
430 } elseif ($result <= 0) {
431 $error++;
432 $errorforwarehouses = 1;
433 $langs->load("errors");
434 setEventMessages($langs->trans("ErrorRefNotFound", $tmp_id_sw), null, 'errors');
435 }
436 $tmp_id_sw = $result;
437 }
438 $data[$i][0]['val'] = $tmp_id_sw;
439 if (!$errorforwarehouses && !($tmp_id_sw > 0)) {
440 $error++;
441 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
442 }
443 }
444
445 $errorforwarehouset = 0;
446 $isidorref = 'ref';
447 if (!is_numeric($tmp_id_tw) && $tmp_id_tw != '' && preg_match('/^id:/i', $tmp_id_tw)) {
448 $isidorref = 'id';
449 }
450 $tmp_id_tw = preg_replace('/^(id|ref):/i', '', $tmp_id_tw);
451 if ($isidorref === 'ref') {
452 $tmp_id_tw = preg_replace('/^ref:/', '', $tmp_id_tw);
453 $result = fetchref($warehousestatict, $tmp_id_tw);
454 if ($result === -2) {
455 $error++;
456 $errorforwarehouset = 1;
457 $langs->load("errors");
458 setEventMessages($langs->trans("ErrorMultipleRecordFoundFromRef", $tmp_id_tw), null, 'errors');
459 } elseif ($result <= 0) {
460 $error++;
461 $errorforwarehouset = 1;
462 $langs->load("errors");
463 setEventMessages($langs->trans("ErrorRefNotFound", $tmp_id_tw), null, 'errors');
464 }
465 $tmp_id_tw = $result;
466 }
467 $data[$i][1]['val'] = $tmp_id_tw;
468 if (!$errorforwarehouset && !($tmp_id_tw > 0)) {
469 $error++;
470 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
471 }
472
473 // If a source is provided and same than target
474 if ($tmp_id_sw > 0 && $tmp_id_tw == $tmp_id_sw) {
475 $error++;
476 $langs->load("errors");
477 setEventMessages($langs->trans("ErrorWarehouseMustDiffers"), null, 'errors');
478 }
479 if (!$tmp_qty) {
480 $error++;
481 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
482 }
483
484 // Check a batch number is provided if product need it
485 if (!$error) {
486 $producttmp = new Product($db);
487 $producttmp->fetch($tmp_id_product);
488 if ($producttmp->hasbatch()) {
489 if (empty($tmp_batch)) {
490 $error++;
491 $langs->load("errors");
492 setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $producttmp->ref), null, 'errors');
493 }
494 }
495 }
496
497 $i++;
498 }
499
500 if (!$error) {
501 foreach ($data as $key => $value) {
502 if (count(array_keys($listofdata)) > 0) {
503 $id = max(array_keys($listofdata)) + 1;
504 } else {
505 $id = 1;
506 }
507 $tmp_id_sw = $data[$key][0]['val'];
508 $tmp_id_tw = $data[$key][1]['val'];
509 $tmp_id_product = $data[$key][2]['val'];
510 $tmp_qty = $data[$key][3]['val'];
511 $tmp_batch = $data[$key][4]['val'];
512 $listofdata[$key] = array('id' => $key, 'id_sw' => $tmp_id_sw, 'id_tw' => $tmp_id_tw, 'id_product' => $tmp_id_product, 'qty' => $tmp_qty, 'batch' => $tmp_batch);
513 }
514 }
515 }
516 }
517 if ($error) {
518 $listofdata = array();
519 }
520
521 $_SESSION['massstockmove'] = json_encode($listofdata);
522}
523
524if ($action == 'confirm_deletefile' && $confirm == 'yes') {
525 $langs->load("other");
526
527 $param = '&datatoimport='.urlencode($datatoimport).'&format='.urlencode($format);
528 if ($excludefirstline) {
529 $param .= '&excludefirstline='.urlencode($excludefirstline);
530 }
531 if ($endatlinenb) {
532 $param .= '&endatlinenb='.urlencode($endatlinenb);
533 }
534
535 $file = $conf->stock->dir_temp.'/'.GETPOST('urlfile');
536 $ret = dol_delete_file($file);
537 if ($ret) {
538 setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
539 } else {
540 setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
541 }
542 header('Location: '.$_SERVER["PHP_SELF"]);
543 exit;
544}
545
546
547/*
548 * View
549 */
550
551$now = dol_now();
552$error = 0;
553
554$form = new Form($db);
555$formproduct = new FormProduct($db);
556$productstatic = new Product($db);
557$warehousestatics = new Entrepot($db);
558$warehousestatict = new Entrepot($db);
559
560$help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks|DE:Modul_Bestände';
561
562$title = $langs->trans('MassMovement');
563
564llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-product page-stock_massstomove');
565
566print load_fiche_titre($langs->trans("MassStockTransferShort"), '', 'stock');
567
568$titletoadd = $langs->trans("Select");
569$buttonrecord = $langs->trans("RecordMovements");
570$titletoaddnoent = $langs->transnoentitiesnoconv("Select");
571$buttonrecordnoent = $langs->transnoentitiesnoconv("RecordMovements");
572print '<span class="opacitymedium">'.$langs->trans("SelectProductInAndOutWareHouse", $titletoaddnoent, $buttonrecordnoent).'</span>';
573
574print '<br>';
575//print '<br>';
576
577// Form to upload a file
578print '<form name="userfile" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data" method="POST">';
579print '<input type="hidden" name="token" value="'.newToken().'">';
580print '<input type="hidden" name="action" value="importCSV">';
581if (!empty($conf->dol_optimize_smallscreen)) {
582 print '<br>';
583}
584print '<span class="opacitymedium">';
585print $langs->trans("or");
586print ' ';
587$importcsv = new ImportCsv($db, 'massstocklist');
588print $form->textwithpicto($langs->trans('SelectAStockMovementFileToImport'), $langs->transnoentitiesnoconv("InfoTemplateImport", $importcsv->separator));
589print '</span>';
590
591$maxfilesizearray = getMaxFileSizeArray();
592$maxmin = $maxfilesizearray['maxmin'];
593if ($maxmin > 0) {
594 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
595}
596print '<input type="file" name="userfile" size="20" maxlength="80"> &nbsp; &nbsp; ';
597$out = (!getDolGlobalString('MAIN_UPLOAD_DOC') ? ' disabled' : '');
598print '<input type="submit" class="button small smallpaddingimp" value="'.$langs->trans("ImportFromCSV").'"'.$out.' name="sendit">';
599$out = '';
600if (getDolGlobalString('MAIN_UPLOAD_DOC')) {
601 $max = getDolGlobalString('MAIN_UPLOAD_DOC'); // In Kb
602 $maxphp = @ini_get('upload_max_filesize'); // In unknown
603 if (preg_match('/k$/i', $maxphp)) {
604 $maxphp = preg_replace('/k$/i', '', $maxphp);
605 $maxphp = (int) $maxphp * 1;
606 }
607 if (preg_match('/m$/i', $maxphp)) {
608 $maxphp = preg_replace('/m$/i', '', $maxphp);
609 $maxphp = (int) $maxphp * 1024;
610 }
611 if (preg_match('/g$/i', $maxphp)) {
612 $maxphp = preg_replace('/g$/i', '', $maxphp);
613 $maxphp = (int) $maxphp * 1024 * 1024;
614 }
615 if (preg_match('/t$/i', $maxphp)) {
616 $maxphp = preg_replace('/t$/i', '', $maxphp);
617 $maxphp = (int) $maxphp * 1024 * 1024 * 1024;
618 }
619 $maxphp2 = @ini_get('post_max_size'); // In unknown
620 if (preg_match('/k$/i', $maxphp2)) {
621 $maxphp2 = preg_replace('/k$/i', '', $maxphp2);
622 $maxphp2 = (int) $maxphp2 * 1;
623 }
624 if (preg_match('/m$/i', $maxphp2)) {
625 $maxphp2 = preg_replace('/m$/i', '', $maxphp2);
626 $maxphp2 = (int) $maxphp2 * 1024;
627 }
628 if (preg_match('/g$/i', $maxphp2)) {
629 $maxphp2 = preg_replace('/g$/i', '', $maxphp2);
630 $maxphp2 = (int) $maxphp2 * 1024 * 1024;
631 }
632 if (preg_match('/t$/i', $maxphp2)) {
633 $maxphp2 = preg_replace('/t$/i', '', $maxphp2);
634 $maxphp2 = (int) $maxphp2 * 1024 * 1024 * 1024;
635 }
636 // Now $max and $maxphp and $maxphp2 are in Kb
637 $maxmin = $max;
638 $maxphptoshow = $maxphptoshowparam = '';
639 if ($maxphp > 0) {
640 $maxmin = min($max, $maxphp);
641 $maxphptoshow = $maxphp;
642 $maxphptoshowparam = 'upload_max_filesize';
643 }
644 if ($maxphp2 > 0) {
645 $maxmin = min($max, $maxphp2);
646 if ($maxphp2 < $maxphp) {
647 $maxphptoshow = $maxphp2;
648 $maxphptoshowparam = 'post_max_size';
649 }
650 }
651
652 $langs->load('other');
653 $out .= ' ';
654 $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup", $max, $maxphptoshow), 1);
655} else {
656 $out .= ' ('.$langs->trans("UploadDisabled").')';
657}
658print $out;
659
660print '</form>';
661
662print '<br><br>';
663
664// Form to add a line
665print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire">';
666print '<input type="hidden" name="token" value="'.newToken().'">';
667print '<input type="hidden" name="action" value="addline">';
668
669
670print '<div class="div-table-responsive-no-min">';
671print '<table class="liste noborder centpercent">';
672
673$param = '';
674
675print '<tr class="liste_titre">';
676print getTitleFieldOfList($langs->trans('WarehouseSource'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
677print getTitleFieldOfList($langs->trans('WarehouseTarget'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
678print getTitleFieldOfList($langs->trans('Product'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
679if (isModEnabled('productbatch')) {
680 print getTitleFieldOfList($langs->trans('Batch'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'tagtd maxwidthonsmartphone ');
681}
682print getTitleFieldOfList($langs->trans('Qty'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right tagtd maxwidthonsmartphone ');
683print getTitleFieldOfList('', 0);
684print '</tr>';
685
686print '<tr class="oddeven">';
687// From warehouse
688print '<td class="nowraponall">';
689print img_picto($langs->trans("WarehouseSource"), 'stock', 'class="paddingright"').$formproduct->selectWarehouses($id_sw, 'id_sw', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200');
690print '</td>';
691// To warehouse
692print '<td class="nowraponall">';
693print img_picto($langs->trans("WarehouseTarget"), 'stock', 'class="paddingright"').$formproduct->selectWarehouses($id_tw, 'id_tw', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200');
694print '</td>';
695// Product
696print '<td class="nowraponall">';
697$filtertype = 0;
698if (getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
699 $filtertype = '';
700}
701if (getDolGlobalInt('PRODUIT_LIMIT_SIZE') <= 0) {
702 $limit = '';
703} else {
704 $limit = getDolGlobalString('PRODUIT_LIMIT_SIZE');
705}
706print img_picto($langs->trans("Product"), 'product', 'class="paddingright"');
707print $form->select_produits((isset($id_product) ? $id_product : 0), 'productid', $filtertype, $limit, 0, -1, 2, '', 1, array(), 0, '1', 0, 'minwidth200imp maxwidth300', 1, '', null, 1);
708print '</td>';
709// Batch number
710if (isModEnabled('productbatch')) {
711 print '<td class="nowraponall">';
712 print img_picto($langs->trans("LotSerial"), 'lot', 'class="paddingright"');
713 print '<input type="text" name="batch" class="flat maxwidth75" value="'.dol_escape_htmltag((isset($batch) ? $batch : '')).'">';
714 print '</td>';
715}
716// Qty
717print '<td class="right"><input type="text" class="flat maxwidth50 right" name="qty" value="'.price2num((float) (isset($qty) ? $qty : 0), 'MS').'"></td>';
718// Button to add line
719print '<td class="right"><input type="submit" class="button" name="addline" value="'.dol_escape_htmltag($titletoadd).'"></td>';
720
721print '</tr>';
722
723foreach ($listofdata as $key => $val) {
724 $productstatic->id = 0;
725 $productstatic->fetch($val['id_product']);
726
727 $warehousestatics->id = 0;
728 if ($val['id_sw'] > 0) {
729 $warehousestatics->fetch($val['id_sw']);
730 }
731 $warehousestatict->id = 0;
732 if ($val['id_tw'] > 0) {
733 $warehousestatict->fetch($val['id_tw']);
734 }
735
736 if ($productstatic->id <= 0) {
737 $error++;
738 setEventMessages($langs->trans("ObjectNotFound", $langs->transnoentitiesnoconv("Product").' (id='.$val['id_product'].')'), null, 'errors');
739 }
740 if ($warehousestatics->id < 0) { // We accept 0 for source warehouse id
741 $error++;
742 setEventMessages($langs->trans("ObjectNotFound", $langs->transnoentitiesnoconv("WarehouseSource").' (id='.$val['id_sw'].')'), null, 'errors');
743 }
744 if ($warehousestatict->id <= 0) {
745 $error++;
746 setEventMessages($langs->trans("ObjectNotFound", $langs->transnoentitiesnoconv("WarehouseTarget").' (id='.$val['id_tw'].')'), null, 'errors');
747 }
748
749 if (!$error) {
750 print '<tr class="oddeven">';
751 print '<td>';
752 if ($warehousestatics->id > 0) {
753 print $warehousestatics->getNomUrl(1);
754 } else {
755 print '<span class="opacitymedium">';
756 print $langs->trans("None");
757 print '</span>';
758 }
759 print '</td>';
760 print '<td>';
761 print $warehousestatict->getNomUrl(1);
762 print '</td>';
763 print '<td>';
764 print $productstatic->getNomUrl(1).' - '.dol_escape_htmltag($productstatic->label);
765 print '</td>';
766 if (isModEnabled('productbatch')) {
767 print '<td>';
768 print dol_escape_htmltag($val['batch']);
769 print '</td>';
770 }
771 print '<td class="right">'.price2num((float) $val['qty'], 'MS').'</td>';
772 print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=delline&token='.newToken().'&idline='.$val['id'].'">'.img_delete($langs->trans("Remove")).'</a></td>';
773 print '</tr>';
774 }
775}
776
777print '</table>';
778print '</div>';
779
780print '</form>';
781
782print '<br>';
783
784// Form to validate all movements
785if (count($listofdata)) {
786 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formulaire2" class="formconsumeproduce">';
787 print '<input type="hidden" name="token" value="'.newToken().'">';
788 print '<input type="hidden" name="action" value="createmovements">';
789
790 // Button to record mass movement
791 $codemove = (GETPOSTISSET("codemove") ? GETPOST("codemove", 'alpha') : dol_print_date(dol_now(), '%Y%m%d%H%M%S'));
792 $labelmovement = GETPOST("label") ? GETPOST('label') : $langs->trans("MassStockTransferShort").' '.dol_print_date($now, '%Y-%m-%d %H:%M');
793
794 print '<div class="center">';
795 print '<span class="fieldrequired">'.$langs->trans("InventoryCode").':</span> ';
796 print '<input type="text" name="codemove" class="maxwidth300" value="'.dol_escape_htmltag($codemove).'"> &nbsp; ';
797 print '<span class="clearbothonsmartphone"></span>';
798 print $langs->trans("MovementLabel").': ';
799 print '<input type="text" name="label" class="minwidth300" value="'.dol_escape_htmltag($labelmovement).'"><br>';
800 print '<br>';
801
802 print '<div class="center"><input type="submit" class="button" name="valid" value="'.dol_escape_htmltag($buttonrecord).'"></div>';
803
804 print '<br>';
805 print '</div>';
806
807 print '</form>';
808}
809
810if ($action == 'delete') {
811 print $form->formconfirm($_SERVER["PHP_SELF"].'?urlfile='.urlencode(GETPOST('urlfile')).'&step=3'.$param, $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
812}
813
814// End of page
815llxFooter();
816$db->close();
817
818
826function startsWith($haystack, $needle)
827{
828 $length = strlen($needle);
829 return substr($haystack, 0, $length) === $needle;
830}
831
839function fetchref($static_object, $tmp_ref)
840{
841 if (startsWith($tmp_ref, 'ref:')) {
842 $tmp_ref = str_replace('ref:', '', $tmp_ref);
843 }
844 $static_object->id = 0;
845 $static_object->fetch(0, $tmp_ref);
846 return $static_object->id;
847}
$id
Definition account.php:48
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage warehouses.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class to import CSV files.
Class to manage products or services.
llxFooter()
Footer empty.
Definition document.php:107
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Check validity of a file upload from an GUI page, and move it to its final destination.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
startsWith($haystack, $needle)
Verify if $haystack startswith $needle.
fetchref($static_object, $tmp_ref)
Fetch object with ref.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.