dolibarr 24.0.3
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2011-2017 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
10 * Copyright (C) 2014-2017 Francis Appels <francis.appels@yahoo.com>
11 * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
12 * Copyright (C) 2016-2018 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2016 Yasser Carreón <yacasia@gmail.com>
14 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
15 * Copyright (C) 2020 Lenin Rivas <lenin@leninrivas.com>
16 * Copyright (C) 2022 Josep Lluís Amador <joseplluis@lliuretic.cat>
17 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
18 * Copyright (C) 2025 Nick Fragoulis
19 * Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 3 of the License, or
24 * (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <https://www.gnu.org/licenses/>.
33 */
34
41// Load Dolibarr environment
42require '../main.inc.php';
52require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
53require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
54require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
55require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php';
56require_once DOL_DOCUMENT_ROOT . '/core/lib/sendings.lib.php';
57require_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php';
58require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
59require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
60require_once DOL_DOCUMENT_ROOT . '/product/stock/class/productlot.class.php';
61require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
62if (isModEnabled("product") || isModEnabled("service")) {
63 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
64}
65if (isModEnabled("propal")) {
66 require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php';
67}
68if (isModEnabled('productbatch')) {
69 require_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php';
70}
71if (isModEnabled('project')) {
72 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
73 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
74}
75
76// Load translation files required by the page
77$langs->loadLangs(array("sendings", "companies", "bills", 'orders', 'stocks', 'other', 'propal', 'productbatch'));
78
79if (isModEnabled('incoterm')) {
80 $langs->load('incoterm');
81}
82if (isModEnabled('productbatch')) {
83 $langs->load('productbatch');
84}
85
86
87$origin = GETPOST('origin', 'alpha'); // Example: commande, propal
88$origin_id = GETPOSTINT('origin_id');
89$id = GETPOSTINT('id');
90
91
92if (empty($origin_id) && !empty($origin)) {
93 $origin_id = GETPOSTINT('origin_id'); // Id of order or propal
94}
95if (empty($origin_id) && !empty($origin)) {
96 $origin_id = GETPOSTINT('object_id'); // Id of order or propal
97}
98$socid = GETPOSTINT('socid');
99$ref = GETPOST('ref', 'alpha');
100$line_id = GETPOSTINT('lineid');
101$facid = GETPOSTINT('facid');
102$contactid = GETPOSTINT('contactid');
103$projectid = GETPOSTINT('projectid');
104$action = GETPOST('action', 'alpha');
105$confirm = GETPOST('confirm', 'alpha');
106$cancel = GETPOST('cancel', 'alpha');
107$rank = (GETPOSTINT('rank') > 0) ? GETPOSTINT('rank') : -1;
108$lineid = GETPOSTINT('lineid');
109$backtopage = GETPOST('backtopage', 'alpha');
110
111//PDF
112$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
113$hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
114$hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
115
116$object = new Expedition($db);
117$objectorder = new Commande($db);
118
119// fetch optionals attributes and labels
120$extrafields->fetch_name_optionals_label($object->table_element);
121$extrafields->fetch_name_optionals_label($object->table_element_line);
122$extrafields->fetch_name_optionals_label($objectorder->table_element_line);
123
124// Load object. Make an object->fetch
125include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
126
127if (empty($origin) && !empty($object->origin_type) && $object->origin_id > 0) {
128 $origin = $object->origin_type;
129} elseif (empty($origin) && is_string($object->origin) && $object->origin !== '' && $object->origin_id > 0) {
130 $origin = $object->origin;
131}
132if (empty($origin_id) && $object->origin_id > 0) {
133 $origin_id = $object->origin_id;
134}
135$origin_type = is_string($origin) ? $origin : '';
136
137// Permissions / Rights
138$usercanread = $user->hasRight("expedition", "lire");
139$usercancreate = $user->hasRight("expedition", "creer");
140$usercandelete = $user->hasRight("expedition", "supprimer");
141
142// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
143$hookmanager->initHooks(array('expeditioncard', 'globalcard'));
144
145$date_delivery = dol_mktime(GETPOSTINT('date_deliveryhour'), GETPOSTINT('date_deliverymin'), 0, GETPOSTINT('date_deliverymonth'), GETPOSTINT('date_deliveryday'), GETPOSTINT('date_deliveryyear'));
146
147$date_shipping = dol_mktime(GETPOSTINT('date_shippinghour'), GETPOSTINT('date_shippingmin'), 0, GETPOSTINT('date_shippingmonth'), GETPOSTINT('date_shippingday'), GETPOSTINT('date_shippingyear'));
148
149
150// Security check
151
152if ($user->socid) {
153 $socid = $user->socid;
154}
155
156$result = restrictedArea($user, 'expedition', $object->id, '');
157
158$permissiondellink = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_dellink.inc.php
159$permissiontoadd = $user->hasRight('expedition', 'creer');
160$permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
161$permissiontoeditextra = $permissiontoadd;
162if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
163 // For action 'update_extras', is there a specific permission set for the attribute to update
164 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
165}
166
167$upload_dir = $conf->expedition->dir_output . '/sending';
168
169$editColspan = 0;
170$objectsrc = null;
171$typeobject = null;
172$ref_customer = null;
173$shipping_method_id = null;
174$warehouse_id = null;
175$note_public = null;
176$note_private = null;
177
178/*
179 * Actions
180 */
181
182$error = 0;
183$parameters = array();
184$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
185if ($reshook < 0) {
186 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
187}
188
189if (empty($reshook)) {
190 $backurlforlist = DOL_URL_ROOT.'/expedition/list.php';
191
192 if (empty($backtopage) || ($cancel && empty($id))) {
193 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
194 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
195 $backtopage = $backurlforlist;
196 } else {
197 $backtopage = DOL_URL_ROOT.'/expedition/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
198 }
199 }
200 }
201
202 if ($cancel) {
203 if (!empty($backtopageforcancel)) {
204 header("Location: ".$backtopageforcancel);
205 exit;
206 } elseif (!empty($backtopage)) {
207 header("Location: ".$backtopage);
208 exit;
209 }
210 $action = '';
211 }
212
213
214 if ($cancel) {
215 if ($origin_id > 0) {
216 if ($origin == 'commande') {
217 header("Location: " . DOL_URL_ROOT . '/expedition/shipment.php?id=' . ((int) $origin_id));
218 exit;
219 }
220 } else {
221 $action = '';
222 $object->fetch($object->id); // show shipment also after canceling modification
223 }
224 }
225
226 include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
227
228 // Actions to build doc
229 include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
230
231 // The lines of a shipment can be modified or deleted only when it is a draft
232 if (in_array($action, array('editline', 'updateline', 'deleteline')) && (!$permissiontoadd || $object->status != Expedition::STATUS_DRAFT)) {
233 if ($object->status != Expedition::STATUS_DRAFT) {
234 setEventMessages($langs->trans("StatusOfRefMustBe", $object->ref, $langs->transnoentitiesnoconv("StatusSendingDraftShort")), null, 'errors');
235 }
236 $action = '';
237 }
238
239 // Back to draft
240 if ($action == 'setdraft' && $permissiontoadd) {
241 $object->fetch($id);
242 $result = $object->setDraft($user, 0);
243 if ($result < 0) {
244 setEventMessages($object->error, $object->errors, 'errors');
245 } else {
246 header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
247 exit;
248 }
249 }
250 // Reopen
251 if ($action == 'reopen' && $permissiontoadd) {
252 $object->fetch($id);
253 $result = $object->reOpen();
254 if ($result < 0) {
255 setEventMessages($object->error, $object->errors, 'errors');
256 } else {
257 header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
258 exit;
259 }
260 }
261
262 // Set incoterm
263 if ($action == 'set_incoterms' && isModEnabled('incoterm') && $permissiontoadd) {
264 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
265 }
266
267 if ($action == 'classin' && $permissiontoadd) {
268 // Link to a project
269 $result = $object->setProject(GETPOSTINT('projectid'));
270 if ($result < 0) {
271 setEventMessages($object->error, $object->errors, 'errors');
272 }
273 }
274
275 if ($action == 'setref_customer' && $permissiontoadd) {
276 $result = $object->fetch($id);
277 if ($result < 0) {
278 setEventMessages($object->error, $object->errors, 'errors');
279 }
280
281 $result = $object->setValueFrom('ref_customer', GETPOST('ref_customer', 'alpha'), '', null, 'text', '', $user, 'SHIPPING_MODIFY');
282 if ($result < 0) {
283 setEventMessages($object->error, $object->errors, 'errors');
284 $action = 'editref_customer';
285 } else {
286 header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
287 exit;
288 }
289 }
290
291 if ($action == 'update_extras' && $permissiontoeditextra) {
292 $object->oldcopy = dol_clone($object, 2);
293
294 $attribute_name = GETPOST('attribute', 'aZ09');
295
296 // Fill array 'array_options' with data from update form
297 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
298 if ($ret < 0) {
299 $error++;
300 }
301
302 if (!$error) {
303 // Actions on extra fields
304 $result = $object->updateExtraField($attribute_name, 'SHIPPING_MODIFY');
305 if ($result < 0) {
306 setEventMessages($object->error, $object->errors, 'errors');
307 $error++;
308 }
309 }
310
311 if ($error) {
312 $action = 'edit_extras';
313 }
314 }
315
316 // Create shipment
317 if ($action == 'add' && $permissiontoadd) {
318 $db->begin();
319
320 if ($origin && $origin_id > 0) {
321 // We will loop on each line of the original document to complete the shipping object with various info and quantity to deliver
322 $classname = ucfirst($origin);
323 $objectsrc = new $classname($db);
324 '@phan-var-force Facture|Commande $objectsrc';
325 $objectsrc->fetch($origin_id);
326 $object->socid = $objectsrc->socid;
327 }
328
329 if (GETPOSTINT('socid') < 1 && $object->socid < 1) {
330 $error++;
331 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty")), null, 'errors');
332 $action = 'create';
333 }
334
335 if (!$origin && getDolGlobalString('SHIPMENT_STANDALONE')) {
336 $object->socid = GETPOSTINT('socid');
337 $object->fetch_thirdparty();
338
339 $object->origin = $origin; // deprecated
340 $object->origin_type = $origin_type;
341 $object->origin_id = $origin_id;
342 $object->fk_project = GETPOSTINT('projectid');
343 $object->weight = GETPOST('weight') == '' ? '' : GETPOSTFLOAT('weight');
344 $object->sizeH = GETPOST('sizeH') == '' ? '' : GETPOSTFLOAT('sizeH');
345 $object->sizeW = GETPOST('sizeW') == '' ? '' : GETPOSTFLOAT('sizeW');
346 $object->sizeS = GETPOST('sizeS') == '' ? '' : GETPOSTFLOAT('sizeS');
347 $object->size_units = GETPOSTINT('size_units');
348 $object->weight_units = GETPOSTINT('weight_units');
349 $object->ref_customer = GETPOST('ref_customer', 'alpha');
350 $object->model_pdf = GETPOST('model');
351 $object->date_delivery = $date_delivery; // Date delivery planned
352 $object->date_shipping = $date_shipping; // Sending date
353 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
354 $object->tracking_number = GETPOST('tracking_number', 'alpha');
355 $object->note = GETPOST('note_private', 'restricthtml'); // deprecated
356 $object->note_private = GETPOST('note_private', 'restricthtml');
357 $object->note_public = GETPOST('note_public', 'restricthtml');
358 $object->fk_incoterms = GETPOSTINT('incoterm_id');
359 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
360
361 $product = new Product($db);
362
363 // Fill array 'array_options' with data from add form
364 $ret = $extrafields->setOptionalsFromPost(null, $object);
365 if ($ret < 0) {
366 $error++;
367 }
368
369 if (!$error) {
370 $ret = $object->create($user);
371 if ($ret <= 0) {
372 setEventMessages($object->error, $object->errors, 'errors');
373 $error++;
374 }
375 }
376 }
377
378 if ($origin && $origin_id > 0) {
379 $object->origin = $origin; // deprecated
380 $object->origin_type = $origin_type;
381 $object->origin_id = $origin_id;
382 $object->fk_project = GETPOSTINT('projectid');
383 $object->weight = GETPOST('weight') == '' ? '' : GETPOSTFLOAT('weight');
384 $object->sizeH = GETPOST('sizeH') == '' ? '' : GETPOSTFLOAT('sizeH');
385 $object->sizeW = GETPOST('sizeW') == '' ? '' : GETPOSTFLOAT('sizeW');
386 $object->sizeS = GETPOST('sizeS') == '' ? '' : GETPOSTFLOAT('sizeS');
387 $object->size_units = GETPOSTINT('size_units');
388 $object->weight_units = GETPOSTINT('weight_units');
389 $object->ref_customer = GETPOST('ref_customer', 'alpha');
390 $object->model_pdf = GETPOST('model');
391 $object->date_delivery = $date_delivery; // Date delivery planned
392 $object->date_shipping = $date_shipping; // Sending date
393 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
394 $object->tracking_number = GETPOST('tracking_number', 'alpha');
395 $object->note = GETPOST('note_private', 'restricthtml'); // deprecated
396 $object->note_private = GETPOST('note_private', 'restricthtml');
397 $object->note_public = GETPOST('note_public', 'restricthtml');
398 $object->fk_incoterms = GETPOSTINT('incoterm_id');
399 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
400
401 // We will loop on each line of the original document to complete the shipping object with various info and quantity to deliver
402 $classname = ucfirst($object->origin_type);
403 $objectsrc = new $classname($db);
404 '@phan-var-force Facture|Commande $objectsrc';
405 $objectsrc->fetch($object->origin_id);
406
407 $object->socid = $objectsrc->socid;
408 $object->fk_delivery_address = $objectsrc->fk_delivery_address;
409
410 $product = new Product($db);
411
412 $batch_line = array();
413 $stockLine = array();
414 $array_options = array();
415
416 $num = count($objectsrc->lines);
417 $totalqty = 0;
418
419 $product_batch_used = array();
420
421 for ($i = 0; $i < $num; $i++) {
422 $idl = "idl" . $i;
423
424 $sub_qty = array();
425 $subtotalqty = 0;
426
427 $j = 0;
428
429 $batch = "batchl" . $i . "_0";
430 $stockLocation = "ent1" . $i . "_0";
431 $qty = "qtyl" . $i;
432
433 $is_batch_or_serial = 0;
434 if (!empty($objectsrc->lines[$i]->fk_product)) {
435 $resultFetch = $product->fetch($objectsrc->lines[$i]->fk_product, '', '', '', 1, 1, 1);
436 if ($resultFetch < 0) {
437 setEventMessages($product->error, $product->errors, 'errors');
438 }
439 $is_batch_or_serial = $product->status_batch;
440 }
441
442 // If product need a batch or serial number
443 if (isModEnabled('productbatch') && $objectsrc->lines[$i]->product_tobatch) {
444 if (GETPOSTISSET($batch)) {
445 //shipment line with batch-enable product
446 $qty .= '_' . $j;
447 while (GETPOSTISSET($batch)) {
448 // save line of detail into sub_qty
449 $sub_qty[$j]['q'] = price2num(GETPOST($qty, 'alpha'), 'MS'); // the qty we want to move for this stock record
450 $sub_qty[$j]['id_batch'] = GETPOSTINT($batch); // the id into llx_product_batch of stock record to move
451 $subtotalqty += $sub_qty[$j]['q'];
452
453 if ($is_batch_or_serial == 2 && ($sub_qty[$j]['q'] > 1 || ($sub_qty[$j]['q'] > 0 && in_array($sub_qty[$j]['id_batch'], $product_batch_used)))) {
454 setEventMessages($langs->trans("TooManyQtyForSerialNumber", $product->ref, ''), null, 'errors');
455 $totalqty = 0;
456 break 2;
457 }
458
459 if ($is_batch_or_serial == 2 && $sub_qty[$j]['q'] > 0) {
460 // we stock the batch id to test later if the same serial is shipped on another line for the same product
461 $product_batch_used[] = $sub_qty[$j]['id_batch'];
462 }
463
464 $j++;
465 $batch = "batchl" . $i . "_" . $j;
466 $qty = "qtyl" . $i . '_' . $j;
467 }
468
469 $batch_line[$i]['detail'] = $sub_qty; // array of details
470 $batch_line[$i]['qty'] = $subtotalqty;
471 $batch_line[$i]['ix_l'] = GETPOSTINT($idl);
472
473 $totalqty += $subtotalqty;
474 } else {
475 // No detail were provided for lots, so if a qty was provided, we can throw an error.
476 if (GETPOST($qty)) {
477 // We try to set an amount
478 // Case we don't use the list of available qty for each warehouse/lot
479 // GUI does not allow this yet
480 setEventMessages($langs->trans("StockIsRequiredToChooseWhichLotToUse") . ' (' . $langs->trans("Line") . ' ' . GETPOSTINT($idl) . ')', null, 'errors');
481 $error++;
482 }
483 }
484 } elseif (GETPOSTISSET($stockLocation)) {
485 //shipment line from multiple stock locations
486 $qty .= '_' . $j;
487 while (GETPOSTISSET($stockLocation)) {
488 // save sub line of warehouse
489 $stockLine[$i][$j]['qty'] = price2num(GETPOST($qty, 'alpha'), 'MS');
490 $stockLine[$i][$j]['warehouse_id'] = GETPOSTINT($stockLocation);
491 $stockLine[$i][$j]['ix_l'] = GETPOSTINT($idl);
492
493 $totalqty += price2num(GETPOST($qty, 'alpha'), 'MS');
494 $subtotalqty += price2num(GETPOST($qty, 'alpha'), 'MS');
495
496 $j++;
497 $stockLocation = "ent1" . $i . "_" . $j;
498 $qty = "qtyl" . $i . '_' . $j;
499 }
500 } else {
501 //shipment line for product with no batch management and no multiple stock location
502 if (GETPOSTFLOAT($qty) > 0) {
503 $totalqty += price2num(GETPOST($qty, 'alpha'), 'MS');
504 $subtotalqty = price2num(GETPOST($qty, 'alpha'), 'MS');
505 }
506 }
507
508 // check qty shipped not greater than ordered
509 if (getDolGlobalInt("MAIN_DONT_SHIP_MORE_THAN_ORDERED") && $subtotalqty > $objectsrc->lines[$i]->qty) {
510 setEventMessages($langs->trans("ErrorTooMuchShipped", $i + 1), null, 'errors');
511 $error++;
512 continue;
513 }
514
515 // Extrafields
516 $array_options[$i] = $extrafields->getOptionalsFromPost($object->table_element_line, (string) $i);
517 // Unset extrafield
518 if (isset($extrafields->attributes[$object->table_element_line]['label']) && is_array($extrafields->attributes[$object->table_element_line]['label'])) {
519 // Get extra fields
520 foreach ($extrafields->attributes[$object->table_element_line]['label'] as $key => $value) {
521 unset($_POST["options_" . $key]);
522 }
523 }
524 }
525
526 if (($totalqty > 0 || getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) && !$error) { // There is at least one thing to ship and no error
527 $selected_subtotal_lines = GETPOST('subtotal_toselect', 'array:int');
528 for ($i = 0; $i < $num; $i++) {
529 $qty = "qtyl" . $i;
530
531 if (!isset($batch_line[$i])) {
532 // not batch mode
533 if (isset($stockLine[$i])) {
534 //shipment from multiple stock locations
535 $nbstockline = count($stockLine[$i]);
536 for ($j = 0; $j < $nbstockline; $j++) {
537 if ($stockLine[$i][$j]['qty'] > 0 || ($stockLine[$i][$j]['qty'] == 0 && getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
538 $ret = $object->addline($stockLine[$i][$j]['warehouse_id'], $stockLine[$i][$j]['ix_l'], (float) $stockLine[$i][$j]['qty'], $array_options[$i]);
539 if ($ret < 0) {
540 setEventMessages($object->error, $object->errors, 'errors');
541 $error++;
542 }
543 }
544 }
545 } else {
546 if (GETPOSTFLOAT($qty) > 0 || getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {
547 $ent = "entl" . $i;
548 $idl = "idl" . $i;
549 $entrepot_id = is_numeric(GETPOSTINT($ent)) ? GETPOSTINT($ent) : GETPOSTINT('entrepot_id');
550 if ($entrepot_id < 0) {
551 $entrepot_id = '';
552 }
553 if (!($objectsrc->lines[$i]->fk_product > 0)) {
554 $entrepot_id = 0;
555 }
556
557
558 $ret = $object->addline($entrepot_id, GETPOSTINT($idl), (float) price2num(GETPOSTFLOAT($qty), 'MS'), $array_options[$i]);
559 if ($ret < 0) {
560 setEventMessages($object->error, $object->errors, 'errors');
561 $error++;
562 }
563 }
564 if (isModEnabled('subtotals') && $objectsrc->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE && in_array($objectsrc->lines[$i]->id, $selected_subtotal_lines)) {
565 $object->addSubtotalLine($langs, $objectsrc->lines[$i]->desc, (int) $objectsrc->lines[$i]->qty, $objectsrc->lines[$i]->extraparams, $objectsrc->lines[$i]->id);
566 }
567 }
568 } else {
569 // batch mode
570 if ($batch_line[$i]['qty'] > 0 || ($batch_line[$i]['qty'] == 0 && getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {
571 $origin_line_id = (int) $batch_line[$i]['ix_l'];
572 $origin_line = new OrderLine($db);
573 $res = $origin_line->fetch($origin_line_id);
574 if ($res <= 0) {
575 $error++;
576 setEventMessages($origin_line->error, $origin_line->errors, 'errors');
577 }
578 $ret = $object->addline_batch($batch_line[$i], $array_options[$i], $origin_line);
579 if ($ret < 0) {
580 setEventMessages($object->error, $object->errors, 'errors');
581 $error++;
582 }
583 }
584 }
585 }
586 // Fill array 'array_options' with data from add form
587 $ret = $extrafields->setOptionalsFromPost(null, $object);
588 if ($ret < 0) {
589 $error++;
590 }
591
592 if (!$error) {
593 $ret = $object->create($user); // This create shipment (like Odoo picking) and lines of shipments. Stock movement will be done when validating or closing shipment.
594 if ($ret <= 0) {
595 setEventMessages($object->error, $object->errors, 'errors');
596 $error++;
597 }
598 }
599 } elseif (!$error) {
600 $labelfieldmissing = $langs->transnoentitiesnoconv("QtyToShip");
601 if (isModEnabled('stock')) {
602 $labelfieldmissing .= '/' . $langs->transnoentitiesnoconv("Warehouse");
603 }
604 setEventMessages($langs->trans("ErrorFieldRequired", $labelfieldmissing), null, 'errors');
605 $error++;
606 }
607 }
608 if (!$error) {
609 $db->commit();
610 $object->fetch_lines();
611 foreach ($object->lines as $line) {
612 $objectsrc_line = new $objectsrc->class_element_line($db);
613 '@phan-var-force CommonObjectLine $objectsrc_line';
614 $objectsrc_line->fetch($line->origin_line_id);
615 $line->extraparams = $objectsrc_line->extraparams;
616 $line->setExtraParameters();
617 }
618 header("Location: card.php?id=" . $object->id);
619 exit;
620 } else {
621 $db->rollback();
622 //$_GET["commande_id"] = GETPOSTINT('commande_id');
623 $action = 'create';
624 }
625 } elseif ($action == 'create_delivery' && getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && $user->hasRight('expedition', 'delivery', 'creer')) {
626 // Build a receiving receipt
627 $db->begin();
628
629 $result = $object->create_delivery($user);
630 if ($result > 0) {
631 $db->commit();
632
633 header("Location: " . DOL_URL_ROOT . '/delivery/card.php?action=create_delivery&token=' . newToken() . '&id=' . $result);
634 exit;
635 } else {
636 $db->rollback();
637
638 setEventMessages($object->error, $object->errors, 'errors');
639 }
640 } elseif (
641 $action == 'confirm_valid' && $confirm == 'yes' && ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'creer'))
642 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'shipping_advance', 'validate')))
643 ) {
644 $object->fetch_thirdparty();
645
646 $result = $object->valid($user);
647
648 if ($result < 0) {
649 setEventMessages($object->error, $object->errors, 'errors');
650 } else {
651 // Define output language
652 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
653 $outputlangs = $langs;
654 $newlang = '';
655 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
656 $newlang = GETPOST('lang_id', 'aZ09');
657 }
658 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
659 $newlang = $object->thirdparty->default_lang;
660 }
661 if (!empty($newlang)) {
662 $outputlangs = new Translate("", $conf);
663 $outputlangs->setDefaultLang($newlang);
664 }
665 $model = $object->model_pdf;
666 $ret = $object->fetch($id); // Reload to get new records
667
668 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
669 if ($result < 0) {
670 dol_print_error($db, $object->error, $object->errors);
671 }
672 }
673 }
674 } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $user->hasRight('expedition', 'creer')) {
675 $also_update_stock = (GETPOST('alsoUpdateStock', 'alpha') ? 1 : 0);
676 $result = $object->cancel($user, 0, (bool) $also_update_stock);
677 if ($result > 0) {
678 $result = $object->setStatut(Expedition::STATUS_CANCELED);
679 } else {
680 setEventMessages($object->error, $object->errors, 'errors');
681 }
682 } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('expedition', 'supprimer')) {
683 $also_update_stock = (GETPOST('alsoUpdateStock', 'alpha') ? 1 : 0);
684 $result = $object->delete($user, 0, (bool) $also_update_stock);
685 if ($result > 0) {
686 header("Location: " . DOL_URL_ROOT . '/expedition/index.php');
687 exit;
688 } else {
689 setEventMessages($object->error, $object->errors, 'errors');
690 }
691 // TODO add alternative status
692 //} elseif ($action == 'reopen' && ($user->hasRight('expedition', 'creer') || $user->hasRight('expedition', 'shipping_advance', 'validate')))
693 //{
694 // $result = $object->setStatut(Expedition::STATUS_DRAFT);
695 // if ($result < 0)
696 // {
697 // setEventMessages($object->error, $object->errors, 'errors');
698 // }
699 //}
700 } elseif ($action == 'confirm_delete_subtotalline' && $confirm == 'yes' && $permissiontoadd) {
701 $result = $object->deleteSubtotalLine($langs, GETPOSTINT('lineid'), (bool) GETPOST('deletecorrespondingsubtotalline'), $user);
702 if ($result > 0) {
703 // reorder lines
704 $object->line_order(true, 'ASC', false);
705 // Define output language
706 $outputlangs = $langs;
707 $newlang = '';
708 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
709 $newlang = GETPOST('lang_id', 'aZ09');
710 }
711 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
712 $newlang = $object->thirdparty->default_lang;
713 }
714 if (!empty($newlang)) {
715 $outputlangs = new Translate("", $conf);
716 $outputlangs->setDefaultLang($newlang);
717 }
718 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
719 $ret = $object->fetch($object->id); // Reload to get new records
720 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
721 }
722
723 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
724 exit;
725 } else {
726 setEventMessages($object->error, $object->errors, 'errors');
727 }
728 } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
729 // Remove a product line
730 $result = $object->deleteLine($user, $lineid);
731 if ($result > 0) {
732 // reorder lines
733 $object->line_order(true);
734 // Define output language
735 $outputlangs = $langs;
736 $newlang = '';
737 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
738 $newlang = GETPOST('lang_id', 'aZ09');
739 }
740 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
741 $newlang = $object->thirdparty->default_lang;
742 }
743 if (!empty($newlang)) {
744 $outputlangs = new Translate("", $conf);
745 $outputlangs->setDefaultLang($newlang);
746 }
747 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
748 $ret = $object->fetch($object->id); // Reload to get new records
749 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
750 }
751
752 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
753 exit;
754 } else {
755 setEventMessages($object->error, $object->errors, 'errors');
756 }
757 } elseif ($action == 'confirm_sign' && $confirm == 'yes' && $user->hasRight('expedition', 'creer')) {
758 $result = $object->setSignedStatus($user, GETPOSTINT('signed_status'), 0, 'SHIPPING_MODIFY');
759 if ($result >= 0) {
760 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
761 exit;
762 } else {
763 setEventMessages($object->error, $object->errors, 'errors');
764 }
765 } elseif ($action == 'confirm_unsign' && $confirm == 'yes' && $user->hasRight('expedition', 'creer')) {
766 $result = $object->setSignedStatus($user, Expedition::$SIGNED_STATUSES['STATUS_NO_SIGNATURE'], 0, 'SHIPPING_MODIFY');
767 if ($result >= 0) {
768 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
769 exit;
770 } else {
771 setEventMessages($object->error, $object->errors, 'errors');
772 }
773 } elseif ($action == 'setdate_livraison' && $user->hasRight('expedition', 'creer')) {
774 $datedelivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
775
776 $object->fetch($id);
777 $result = $object->setDeliveryDate($user, $datedelivery); // Set the planned delivery date
778 if ($result < 0) {
779 setEventMessages($object->error, $object->errors, 'errors');
780 }
781 } elseif ($action == 'setdate_shipping' && $user->hasRight('expedition', 'creer')) {
782 $dateshipping = dol_mktime(GETPOSTINT('ship_hour'), GETPOSTINT('ship_min'), 0, GETPOSTINT('ship_month'), GETPOSTINT('ship_day'), GETPOSTINT('ship_year'));
783
784 $object->fetch($id);
785 $result = $object->setShippingDate($user, $dateshipping);
786 if ($result < 0) {
787 setEventMessages($object->error, $object->errors, 'errors');
788 }
789 } elseif (in_array($action, array('settracking_number', 'settracking_url', 'settrueWeight', 'settrueWidth', 'settrueHeight', 'settrueDepth', 'setshipping_method_id')) && $user->hasRight('expedition', 'creer')) {
790 // Action update
791 $error = 0;
792
793 if ($action == 'settracking_number') { // Test on permission not required
794 $object->tracking_number = trim(GETPOST('tracking_number', 'alpha'));
795 $object->tracking_number = preg_replace('/\s+/', '', $object->tracking_number);
796 }
797 if ($action == 'settracking_url') { // Test on permission not required
798 $object->tracking_url = trim(GETPOST('tracking_url', 'restricthtml'));
799 }
800
801 if ($action == 'settrueWeight') { // Test on permission not required
802 $object->trueWeight = GETPOSTFLOAT('trueWeight');
803 $object->weight_units = GETPOSTINT('weight_units');
804 }
805 if ($action == 'settrueWidth') { // Test on permission not required
806 $object->trueWidth = GETPOSTFLOAT('trueWidth');
807 }
808 if ($action == 'settrueHeight') { // Test on permission not required
809 $object->trueHeight = GETPOSTFLOAT('trueHeight');
810 $object->size_units = GETPOSTINT('size_units');
811 }
812 if ($action == 'settrueDepth') { // Test on permission not required
813 $object->trueDepth = GETPOSTFLOAT('trueDepth');
814 }
815 if ($action == 'setshipping_method_id') { // Test on permission not required
816 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
817 }
818
819 if ($object->update($user) >= 0) {
820 header("Location: card.php?id=" . $object->id);
821 exit;
822 }
823 setEventMessages($object->error, $object->errors, 'errors');
824 $action = "";
825 } elseif ($action == 'classifybilled' && $permissiontoadd) {
826 $object->fetch($id);
827 $result = $object->setBilled();
828 if ($result >= 0) {
829 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
830 exit();
831 }
832 setEventMessages($object->error, $object->errors, 'errors');
833 } elseif ($action == 'classifyclosed' && $permissiontoadd) {
834 $object->fetch($id);
835 $result = $object->setClosed();
836 if ($result >= 0) {
837 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
838 exit();
839 }
840 setEventMessages($object->error, $object->errors, 'errors');
841 } elseif ($action == 'deleteline' && !empty($line_id) && $permissiontoadd) {
842 // delete a line
843 $error = 0;
844 $object->fetch($id);
845 $lines = $object->lines;
846 $line = new ExpeditionLigne($db);
847 $line->fk_expedition = $object->id;
848
849 $num_prod = count($lines);
850 for ($i = 0; $i < $num_prod; $i++) {
851 if ($lines[$i]->id == $line_id) {
852 // A standalone shipment (SHIPMENT_STANDALONE) loads its lines with fetch_lines_free(),
853 // which does not set details_entrepot, so count() must not be called on it blindly.
854 if (is_array($lines[$i]->details_entrepot) && count($lines[$i]->details_entrepot) > 1) {
855 // delete multi warehouse lines
856 foreach ($lines[$i]->details_entrepot as $details_entrepot) {
857 $line->id = $details_entrepot->line_id;
858 if (!$error && $line->delete($user) < 0) {
859 $error++;
860 }
861 }
862 } else {
863 // delete single warehouse line
864 $line->id = $line_id;
865 if (!$error && $line->delete($user) < 0) {
866 $error++;
867 }
868 }
869 }
870 unset($_POST["lineid"]);
871 }
872
873 if (!$error) {
874 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
875 exit();
876 } else {
877 setEventMessages($line->error, $line->errors, 'errors');
878 }
879 } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('cancel', 'alpha') != $langs->trans("Cancel")) {
880 if (!$origin && getDolGlobalString('SHIPMENT_STANDALONE')) {
881 // Update a line
882 // Clean parameters
883
884 if (!$object->fetch($id) > 0) {
886 }
887 $object->fetch_thirdparty();
888
889 $qty = GETPOST('qty', 'alpha');
890 $description = '';
891 $fk_parent = 0;
892 $element_type = 'shipping';
893 $fk_unit = '';
894 $fk_product = 0;
895 $rang = 0;
896
897 // Extrafields
898 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
899 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
900 // Unset extrafield
901 if (is_array($extralabelsline)) {
902 // Get extra fields
903 foreach ($extralabelsline as $key => $value) {
904 unset($_POST["options_" . $key]);
905 }
906 }
907
908 $shipline = new ExpeditionLigne($db);
909 $shipline->fetch(GETPOSTINT('lineid'));
910
911
912 if (!$error) {
913 $result = $object->updatelinefree(GETPOSTINT('lineid'), (float) $qty, $element_type, $fk_product, GETPOSTINT('units'), $rang, $description, $fk_parent, 0, $array_options);
914
915 if ($result >= 0) {
916 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
917 // Define output language
918 $outputlangs = $langs;
919 $newlang = '';
920 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
921 $newlang = GETPOST('lang_id', 'aZ09');
922 }
923 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
924 $newlang = $object->thirdparty->default_lang;
925 }
926 if (!empty($newlang)) {
927 $outputlangs = new Translate("", $conf);
928 $outputlangs->setDefaultLang($newlang);
929 $outputlangs->load('products');
930 }
931
932 $ret = $object->fetch($object->id); // Reload to get new records
933 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
934 }
935 unset($_POST['qty']);
936 unset($_POST['units']);
937 } else {
938 setEventMessages($object->error, $object->errors, 'errors');
939 }
940 }
941 } elseif ($origin && $origin_id > 0) {
942 // Update a line
943 // Clean parameters
944 $qty = 0;
945 $entrepot_id = 0;
946 $batch_id = 0;
947
948 $lines = $object->lines;
949 $num_prod = count($lines);
950 for ($i = 0; $i < $num_prod; $i++) {
951 if ($lines[$i]->id == $line_id) { // we have found line to update
952 $update_done = false;
953 $line = new ExpeditionLigne($db);
954 $line->fk_expedition = $object->id;
955
956 // Extrafields Lines
957 $line->array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
958 // Unset extrafield POST Data
959 if (is_array($extrafields->attributes[$object->table_element_line]['label'])) {
960 foreach ($extrafields->attributes[$object->table_element_line]['label'] as $key => $value) {
961 unset($_POST["options_" . $key]);
962 }
963 }
964 $line->fk_product = $lines[$i]->fk_product;
965 if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) {
966 // line with lot
967 foreach ($lines[$i]->detail_batch as $detail_batch) {
968 $lotStock = new Productbatch($db);
969 $batch = "batchl" . $detail_batch->fk_expeditiondet . "_" . $detail_batch->fk_origin_stock;
970 $qty = "qtyl" . $detail_batch->fk_expeditiondet . '_' . $detail_batch->id;
971 $batch_id = GETPOSTINT($batch);
972 $batch_qty = GETPOSTFLOAT($qty);
973 if (!empty($batch_id)) {
974 if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0) { // $line is ExpeditionLine
975 if ($lines[$i]->entrepot_id != 0) {
976 // allow update line entrepot_id if not multi warehouse shipping
977 $line->entrepot_id = $lotStock->warehouseid;
978 }
979
980 // detail_batch can be an object with keys, or an array of ExpeditionLineBatch
981 if (empty($line->detail_batch)) {
982 $line->detail_batch = new stdClass();
983 }
984
985 $line->detail_batch->fk_origin_stock = $batch_id;
986 $line->detail_batch->batch = $lotStock->batch;
987 $line->detail_batch->id = $detail_batch->id;
988 $line->detail_batch->entrepot_id = $lotStock->warehouseid;
989 $line->detail_batch->qty = $batch_qty;
990 if ($line->update($user) < 0) {
991 setEventMessages($line->error, $line->errors, 'errors');
992 $error++;
993 } else {
994 $update_done = true;
995 }
996 } else {
997 setEventMessages($lotStock->error, $lotStock->errors, 'errors');
998 $error++;
999 }
1000 }
1001 unset($_POST[$batch]);
1002 unset($_POST[$qty]);
1003 }
1004 // add new batch
1005 $lotStock = new Productbatch($db);
1006 $batch = "batchl" . $line_id . "_0";
1007 $qty = "qtyl" . $line_id . "_0";
1008 $batch_id = GETPOSTINT($batch);
1009 $batch_qty = GETPOSTFLOAT($qty);
1010 $lineIdToAddLot = 0;
1011 if ($batch_qty > 0 && !empty($batch_id)) {
1012 if ($lotStock->fetch($batch_id) > 0) {
1013 // check if lotStock warehouse id is same as line warehouse id
1014 if ($lines[$i]->entrepot_id > 0) {
1015 // single warehouse shipment line
1016 if ($lines[$i]->entrepot_id == $lotStock->warehouseid) {
1017 $lineIdToAddLot = $line_id;
1018 }
1019 } elseif (count($lines[$i]->details_entrepot) > 1) {
1020 // multi warehouse shipment lines
1021 foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
1022 if ($detail_entrepot->entrepot_id == $lotStock->warehouseid) {
1023 $lineIdToAddLot = $detail_entrepot->line_id;
1024 }
1025 }
1026 }
1027 if ($lineIdToAddLot) {
1028 // add lot to existing line
1029 if ($line->fetch($lineIdToAddLot) > 0) {
1030 $line->detail_batch->fk_origin_stock = $batch_id;
1031 $line->detail_batch->batch = $lotStock->batch;
1032 $line->detail_batch->entrepot_id = $lotStock->warehouseid;
1033 $line->detail_batch->qty = $batch_qty;
1034 if ($line->update($user) < 0) {
1035 setEventMessages($line->error, $line->errors, 'errors');
1036 $error++;
1037 } else {
1038 $update_done = true;
1039 }
1040 } else {
1041 setEventMessages($line->error, $line->errors, 'errors');
1042 $error++;
1043 }
1044 } else {
1045 // create new line with new lot
1046 $line->origin_line_id = $lines[$i]->origin_line_id;
1047 $line->entrepot_id = $lotStock->warehouseid;
1048 $line->detail_batch[0] = new ExpeditionLineBatch($db);
1049 $line->detail_batch[0]->fk_origin_stock = $batch_id;
1050 $line->detail_batch[0]->batch = $lotStock->batch;
1051 $line->detail_batch[0]->entrepot_id = $lotStock->warehouseid;
1052 $line->detail_batch[0]->qty = $batch_qty;
1053 if ($object->create_line_batch($line, $line->array_options) < 0) {
1054 setEventMessages($object->error, $object->errors, 'errors');
1055 $error++;
1056 } else {
1057 $update_done = true;
1058 }
1059 }
1060 } else {
1061 setEventMessages($lotStock->error, $lotStock->errors, 'errors');
1062 $error++;
1063 }
1064 }
1065 } else {
1066 if ($lines[$i]->fk_product > 0) {
1067 // line without lot
1068 if ($lines[$i]->entrepot_id == 0) {
1069 // single warehouse shipment line or line in several warehouses context but with warehouse not defined
1070 $stockLocation = "entl" . $line_id;
1071 $qty = "qtyl" . $line_id;
1072 $line->id = $line_id;
1073 $line->entrepot_id = GETPOSTINT((string) $stockLocation);
1074 $line->qty = GETPOSTFLOAT($qty);
1075 if ($line->update($user) < 0) {
1076 setEventMessages($line->error, $line->errors, 'errors');
1077 $error++;
1078 } else {
1079 $update_done = true;
1080 }
1081 unset($_POST[$stockLocation]);
1082 unset($_POST[$qty]);
1083 } elseif ($lines[$i]->entrepot_id > 0) {
1084 // single warehouse shipment line
1085 $stockLocation = "entl" . $line_id;
1086 $qty = "qtyl" . $line_id;
1087 $line->id = $line_id;
1088 $line->entrepot_id = GETPOSTINT($stockLocation);
1089 $line->qty = GETPOSTFLOAT($qty);
1090 if ($line->update($user) < 0) {
1091 setEventMessages($line->error, $line->errors, 'errors');
1092 $error++;
1093 } else {
1094 $update_done = true;
1095 }
1096 unset($_POST[$stockLocation]);
1097 unset($_POST[$qty]);
1098 } elseif (count($lines[$i]->details_entrepot) > 1) {
1099 // multi warehouse shipment lines
1100 foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
1101 if (!$error) {
1102 $stockLocation = "entl" . $detail_entrepot->line_id;
1103 $qty = "qtyl" . $detail_entrepot->line_id;
1104 $warehouse = GETPOSTINT($stockLocation);
1105 if (!empty($warehouse)) {
1106 $line->id = $detail_entrepot->line_id;
1107 $line->entrepot_id = $warehouse;
1108 $line->qty = GETPOSTFLOAT($qty);
1109 if ($line->update($user) < 0) {
1110 setEventMessages($line->error, $line->errors, 'errors');
1111 $error++;
1112 } else {
1113 $update_done = true;
1114 }
1115 }
1116 unset($_POST[$stockLocation]);
1117 unset($_POST[$qty]);
1118 }
1119 }
1120 } elseif (!isModEnabled('stock') && !isModEnabled('productbatch')) { // both product batch and stock are not activated.
1121 $qty = "qtyl" . $line_id;
1122 $line->id = $line_id;
1123 $line->qty = GETPOSTFLOAT($qty);
1124 $line->entrepot_id = 0;
1125 if ($line->update($user) < 0) {
1126 setEventMessages($line->error, $line->errors, 'errors');
1127 $error++;
1128 } else {
1129 $update_done = true;
1130 }
1131 unset($_POST[$qty]);
1132 }
1133 } else {
1134 // Product no predefined
1135 $qty = "qtyl" . $line_id;
1136 $line->id = $line_id;
1137 $line->qty = GETPOSTFLOAT($qty);
1138 $line->entrepot_id = 0;
1139 if ($line->update($user) < 0) {
1140 setEventMessages($line->error, $line->errors, 'errors');
1141 $error++;
1142 } else {
1143 $update_done = true;
1144 }
1145 unset($_POST[$qty]);
1146 }
1147 }
1148
1149 if (empty($update_done)) {
1150 $line->id = $lines[$i]->id;
1151 $resultInsertExtraFields = $line->insertExtraFields();
1152 if ($resultInsertExtraFields < 0) {
1153 setEventMessages($line->error, $line->errors, 'errors');
1154 $error++;
1155 } elseif ($resultInsertExtraFields > 0) {
1156 $update_done = true;
1157 }
1158 }
1159
1160 if (empty($update_done) && !$error) {
1161 setEventMessages($langs->trans('NoShipmentLineChangeDetected'), null, 'warnings');
1162 }
1163 }
1164 }
1165
1166 unset($_POST["lineid"]);
1167
1168 if (!$error) {
1169 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1170 // Define output language
1171 $outputlangs = $langs;
1172 $newlang = '';
1173 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1174 $newlang = GETPOST('lang_id', 'aZ09');
1175 }
1176 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1177 $newlang = $object->thirdparty->default_lang;
1178 }
1179 if (!empty($newlang)) {
1180 $outputlangs = new Translate("", $conf);
1181 $outputlangs->setDefaultLang($newlang);
1182 }
1183
1184 $ret = $object->fetch($object->id); // Reload to get new records
1185 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1186 }
1187 } else {
1188 header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // To redisplay the form being edited
1189 exit();
1190 }
1191 }
1192 } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
1193 header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // To redisplay the form being edited
1194 exit();
1195 } elseif ($action == 'addline' && !$origin && getDolGlobalString('SHIPMENT_STANDALONE') && $usercancreate) { // Add a new line
1196 $langs->load('errors');
1197 $error = 0;
1198 $line_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
1199 $predef = '';
1200 $description = '';
1201 $fk_parent = 0;
1202 $fk_elementdet = '';
1203 $element_type = 'shipping';
1204 $fk_unit = '';
1205 $idprod = 0;
1206 $fk_product = 0;
1207 $fk_entrepot = '';
1208 $rang = '';
1209 $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
1210 if ($prod_entry_mode == 'free') {
1211 $idprod = 0;
1212 } else {
1213 $idprod = GETPOSTINT('idprod');
1214 if (getDolGlobalString('MAIN_DISABLE_FREE_LINES') && $idprod <= 0) {
1215 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors');
1216 $error++;
1217 }
1218 }
1219
1220 $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
1221
1222 // Extrafields
1223 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1224 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1225 // Unset extrafield
1226 if (is_array($extralabelsline)) {
1227 // Get extra fields
1228 foreach ($extralabelsline as $key => $value) {
1229 unset($_POST["options_".$key]);
1230 }
1231 }
1232
1233 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
1234 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
1235 $error++;
1236 }
1237
1238 if ($qty == '') {
1239 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
1240 $error++;
1241 }
1242 if ($qty < 0) {
1243 setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
1244 $error++;
1245 }
1246 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
1247 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
1248 $error++;
1249 }
1250
1251 if (!$error && isModEnabled('variants') && $prod_entry_mode != 'free') {
1252 if ($combinations = GETPOST('combinations', 'array')) {
1253 // Check if there is a product with the given combination
1254 $prodcomb = new ProductCombination($db);
1255
1256 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1257 $idprod = $res->fk_product_child;
1258 $fk_product = $idprod; // Update $fk_product with the fetched child product
1259 } else {
1260 setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors');
1261 $error++;
1262 }
1263 }
1264 }
1265
1266 if (!$error && ($qty >= 0) && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
1267 // Clean parameters
1268 if (!empty($idprod) && $idprod > 0) {
1269 $prod = new Product($db);
1270 $prod->fetch($idprod);
1271 $desc = $prod->label;
1272 $description = $desc;
1273 // Define output language
1274 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
1275 $outputlangs = $langs;
1276 $newlang = '';
1277 if (GETPOST('lang_id', 'aZ09')) {
1278 $newlang = GETPOST('lang_id', 'aZ09');
1279 }
1280 if (empty($newlang)) {
1281 $newlang = $object->thirdparty->default_lang;
1282 }
1283 if (!empty($newlang)) {
1284 $outputlangs = new Translate("", $conf);
1285 $outputlangs->setDefaultLang($newlang);
1286 }
1287
1288 $description = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
1289 } else {
1290 $description = $prod->description;
1291 }
1292 if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 0) {
1293 $description = dol_concatdesc($desc, $line_desc, false, getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION') ? true : false);
1294 } else {
1295 $description = $line_desc;
1296 }
1297
1298 // Add custom code and origin country into description
1299 if (!getDolGlobalString('MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
1300 $tmptxt = '(';
1301 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
1302 $outputlangs = $langs;
1303 $newlang = '';
1304 if (GETPOST('lang_id', 'alpha')) {
1305 $newlang = GETPOST('lang_id', 'alpha');
1306 }
1307 if (empty($newlang)) {
1308 $newlang = $object->thirdparty->default_lang;
1309 }
1310 if (!empty($newlang)) {
1311 $outputlangs = new Translate("", $conf);
1312 $outputlangs->setDefaultLang($newlang);
1313 $outputlangs->load('products');
1314 }
1315 if (!empty($prod->customcode)) {
1316 $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomsCode").': '.$prod->customcode;
1317 }
1318 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1319 $tmptxt .= ' - ';
1320 }
1321 if (!empty($prod->country_code)) {
1322 $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, '', $db, $outputlangs, 0);
1323 }
1324 } else {
1325 if (!empty($prod->customcode)) {
1326 $tmptxt .= $langs->transnoentitiesnoconv("CustomsCode").': '.$prod->customcode;
1327 }
1328 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1329 $tmptxt .= ' - ';
1330 }
1331 if (!empty($prod->country_code)) {
1332 $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, '', $db, $langs, 0);
1333 }
1334 }
1335 $tmptxt .= ')';
1336 $description = dol_concatdesc($desc, $tmptxt);
1337 }
1338 $type = $prod->type;
1339 $fk_unit = $prod->fk_unit;
1340 } else {
1341 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1342 $desc = $line_desc;
1343 $type = GETPOST('type');
1344 $fk_unit = GETPOST('units', 'alpha');
1345 $description = $desc;
1346 $fk_elementdet = '';
1347 }
1348 $desc = dol_htmlcleanlastbr($desc);
1349
1350 // Insert line
1351 $result = $object->addlinefree((float) $qty, $element_type, $idprod, $fk_unit, min($rank, count($object->lines) + 1), $description, $fk_parent, $array_options);
1352
1353 if ($result > 0) {
1354 $ret = $object->fetch($object->id); // Reload to get new records
1355 $object->fetch_thirdparty();
1356 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1357 // Define output language
1358 $outputlangs = $langs;
1359 $newlang = GETPOST('lang_id', 'alpha');
1360 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1361 $newlang = $object->thirdparty->default_lang;
1362 }
1363 if (!empty($newlang)) {
1364 $outputlangs = new Translate("", $conf);
1365 $outputlangs->setDefaultLang($newlang);
1366 }
1367 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1368 }
1369 } else {
1370 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To redisplay the form being edited
1371 exit();
1372 }
1373 }
1374 } elseif ($action == 'confirm_sign' && $confirm == 'yes' && $permissiontoadd) {
1375 $result = $object->setSignedStatus($user, GETPOSTINT('signed_status'), 0, 'SHIPPING_MODIFY');
1376 if ($result >= 0) {
1377 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1378 // Define output language
1379 $outputlangs = $langs;
1380 $newlang = '';
1381 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1382 $newlang = GETPOST('lang_id', 'aZ09');
1383 }
1384 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1385 $newlang = $object->thirdparty->default_lang;
1386 }
1387 if (!empty($newlang)) {
1388 $outputlangs = new Translate("", $conf);
1389 $outputlangs->setDefaultLang($newlang);
1390 }
1391 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1392 }
1393
1394 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
1395 exit;
1396 } else {
1397 $mesg = $object->error;
1398 }
1399 } elseif ($action == 'confirm_unsign' && $confirm == 'yes' && $permissiontoadd) {
1400 $result = $object->setSignedStatus($user, Expedition::$SIGNED_STATUSES['STATUS_NO_SIGNATURE'], 0, 'SHIPPING_MODIFY');
1401 if ($result >= 0) {
1402 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1403 // Define output language
1404 $outputlangs = $langs;
1405 $newlang = '';
1406 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1407 $newlang = GETPOST('lang_id', 'aZ09');
1408 }
1409 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1410 $newlang = $object->thirdparty->default_lang;
1411 }
1412 if (!empty($newlang)) {
1413 $outputlangs = new Translate("", $conf);
1414 $outputlangs->setDefaultLang($newlang);
1415 }
1416 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1417 }
1418
1419 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
1420 exit;
1421 } else {
1422 $mesg = $object->error;
1423 }
1424 }
1425
1426 include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
1427
1428 // Actions to send emails
1429 if (empty($id)) {
1430 $id = $facid;
1431 }
1432 $triggersendname = 'SHIPPING_SENTBYMAIL';
1433 $paramname = 'id';
1434 $autocopy = 'MAIN_MAIL_AUTOCOPY_SHIPMENT_TO';
1435 $mode = 'emailfromshipment';
1436 $trackid = 'shi' . $object->id;
1437 include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
1438}
1439
1440/*
1441 * View
1442 */
1443
1444$title = $object->ref . ' - ' . $langs->trans("Card");
1445if ($action == 'create') {
1446 $title = $langs->trans("NewSending");
1447}
1448
1449$help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:M&oacute;dulo_Expediciones|DE:Modul_Lieferungen';
1450
1451llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-expedition page-card');
1452
1453if (empty($action)) {
1454 $action = 'view';
1455}
1456
1457$form = new Form($db);
1458$formfile = new FormFile($db);
1459$formproduct = new FormProduct($db);
1460if (isModEnabled('project')) {
1461 $formproject = new FormProjets($db);
1462} else {
1463 $formproject = null;
1464}
1465
1466$product_static = new Product($db);
1467$shipment_static = new Expedition($db);
1468$warehousestatic = new Entrepot($db);
1469
1470if (!$origin && $action == 'create' && !getDolGlobalString('SHIPMENT_STANDALONE')) {
1471 print load_fiche_titre($langs->trans("CreateShipment"), '', 'dolly');
1472
1473 print '<br>' .$langs->trans("ShipmentCreationIsDoneFromOrder");
1474 $action = '';
1475 $id = '';
1476 $ref = '';
1477}
1478
1479// Mode creation.
1480if ($action == 'create' && $usercancreate) {
1481 $expe = new Expedition($db);
1482
1483 print load_fiche_titre($langs->trans("NewSending"), '', 'dolly');
1484
1485 if (!$origin && getDolGlobalString('SHIPMENT_STANDALONE')) {
1486 $soc = new Societe($db);
1487 if ($socid > 0) {
1488 $res = $soc->fetch($socid);
1489 }
1490
1491 $shipping_method_id = $soc->shipping_method_id;
1492 $note_private = $object->getDefaultCreateValueFor('note_private');
1493 $note_public = $object->getDefaultCreateValueFor('note_public');
1494
1495 print '<form name="crea_expedition" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
1496 print '<input type="hidden" name="token" value="' . newToken() . '">';
1497 print '<input type="hidden" name="action" value="add">';
1498 print '<input type="hidden" name="changecompany" value="0">'; // will be set to 1 by javascript so we know post is done after a company change
1499 print '<input type="hidden" name="originid" value="' . $id . '">';
1500 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
1501
1502 print dol_get_fiche_head([]);
1503
1504 print '<table class="border centpercent">';
1505
1506 // Thirdparty
1507 print '<tr>';
1508 print '<td class="fieldrequired">' . $langs->trans('ThirdParty') . '</td>';
1509 if ($socid > 0) {
1510 print '<td>';
1511 print $soc->getNomUrl(1);
1512 print '<input type="hidden" name="socid" value="' . $soc->id . '">';
1513 print '</td>';
1514 } else {
1515 print '<td class="valuefieldcreate">';
1516 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, array(), 0, 'minwidth175 maxwidth500 widthcentpercentminusxx');
1517 // reload page to retrieve customer information
1518 if (!getDolGlobalString('RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED')) {
1519 print '<script>
1520 $(document).ready(function() {
1521 $("#socid").change(function() {
1522 console.log("We have changed the company - Reload page");
1523 var socid = $(this).val();
1524 // reload page
1525 $("input[name=action]").val("create");
1526 $("input[name=changecompany]").val("1");
1527 $("form[name=crea_expedition]").submit();
1528 });
1529 });
1530 </script>';
1531 }
1532 print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1533 print '</td>';
1534 }
1535 print '</tr>'."\n";
1536
1537 // Project
1538 if (isModEnabled('project') && is_object($formproject)) {
1539 $projectid = GETPOSTINT('projectid');
1540 if (empty($projectid) && !empty($object->fk_project)) {
1541 $projectid = (int) $object->fk_project;
1542 }
1543
1544 $langs->load("projects");
1545 print '<tr>';
1546 print '<td>' . $langs->trans("Project") . '</td><td colspan="2">';
1547 print img_picto('', 'project', 'class="pictofixedwidth"');
1548 print $formproject->select_projects($soc->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, 'widthcentpercentminusxx');
1549 print ' <a class="paddingleft" href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $soc->id . '&action=create&status=1&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create&socid=' . $soc->id) . '"><span class="fa fa-plus-circle valignmiddle"></span></a>';
1550 print '</td>';
1551 print '</tr>';
1552 }
1553
1554 // Date sending
1555 print '<tr><td>'.$langs->trans("DateShipping").'</td>';
1556 print '<td colspan="3">';
1557 print img_picto('', 'action', 'class="pictofixedwidth"');
1558 $date_shipping = ($date_shipping ? $date_shipping : $object->date_shipping); // $date_shipping comes from GETPOST
1559 print $form->selectDate($date_shipping ? $date_shipping : -1, 'date_shipping', 1, 1, 1);
1560 print "</td>\n";
1561 print '</tr>';
1562
1563 // Date delivery planned
1564 print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
1565 print '<td colspan="3">';
1566 print img_picto('', 'action', 'class="pictofixedwidth"');
1567 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date); // $date_delivery comes from GETPOST
1568 print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
1569 print "</td>\n";
1570 print '</tr>';
1571
1572 // Weight
1573 print '<tr><td>';
1574 print $langs->trans("Weight");
1575 print '</td><td colspan="3">';
1576 print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"');
1577 print '<input name="weight" size="4" value="' . GETPOST('weight') . '"> '; // Do not use GETPOSTINT here, we must accept '' also.
1578 $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units'), 0, 2);
1579 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
1580 print $form->textwithpicto($text, $htmltext);
1581 print '</td></tr>';
1582
1583 // Dim width x height x depth
1584 print '<tr><td>';
1585 print $langs->trans("Width") . ' x ' . $langs->trans("Height") . ' x ' . $langs->trans("Depth");
1586 print ' </td><td colspan="3">';
1587 print img_picto('', 'fa-ruler', 'class="pictofixedwidth"');
1588 print '<input name="sizeW" size="4" value="' . GETPOST('sizeW') . '">';
1589 print ' x <input name="sizeH" size="4" value="' . GETPOST('sizeH') . '">';
1590 print ' x <input name="sizeS" size="4" value="' . GETPOST('sizeS') . '">';
1591 print ' ';
1592 $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units'), 0, 2);
1593 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
1594 print $form->textwithpicto($text, $htmltext);
1595 print '</td></tr>';
1596
1597 // Delivery method
1598 print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";
1599 print '<td colspan="3">';
1600 $expe->fetch_delivery_methods();
1601 print img_picto('', 'dolly', 'class="pictofixedwidth"');
1602 print $form->selectarray("shipping_method_id", $expe->meths, GETPOSTINT('shipping_method_id'), 1, 0, 0, "", 1, 0, 0, '', 'widthcentpercentminusxx');
1603 if ($user->admin) {
1604 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1605 }
1606 print "</td></tr>\n";
1607
1608 // Tracking number
1609 print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
1610 print '<td colspan="3">';
1611 print img_picto('', 'barcode', 'class="pictofixedwidth"');
1612 print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';
1613 print "</td></tr>\n";
1614
1615 // Other attributes
1616 $parameters = array('objectsrc' => isset($objectsrc) ? $objectsrc : '', 'colspan' => ' colspan="3"', 'cols' => '3', 'socid' => $socid);
1617 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $expe, $action); // Note that $action and $object may have been modified by hook
1618 print $hookmanager->resPrint;
1619
1620 if (empty($reshook)) {
1621 // copy from order
1622 if ($object->fetch_optionals() > 0) {
1623 $expe->array_options = array_merge($expe->array_options, $object->array_options);
1624 }
1625 print $expe->showOptionals($extrafields, 'edit', $parameters);
1626 }
1627
1628 // Incoterms
1629 if (isModEnabled('incoterm')) {
1630 print '<tr>';
1631 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->label_incoterms, 1).'</label></td>';
1632 print '<td colspan="3" class="maxwidthonsmartphone">';
1633 print img_picto('', 'incoterm', 'class="pictofixedwidth"');
1634 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1635 print '</td></tr>';
1636 }
1637
1638 // Document model
1639 include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
1641 if (is_array($list) && count($list) > 1) {
1642 print "<tr><td>".$langs->trans("DefaultModel")."</td>";
1643 print '<td colspan="3">';
1644 print img_picto('', 'pdf', 'class="pictofixedwidth"');
1645 print $form->selectarray('model', $list, getDolGlobalString('EXPEDITION_ADDON_PDF'), 0, 0, 0, '', 0, 0, 0, '', 'widthcentpercentminusx');
1646 print "</td></tr>\n";
1647 }
1648
1649 // Note Public
1650 $htmltext = '';
1651 print '<tr>';
1652 print '<td class="tdtop">';
1653 print $form->textwithpicto($langs->trans('NotePublic'), $htmltext);
1654 print '</td>';
1655 print '<td valign="top" colspan="2">';
1656 $doleditor = new DolEditor('note_public', (string) $note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1657 print $doleditor->Create(1);
1658
1659 // Note Private
1660 if (!$user->socid) {
1661 print '<tr>';
1662 print '<td class="tdtop">';
1663 print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext);
1664 print '</td>';
1665 print '<td valign="top" colspan="2">';
1666 $doleditor = new DolEditor('note_private', (string) $note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1667 print $doleditor->Create(1);
1668 print "</td></tr>";
1669 }
1670
1671 print "</table>\n";
1672
1673 print dol_get_fiche_end();
1674
1675 print $form->buttonsSaveCancel("CreateDraft");
1676
1677 print "</form>\n";
1678 } elseif ($origin) {
1679 $classname = ucfirst($origin);
1680
1681 $object = new $classname($db);
1682 /* @var Commande|Facture $object */
1683 '@phan-var-force Commande|Facture $object';
1684
1685
1686 if ($object->fetch($origin_id)) { // This include the fetch_lines
1687 $soc = new Societe($db);
1688 $soc->fetch($object->socid);
1689
1690 $author = new User($db);
1691 $author->fetch($object->user_author_id);
1692
1693 if (isModEnabled('stock')) {
1694 $entrepot = new Entrepot($db);
1695 }
1696
1697 print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
1698 print '<input type="hidden" name="token" value="' . newToken() . '">';
1699 print '<input type="hidden" name="action" value="add">';
1700 print '<input type="hidden" name="origin" value="' . $origin . '">';
1701 print '<input type="hidden" name="origin_id" value="' . $object->id . '">';
1702 if (GETPOSTINT('entrepot_id')) {
1703 print '<input type="hidden" name="entrepot_id" value="' . GETPOSTINT('entrepot_id') . '">';
1704 }
1705
1706 print dol_get_fiche_head([]);
1707
1708 print '<table class="border centpercent">';
1709
1710 // Ref
1711 print '<tr><td class="titlefieldcreate fieldrequired">';
1712 if ($origin == 'commande' && isModEnabled('order')) {
1713 print $langs->trans("RefOrder");
1714 }
1715 if ($origin == 'propal' && isModEnabled("propal")) {
1716 print $langs->trans("RefProposal");
1717 }
1718 print '</td><td colspan="3">';
1719 print $object->getNomUrl(1);
1720 print '</td>';
1721 print "</tr>\n";
1722
1723 // Ref client
1724 print '<tr><td>';
1725 if ($origin == 'commande') {
1726 print $langs->trans('RefCustomerOrder');
1727 } elseif ($origin == 'propal') {
1728 print $langs->trans('RefCustomerOrder');
1729 } else {
1730 print $langs->trans('RefCustomer');
1731 }
1732 print '</td><td colspan="3">';
1733 print '<input type="text" name="ref_customer" value="' . $object->ref_client . '" />';
1734 print '</td>';
1735 print '</tr>';
1736
1737 // Thirdparty
1738 print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans('Company') . '</td>';
1739 print '<td colspan="3">' . $soc->getNomUrl(1) . '</td>';
1740 print '<input type="hidden" name="socid" value="' . $soc->id . '">';
1741 print '</tr>';
1742
1743 // Project
1744 if (isModEnabled('project') && is_object($formproject)) {
1745 $projectid = GETPOSTINT('projectid');
1746 if (empty($projectid) && !empty($object->fk_project)) {
1747 $projectid = (int) $object->fk_project;
1748 }
1749 if ($origin == 'project') {
1750 $projectid = ($object->id ? $object->id : 0);
1751 }
1752 $langs->load("projects");
1753 print '<tr>';
1754 print '<td>' . $langs->trans("Project") . '</td><td colspan="2">';
1755 print img_picto('', 'project', 'class="pictofixedwidth"');
1756 print $formproject->select_projects($soc->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, 'widthcentpercentminusxx');
1757 print ' <a class="paddingleft" href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $soc->id . '&action=create&status=1&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create&socid=' . $soc->id) . '"><span class="fa fa-plus-circle valignmiddle"></span></a>';
1758 print '</td>';
1759 print '</tr>';
1760 }
1761
1762 // Date delivery planned
1763 print '<tr><td>' . $langs->trans("DateDeliveryPlanned") . '</td>';
1764 print '<td colspan="3">';
1765 print img_picto('', 'action', 'class="pictofixedwidth"');
1766 $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date); // $date_delivery comes from GETPOST
1767 print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
1768 print "</td>\n";
1769 print '</tr>';
1770
1771 // Date shipment (sending)
1772 print '<tr><td>' . $langs->trans("DateShipping") . '</td>';
1773 print '<td colspan="3">';
1774 print img_picto('', 'action', 'class="pictofixedwidth"');
1775 //$date_shipping = ($date_shipping ? $date_shipping : $object->date_shipping); // $date_shipping comes from GETPOST
1776 print $form->selectDate($date_shipping ? $date_shipping : -1, 'date_shipping', 1, 1, 1);
1777 print "</td>\n";
1778 print '</tr>';
1779
1780 // Note Public
1781 print '<tr><td>' . $langs->trans("NotePublic") . '</td>';
1782 print '<td colspan="3">';
1783 $doleditor = new DolEditor('note_public', $object->note_public, '', 60, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1784 print $doleditor->Create(1);
1785 print "</td></tr>";
1786
1787 // Note Private
1788 if ($object->note_private && !$user->socid) {
1789 print '<tr><td>' . $langs->trans("NotePrivate") . '</td>';
1790 print '<td colspan="3">';
1791 $doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1792 print $doleditor->Create(1);
1793 print "</td></tr>";
1794 }
1795
1796 // Weight
1797 print '<tr><td>';
1798 print $langs->trans("Weight");
1799 print '</td><td colspan="3">';
1800 print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"');
1801
1802 print '<input name="weight" size="4" value="' . dol_escape_htmltag(GETPOST('weight')) . '"> '; // Do not use GETPOSTINT here, we must accept '' also.
1803 $text = $formproduct->selectMeasuringUnits("weight_units", "weight", (string) GETPOST('weight_units'), 0, 2);
1804 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
1805 print $form->textwithpicto($text, $htmltext);
1806 print '</td></tr>';
1807
1808 // Dim Width x Height x Depth
1809 print '<tr><td>';
1810 print $langs->trans("Width") . ' x ' . $langs->trans("Height") . ' x ' . $langs->trans("Depth");
1811 print ' </td><td colspan="3">';
1812 print img_picto('', 'fa-ruler', 'class="pictofixedwidth"');
1813 print '<input name="sizeW" size="4" value="' . GETPOST('sizeW') . '">';
1814 print ' x <input name="sizeH" size="4" value="' . GETPOST('sizeH') . '">';
1815 print ' x <input name="sizeS" size="4" value="' . GETPOST('sizeS') . '">';
1816 print ' ';
1817 $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units'), 0, 2);
1818 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
1819 print $form->textwithpicto($text, $htmltext);
1820 print '</td></tr>';
1821
1822 // Delivery method
1823 print "<tr><td>" . $langs->trans("DeliveryMethod") . "</td>";
1824 print '<td colspan="3">';
1825 $expe->fetch_delivery_methods();
1826 print img_picto('', 'dolly', 'class="pictofixedwidth"');
1827 print $form->selectarray("shipping_method_id", $expe->meths, GETPOSTINT('shipping_method_id'), 1, 0, 0, "", 1, 0, 0, '', 'widthcentpercentminusxx');
1828 if ($user->admin) {
1829 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1830 }
1831 print "</td></tr>\n";
1832
1833 // Tracking number
1834 print "<tr><td>" . $langs->trans("TrackingNumber") . "</td>";
1835 print '<td colspan="3">';
1836 print img_picto('', 'barcode', 'class="pictofixedwidth"');
1837 print '<input name="tracking_number" size="20" value="' . GETPOST('tracking_number', 'alpha') . '">';
1838 print "</td></tr>\n";
1839
1840 // Incoterms
1841 if (isModEnabled('incoterm')) {
1842 print '<tr>';
1843 print '<td><label for="incoterm_id">' . $form->textwithpicto($langs->trans("IncotermLabel"), $object->label_incoterms, 1) . '</label></td>';
1844 print '<td colspan="3" class="maxwidthonsmartphone">';
1845 print img_picto('', 'incoterm', 'class="pictofixedwidth"');
1846 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1847 print '</td></tr>';
1848 }
1849
1850 // Document model
1851 include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php';
1853 if (is_array($list) && count($list) > 1) {
1854 print "<tr><td>" . $langs->trans("DefaultModel") . "</td>";
1855 print '<td colspan="3">';
1856 print img_picto('', 'pdf', 'class="pictofixedwidth"');
1857 print $form->selectarray('model', $list, getDolGlobalString('EXPEDITION_ADDON_PDF'), 0, 0, 0, '', 0, 0, 0, '', 'widthcentpercentminusx');
1858 print "</td></tr>\n";
1859 }
1860
1861 // Other attributes. Fields from hook formObjectOptions and Extrafields.
1862 // $objectsrc is Commande|Facture
1863 $objectsav = $object; // Because Expedition is $expe and not $object that is wrongly a duplicate of $objectsrc.
1864 $object = $expe;
1865 // Propagate extrafieldsvalue from source object to shipment object
1866 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && !empty($extrafields->attributes[$object->table_element]['label'])) {
1867 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
1868 if (array_key_exists('options_'.$key, $objectsav->array_options)) { // We take value from order only if extrafield has the same name/key.
1869 $object->array_options['options_'.$key] = $objectsav->array_options['options_'.$key];
1870 }
1871 }
1872 }
1873 $parameters = array(
1874 'objectsrc' => isset($objectsrc) ? $objectsrc : '',
1875 'cols' => '3',
1876 'socid' => $socid
1877 );
1878 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1879 $object = $objectsav;
1880
1881 print "</table>";
1882
1883 print dol_get_fiche_end();
1884
1885
1886 // Shipment lines
1887
1888 $numAsked = count($object->lines);
1889
1890 print '<script type="text/javascript">' . "\n";
1891 print 'jQuery(document).ready(function() {' . "\n";
1892 print 'jQuery("#autofill").click(function() {';
1893 $i = 0;
1894 while ($i < $numAsked) {
1895 print 'jQuery("#qtyl' . $i . '").val(jQuery("#qtyasked' . $i . '").val() - jQuery("#qtydelivered' . $i . '").val());' . "\n";
1896 if (isModEnabled('productbatch')) {
1897 print 'jQuery("#qtyl' . $i . '_' . $i . '").val(jQuery("#qtyasked' . $i . '").val() - jQuery("#qtydelivered' . $i . '").val());' . "\n";
1898 }
1899 $i++;
1900 }
1901 print 'return false; });' . "\n";
1902 print 'jQuery("#autoreset").click(function() { console.log("Reset values to 0"); jQuery(".qtyl").val(0);' . "\n";
1903 print 'return false; });' . "\n";
1904 print '});' . "\n";
1905 print '</script>' . "\n";
1906
1907 print '<br>';
1908
1909 print '<div class="div-table-responsive-no-min">';
1910 print '<table class="noborder centpercent">';
1911
1912 // Load shipments already done for same order
1913 $object->loadExpeditions();
1914
1915 $alreadyQtyBatchSetted = $alreadyQtySetted = array();
1916
1917 $title_lines_to_disable = array();
1918
1919 if ($numAsked) {
1920 if (isModEnabled('subtotals')) {
1921 if (!(getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES') || getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
1922 $title_lines_to_disable = $object->getDisabledShippmentSubtotalLines();
1923 }
1924 $selectedLines = GETPOST('subtotal_toselect', 'array:int');
1925 foreach ($object->lines as $line) {
1926 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
1927 $show_check_add_buttons = true;
1928 break;
1929 }
1930 }
1931 }
1932 print '<tr class="liste_titre">';
1933 print '<td>';
1934 if (isset($show_check_add_buttons)) {
1935 print $form->showCheckAddButtons('checkforselect');
1936 }
1937 print $langs->trans("Description");
1938 print '</td>';
1939 print '<td class="center">' . $langs->trans("QtyOrdered") . '</td>';
1940 print '<td class="center">' . $langs->trans("QtyShipped") . '</td>';
1941 print '<td class="center">' . $langs->trans("QtyToShip");
1942 if (!isModEnabled('productbatch')) {
1943 print '<br><a href="#" id="autofill" class="opacitymedium link cursor cursorpointer">' . img_picto($langs->trans("Autofill"), 'autofill', 'class="paddingrightonly"') . '</a>';
1944 print ' / ';
1945 } else {
1946 print '<br>';
1947 }
1948 print '<span id="autoreset" class="opacitymedium link cursor cursorpointer">' . img_picto($langs->trans("Reset"), 'eraser') . '</span>';
1949 print '</td>';
1950 if (isModEnabled('stock')) {
1951 if (!isModEnabled('productbatch')) {
1952 print '<td class="left">' . $langs->trans("Warehouse") . ' (' . $langs->trans("Stock") . ')</td>';
1953 } else {
1954 print '<td class="left">' . $langs->trans("Warehouse") . ' / ' . $langs->trans("Batch") . ' (' . $langs->trans("Stock") . ')</td>';
1955 }
1956 }
1957 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
1958 print '<td class="left">' . $langs->trans('StockEntryDate') . '</td>';
1959 }
1960 print "</tr>\n";
1961 }
1962
1963 $warehouse_id = GETPOSTINT('entrepot_id');
1964 $warehousePicking = array();
1965 // get all warehouse children for picking
1966 if ($warehouse_id > 0) {
1967 $warehousePicking[] = $warehouse_id;
1968 $warehouseObj = new Entrepot($db);
1969 $warehouseObj->get_children_warehouses($warehouse_id, $warehousePicking);
1970 }
1971
1972 $indiceAsked = 0;
1973 while ($indiceAsked < $numAsked) {
1974 $product = new Product($db);
1975
1976 $line = $object->lines[$indiceAsked];
1977
1978 $parameters = array('i' => $indiceAsked, 'line' => $line, 'num' => $numAsked);
1979 $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);
1980 if ($reshook < 0) {
1981 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1982 }
1983
1984 if (empty($reshook) && $line->special_code != SUBTOTALS_SPECIAL_CODE) {
1985 // Show product and description
1986 $type = $line->product_type ? $line->product_type : $line->fk_product_type;
1987 // Try to enhance type detection using date_start and date_end for free lines where type was not saved.
1988 if (!empty($line->date_start)) {
1989 $type = 1;
1990 }
1991 if (!empty($line->date_end)) {
1992 $type = 1;
1993 }
1994
1995 print '<!-- line for order line ' . $line->id . ' -->' . "\n";
1996 print '<tr class="oddeven" id="row-' . $line->id . '">' . "\n";
1997
1998 $qtyProdCom = $line->qty;
1999 $productChildrenNb = 0;
2000 // Product label
2001 if ($line->fk_product > 0) { // If predefined product
2002 $res = $product->fetch($line->fk_product);
2003 if ($res < 0) {
2004 dol_print_error($db, $product->error, $product->errors);
2005 }
2006 if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) {
2007 $productChildrenNb = $product->hasFatherOrChild(1);
2008 }
2009 if ($productChildrenNb > 0) {
2010 $product->loadStockForVirtualProduct('warehouseopen', $qtyProdCom);
2011 } else {
2012 $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
2013 }
2014 //var_dump($product->stock_warehouse[1]);
2015
2016 print '<td>';
2017 print '<a name="' . $line->id . '"></a>'; // Anchor to retor to the line
2018
2019 // Show product and description
2020 $product_static->type = $line->fk_product_type;
2021 $product_static->id = $line->fk_product;
2022 $product_static->ref = $line->ref;
2023 $product_static->status = $line->product_tosell;
2024 $product_static->status_buy = $line->product_tobuy;
2025 $product_static->status_batch = $line->product_tobatch;
2026
2027 $showdescinproductdesc = getDolGlobalString('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE');
2028
2029 $text = $product_static->getNomUrl(1);
2030 $text .= ' - ' . (!empty($line->label) ? $line->label : $line->product_label);
2031 $description = ($showdescinproductdesc ? '' : dol_htmlentitiesbr($line->desc));
2032 $description .= empty($product->stockable_product) ? $langs->trans('StockDisabled') : $langs->trans('StockEnabled');
2033 print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
2034
2035 // Show range
2036 print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
2037
2038 // Add description in form
2039 if ($showdescinproductdesc) {
2040 print ($line->desc && $line->desc != $line->product_label) ? '<br>' . dol_htmlentitiesbr($line->desc) : '';
2041 }
2042
2043 $expLine = new ExpeditionLigne($db);
2044 $srcLine = new OrderLine($db);
2045 $srcLine->id = $line->id;
2046 $srcLine->fetch_optionals(); // Fetch source line extrafields so shipment line creation matches order UI.
2047 $expLine->array_options = array_merge($expLine->array_options, $srcLine->array_options);
2048 $lineExtrafieldsHtml = $expLine->showOptionals($extrafields, 'edit', array(), (string) $indiceAsked, '', '1', 'line');
2049 if (!empty($lineExtrafieldsHtml)) {
2050 print '<div style="padding-top: 10px" id="extrafield_lines_area_create_' . $indiceAsked . '" name="extrafield_lines_area_create_' . $indiceAsked . '">';
2051 print $lineExtrafieldsHtml;
2052 print '</div>';
2053 }
2054
2055 print '</td>';
2056 } else {
2057 print "<td>";
2058 if ($type == 1) {
2059 $text = img_object($langs->trans('Service'), 'service');
2060 } else {
2061 $text = img_object($langs->trans('Product'), 'product');
2062 }
2063
2064 if (!empty($line->label)) {
2065 $text .= ' <strong>' . $line->label . '</strong>';
2066 print $form->textwithtooltip($text, $line->desc, 3, 0, '', (string) $i);
2067 } else {
2068 print $text . ' ' . nl2br($line->desc);
2069 }
2070
2071 // Show range
2072 print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
2073
2074 $expLine = new ExpeditionLigne($db);
2075 $srcLine = new OrderLine($db);
2076 $srcLine->id = $line->id;
2077 $srcLine->fetch_optionals(); // Fetch source line extrafields so shipment line creation matches order UI.
2078 $expLine->array_options = array_merge($expLine->array_options, $srcLine->array_options);
2079 $lineExtrafieldsHtml = $expLine->showOptionals($extrafields, 'edit', array(), (string) $indiceAsked, '', '1', 'line');
2080 if (!empty($lineExtrafieldsHtml)) {
2081 print '<div style="padding-top: 10px" id="extrafield_lines_area_create_' . $indiceAsked . '" name="extrafield_lines_area_create_' . $indiceAsked . '">';
2082 print $lineExtrafieldsHtml;
2083 print '</div>';
2084 }
2085 print "</td>\n";
2086 }
2087
2088 // unit of order
2089 $unit_order = '';
2090 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
2091 $unit_order = measuringUnitString($line->fk_unit);
2092 }
2093
2094 // Qty
2095 print '<td class="center">' . $line->qty;
2096 print '<input name="qtyasked' . $indiceAsked . '" id="qtyasked' . $indiceAsked . '" type="hidden" value="' . $line->qty . '">';
2097 if ($line->qty) {
2098 print ' ' . $unit_order . '</td>';
2099 }
2100
2101 // Qty already shipped
2102 print '<td class="center">';
2103 $quantityDelivered = isset($object->expeditions[$line->id]) ? $object->expeditions[$line->id] : '';
2104 print $quantityDelivered;
2105 print '<input name="qtydelivered' . $indiceAsked . '" id="qtydelivered' . $indiceAsked . '" type="hidden" value="' . $quantityDelivered . '">';
2106 if ($quantityDelivered) {
2107 print ' ' . $unit_order . '</td>';
2108 }
2109
2110 // Qty to ship
2111 $quantityAsked = $line->qty;
2112 if ($line->product_type == Product::TYPE_SERVICE && !getDolGlobalString('STOCK_SUPPORTS_SERVICES') && !getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {
2113 $quantityToBeDelivered = 0;
2114 } else {
2115 if (is_numeric($quantityDelivered)) {
2116 $quantityToBeDelivered = $quantityAsked - $quantityDelivered;
2117 } else {
2118 $quantityToBeDelivered = $quantityAsked;
2119 }
2120 }
2121
2122 $warehouseObject = null;
2123 if (count($warehousePicking) == 1 || !($line->fk_product > 0) || !isModEnabled('stock')) { // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
2124 print '<!-- Case warehouse already known or product not a predefined product -->';
2125 //ship from preselected location
2126 $stock = + (isset($product->stock_warehouse[$warehouse_id]->real) ? $product->stock_warehouse[$warehouse_id]->real : 0); // Convert to number
2127 if (($line->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) || $product->stockable_product == Product::DISABLED_STOCK) {
2128 $deliverableQty = $quantityToBeDelivered;
2129 } else {
2130 $deliverableQty = min($quantityToBeDelivered, $stock);
2131 }
2132 if ($deliverableQty < 0) {
2133 $deliverableQty = 0;
2134 }
2135 if (!isModEnabled('productbatch') || !$product->hasbatch()) {
2136 // Quantity to send
2137 print '<td class="center">';
2138 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || ($line->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES'))) {
2139 if (GETPOSTISSET('qtyl'.$indiceAsked) && GETPOST('qtyl'.$indiceAsked) !== '') {
2140 $deliverableQty = GETPOSTFLOAT('qtyl'.$indiceAsked, 'MS');
2141 }
2142 print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line->id . '">';
2143 $qtylValue = $deliverableQty;
2144 if (getDolGlobalBool('SHIPMENT_DONT_PREFILL_QTY', false)) {
2145 $qtylValue = '';
2146 } elseif (is_numeric($qtylValue)) {
2147 // Render as locale number so GETPOSTFLOAT() on submit reads it back via price2num option=2 without confusing '.' for a thousand separator in es_ES.
2148 $qtylValue = price($qtylValue);
2149 }
2150 print '<input name="qtyl' . $indiceAsked . '" id="qtyl' . $indiceAsked . '" class="qtyl right" type="text" size="4" value="' . $qtylValue . '">';
2151 } else {
2152 if (getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {
2153 print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line->id . '">';
2154 print '<input name="qtyl' . $indiceAsked . '" id="qtyl' . $indiceAsked . '" type="hidden" value="0">';
2155 }
2156
2157 print $langs->trans("NA");
2158 }
2159 print '</td>';
2160
2161 // Stock
2162 if (isModEnabled('stock')) {
2163 print '<td class="left">';
2164 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { // Type of product need stock change ?
2165 // Show warehouse combo list
2166 $ent = "entl" . $indiceAsked;
2167 $idl = "idl" . $indiceAsked;
2168 $tmpentrepot_id = is_numeric(GETPOST($ent)) ? GETPOSTINT($ent) : $warehouse_id;
2169 if ($line->fk_product > 0) {
2170 print '<!-- Show warehouse selection -->';
2171
2172 $stockMin = false;
2173 if (getDolGlobalInt('STOCK_DISALLOW_NEGATIVE_TRANSFER')) {
2174 $stockMin = 0;
2175 }
2176 if ($productChildrenNb > 0) {
2177 print $formproduct->selectWarehouses($tmpentrepot_id, 'entl' . $indiceAsked, '', 1, 0, 0, '', 0, 0, array(), 'minwidth200', array(), 1, $stockMin, 'stock DESC, e.ref');
2178 } else {
2179 if ($product->stockable_product == Product::ENABLED_STOCK) {
2180 print $formproduct->selectWarehouses($tmpentrepot_id, 'entl' . $indiceAsked, '', 1, 0, $line->fk_product, '', 1, 0, array(), 'minwidth200', array(), 1, $stockMin, 'stock DESC, e.ref');
2181 } else {
2182 print img_warning() . ' ' . $langs->trans('StockDisabled');
2183 }
2184 }
2185
2186 if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id) {
2187 //print $stock.' '.$quantityToBeDelivered;
2188 if ($stock < $quantityToBeDelivered) {
2189 print ' ' . img_warning($langs->trans("StockTooLow")); // Stock too low for this $warehouse_id but you can change warehouse
2190 }
2191 }
2192 }
2193 } else {
2194 print '<span class="opacitymedium">(' . $langs->trans("Service") . ')</span><input name="entl' . $indiceAsked . '" id="entl' . $indiceAsked . '" type="hidden" value="0">';
2195 }
2196 print '</td>';
2197 }
2198 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2199 print '<td></td>';
2200 } //StockEntrydate
2201 print "</tr>\n";
2202
2203 // Show subproducts of product
2204 if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && $line->fk_product > 0) {
2205 $product->get_sousproduits_arbo();
2206 $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
2207 if (count($prods_arbo) > 0) {
2208 foreach ($prods_arbo as $key => $value) {
2209 //print $value[0];
2210 $img = '';
2211 if ($value['stock'] < $value['stock_alert']) {
2212 $img = img_warning($langs->trans("StockTooLow"));
2213 }
2214 print "<tr class=\"oddeven\"><td>&nbsp; &nbsp; &nbsp; ->
2215 <a href=\"" . DOL_URL_ROOT . "/product/card.php?id=" . $value['id'] . "\">" . $value['fullpath'] . "
2216 </a> (" . $value['nb'] . ")</td><td class=\"center\"> " . $value['nb_total'] . "</td><td>&nbsp;</td><td>&nbsp;</td>
2217 <td class=\"center\">" . $value['stock'] . " " . $img . "</td>";
2218 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2219 print '<td></td>';
2220 } //StockEntrydate
2221 print "</tr>";
2222 }
2223 }
2224 }
2225 } else {
2226 // Product need lot
2227 print '<td></td><td></td>';
2228 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2229 print '<td></td>';
2230 } //StockEntrydate
2231 print '</tr>'; // end line and start a new one for lot/serial
2232 print '<!-- Case product need lot -->';
2233
2234 $staticwarehouse = new Entrepot($db);
2235 if ($warehouse_id > 0) {
2236 $staticwarehouse->fetch($warehouse_id);
2237 }
2238
2239 $subj = 0;
2240 // Define nb of lines suggested for this order line
2241 $nbofsuggested = 0;
2242 if (is_object($product->stock_warehouse[$warehouse_id]) && !empty($product->stock_warehouse[$warehouse_id]->detail_batch)) {
2243 foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) {
2244 $nbofsuggested++;
2245 }
2246 }
2247 print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
2248 if (is_object($product->stock_warehouse[$warehouse_id]) && !empty($product->stock_warehouse[$warehouse_id]->detail_batch)) {
2249 foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) { // $dbatch is instance of Productbatch
2250 //var_dump($dbatch);
2251 $batchStock = +$dbatch->qty; // To get a numeric
2252 $deliverableQty = min($quantityToBeDelivered, $batchStock);
2253
2254 // Now we will check if we have to reduce the deliverableQty by taking into account the qty already suggested in previous line
2255 if (isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {
2256 $deliverableQty = min($quantityToBeDelivered, $batchStock - $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)]);
2257 } else {
2258 if (!isset($alreadyQtyBatchSetted[$line->fk_product])) {
2259 $alreadyQtyBatchSetted[$line->fk_product] = array();
2260 }
2261
2262 if (!isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch])) {
2263 $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch] = array();
2264 }
2265
2266 $deliverableQty = min($quantityToBeDelivered, $batchStock);
2267 }
2268
2269 if ($deliverableQty < 0) {
2270 $deliverableQty = 0;
2271 }
2272
2273 $inputName = 'qtyl' . $indiceAsked . '_' . $subj;
2274 if (GETPOSTISSET($inputName)) {
2275 $deliverableQty = GETPOST($inputName, 'int');
2276 }
2277
2278 $tooltipClass = $tooltipTitle = '';
2279 if (!empty($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {
2280 $tooltipClass = ' classfortooltip';
2281 $tooltipTitle = $langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines') . ' : ' . $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];
2282 } else {
2283 $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)] = 0;
2284 }
2285 $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)] = $deliverableQty + $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];
2286
2287 print '<!-- subj=' . $subj . '/' . $nbofsuggested . ' --><tr ' . ((($subj + 1) == $nbofsuggested) ? 'oddeven' : '') . '>';
2288 print '<td colspan="3" ></td><td class="center">';
2289 $qtylValue = $deliverableQty;
2290 if (getDolGlobalBool('SHIPMENT_DONT_PREFILL_QTY', false)) {
2291 $qtylValue = '';
2292 } elseif (is_numeric($qtylValue)) {
2293 $qtylValue = price($qtylValue);
2294 }
2295 print '<input class="qtyl ' . $tooltipClass . ' right" title="' . $tooltipTitle . '" name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="' . $qtylValue . '">';
2296 print '</td>';
2297
2298 print '<!-- Show details of lot -->';
2299 print '<td class="left">';
2300
2301 print $staticwarehouse->getNomUrl(0) . ' / ';
2302
2303 print '<input name="batchl' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $dbatch->id . '">';
2304
2305 $detail = '';
2306 $detail .= $langs->trans("Batch") . ': ' . $dbatch->batch;
2307 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && !empty($dbatch->sellby)) {
2308 $detail .= ' - ' . $langs->trans("SellByDate") . ': ' . dol_print_date($dbatch->sellby, "day");
2309 }
2310 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && !empty($dbatch->eatby)) {
2311 $detail .= ' - ' . $langs->trans("EatByDate") . ': ' . dol_print_date($dbatch->eatby, "day");
2312 }
2313 $detail .= ' - ' . $langs->trans("Qty") . ': ' . $dbatch->qty;
2314 $detail .= '<br>';
2315 print $detail;
2316
2317 $quantityToBeDelivered -= $deliverableQty;
2318 if ($quantityToBeDelivered < 0) {
2319 $quantityToBeDelivered = 0;
2320 }
2321 $subj++;
2322 print '</td>';
2323 if (getDolGlobalInt('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2324 print '<td>' . dol_print_date($dbatch->context['stock_entry_date'], 'day') . '</td>'; //StockEntrydate
2325 }
2326 print '</tr>';
2327 }
2328 } else {
2329 print '<!-- Case there is no details of lot at all -->';
2330 print '<tr class="oddeven"><td colspan="3"></td><td class="center">';
2331 print '<input class="qtyl right" name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '_' . $subj . '" type="text" size="4" value="0" disabled="disabled"> ';
2332 print '</td>';
2333
2334 print '<td class="left">';
2335 print img_warning() . ' ' . $langs->trans("NoProductToShipFoundIntoStock", $staticwarehouse->label);
2336 print '</td>';
2337 if (getDolGlobalInt('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2338 print '<td></td>';
2339 } //StockEntrydate
2340 print '</tr>';
2341 }
2342 }
2343 } else {
2344 // ship from multiple locations
2345 if (!isModEnabled('productbatch') || !$product->hasbatch()) {
2346 print '<!-- Case warehouse not already known and product does not need lot -->';
2347 print '<td></td><td></td>';
2348 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2349 print '<td></td>';
2350 } //StockEntrydate
2351 print '</tr>' . "\n"; // end line and start a new one for each warehouse
2352
2353 print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line->id . '">';
2354 $subj = 0;
2355 // Define nb of lines suggested for this order line
2356 $nbofsuggested = 0;
2357
2358 foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {
2359 if ($stock_warehouse->real > 0 || !getDolGlobalInt('STOCK_DISALLOW_NEGATIVE_TRANSFER')) {
2360 $nbofsuggested++;
2361 }
2362 }
2363 $tmpwarehouseObject = new Entrepot($db);
2364 foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) { // $stock_warehouse is product_stock
2365 $var = $subj % 2;
2366 if (!empty($warehousePicking) && !in_array($warehouse_id, $warehousePicking)) {
2367 // if a warehouse was selected by user, picking is limited to this warehouse and his children
2368 continue;
2369 }
2370
2371 $tmpwarehouseObject->fetch($warehouse_id);
2372 if ($stock_warehouse->real > 0 || !getDolGlobalInt('STOCK_DISALLOW_NEGATIVE_TRANSFER')) {
2373 $stock = +$stock_warehouse->real; // Convert it to number
2374 $deliverableQty = min($quantityToBeDelivered, $stock);
2375 $deliverableQty = max(0, $deliverableQty);
2376 // Quantity to send
2377 print '<!-- subj=' . $subj . '/' . $nbofsuggested . ' --><tr ' . ((($subj + 1) == $nbofsuggested) ? 'oddeven' : '') . '>';
2378 print '<td colspan="3" ></td><td class="center"><!-- qty to ship (no lot management for product line indiceAsked=' . $indiceAsked . ') -->';
2379 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {
2380 // For a virtual product (kit), $deliverableQty is already min($quantityToBeDelivered, $stock) computed above
2381 // and the per-warehouse "stock" returned by loadStockForVirtualProduct() is $qtyWish, not a shared physical
2382 // stock. The cross-line $alreadyQtySetted cap must not be applied for kits, otherwise the 2nd and next order
2383 // lines of the same kit would be wrongly pre-filled with 0.
2384 $tooltipClass = $tooltipTitle = '';
2385 if ($productChildrenNb <= 0) {
2386 if (isset($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) {
2387 $deliverableQty = min($quantityToBeDelivered, $stock - $alreadyQtySetted[$line->fk_product][intval($warehouse_id)]);
2388 } else {
2389 if (!isset($alreadyQtySetted[$line->fk_product])) {
2390 $alreadyQtySetted[$line->fk_product] = array();
2391 }
2392
2393 $deliverableQty = min($quantityToBeDelivered, $stock);
2394 }
2395
2396 if ($deliverableQty < 0) {
2397 $deliverableQty = 0;
2398 }
2399
2400 if (!empty($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) {
2401 $tooltipClass = ' classfortooltip';
2402 $tooltipTitle = $langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines').' : '.$alreadyQtySetted[$line->fk_product][intval($warehouse_id)];
2403 } else {
2404 $alreadyQtySetted[$line->fk_product][intval($warehouse_id)] = 0;
2405 }
2406
2407 $alreadyQtySetted[$line->fk_product][intval($warehouse_id)] = $deliverableQty + $alreadyQtySetted[$line->fk_product][intval($warehouse_id)];
2408 }
2409
2410 $inputName = 'qtyl'.$indiceAsked.'_'.$subj;
2411 if (GETPOSTISSET($inputName)) {
2412 $deliverableQty = GETPOSTINT($inputName);
2413 }
2414 $qtylValue = $deliverableQty;
2415 if (getDolGlobalBool('SHIPMENT_DONT_PREFILL_QTY', false)) {
2416 $qtylValue = '';
2417 } elseif (is_numeric($qtylValue)) {
2418 $qtylValue = price($qtylValue);
2419 }
2420 print '<input class="qtyl' . $tooltipClass . ' right" title="' . $tooltipTitle . '" name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '" type="text" size="4" value="' . $qtylValue . '">';
2421 print '<input name="ent1' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $warehouse_id . '">';
2422 } else {
2423 if (getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {
2424 print '<input name="qtyl' . $indiceAsked . '_' . $subj . '" id="qtyl' . $indiceAsked . '" type="hidden" value="0">';
2425 }
2426
2427 print $langs->trans("NA");
2428 }
2429 print '</td>';
2430
2431 // Stock
2432 print '<td class="left">';
2433 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2434 if ($product->stockable_product == Product::ENABLED_STOCK || $productChildrenNb > 0) {
2435 print $tmpwarehouseObject->getNomUrl(0) . ' ';
2436 if ($productChildrenNb <= 0) {
2437 print '<!-- Show details of stock -->';
2438 print '(' . $stock . ')';
2439 }
2440 } else {
2441 print img_warning() . ' ' . $langs->trans('StockDisabled');
2442 }
2443 } else {
2444 print '<span class="opacitymedium">(' . $langs->trans("Service") . ')</span>';
2445 }
2446 print '</td>';
2447 $quantityToBeDelivered -= $deliverableQty;
2448 if ($quantityToBeDelivered < 0) {
2449 $quantityToBeDelivered = 0;
2450 }
2451 $subj++;
2452 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2453 print '<td></td>';
2454 } //StockEntrydate
2455 print "</tr>\n";
2456 }
2457 }
2458 // Show subproducts of product (not recommended)
2459 if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && $line->fk_product > 0) {
2460 $product->get_sousproduits_arbo();
2461 $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
2462 if (count($prods_arbo) > 0) {
2463 foreach ($prods_arbo as $key => $value) {
2464 //print $value[0];
2465 $img = '';
2466 if ($value['stock'] < $value['stock_alert']) {
2467 $img = img_warning($langs->trans("StockTooLow"));
2468 }
2469 print '<tr class"oddeven"><td>';
2470 print "&nbsp; &nbsp; &nbsp; ->
2471 <a href=\"" . DOL_URL_ROOT . "/product/card.php?id=" . $value['id'] . "\">" . $value['fullpath'] . "
2472 </a> (" . $value['nb'] . ")</td><td class=\"center\"> " . $value['nb_total'] . "</td><td>&nbsp;</td><td>&nbsp;</td>
2473 <td class=\"center\">" . $value['stock'] . " " . $img . "</td>";
2474 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2475 print '<td></td>';
2476 } //StockEntrydate
2477 print "</tr>";
2478 }
2479 }
2480 }
2481 } else {
2482 print '<!-- Case warehouse not already known and product need lot -->';
2483 print '<td></td><td></td>';
2484 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2485 print '<td></td>';
2486 } //StockEntrydate
2487 print '</tr>'; // end line and start a new one for lot/serial
2488
2489 $subj = 0;
2490 print '<input name="idl' . $indiceAsked . '" type="hidden" value="' . $line->id . '">';
2491
2492 $tmpwarehouseObject = new Entrepot($db);
2493 $productlotObject = new Productlot($db);
2494
2495 // Define nb of lines suggested for this order line
2496 $nbofsuggested = 0;
2497 foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {
2498 if (($stock_warehouse->real > 0 || !getDolGlobalInt('STOCK_DISALLOW_NEGATIVE_TRANSFER')) && (!empty($stock_warehouse->detail_batch))) {
2499 $nbofsuggested += count($stock_warehouse->detail_batch);
2500 }
2501 }
2502
2503 foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {
2504 $var = $subj % 2;
2505 if (!empty($warehousePicking) && !in_array($warehouse_id, $warehousePicking)) {
2506 // if a warehouse was selected by user, picking is limited to this warehouse and his children
2507 continue;
2508 }
2509
2510 $tmpwarehouseObject->fetch($warehouse_id);
2511 if (($stock_warehouse->real > 0 || !getDolGlobalInt('STOCK_DISALLOW_NEGATIVE_TRANSFER')) && (!empty($stock_warehouse->detail_batch))) {
2512 foreach ($stock_warehouse->detail_batch as $dbatch) {
2513 $batchStock = +$dbatch->qty; // To get a numeric
2514 if (isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {
2515 $deliverableQty = min($quantityToBeDelivered, $batchStock - $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)]);
2516 } else {
2517 if (!isset($alreadyQtyBatchSetted[$line->fk_product])) {
2518 $alreadyQtyBatchSetted[$line->fk_product] = array();
2519 }
2520
2521 if (!isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch])) {
2522 $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch] = array();
2523 }
2524
2525 $deliverableQty = min($quantityToBeDelivered, $batchStock);
2526 }
2527
2528 if ($deliverableQty < 0) {
2529 $deliverableQty = 0;
2530 }
2531
2532 $inputName = 'qtyl' . $indiceAsked . '_' . $subj;
2533 if (GETPOSTISSET($inputName)) {
2534 $deliverableQty = GETPOSTINT($inputName);
2535 }
2536
2537 $tooltipClass = $tooltipTitle = '';
2538 if (!empty($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {
2539 $tooltipClass = ' classfortooltip';
2540 $tooltipTitle = $langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines') . ' : ' . $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];
2541 } else {
2542 $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)] = 0;
2543 }
2544 $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)] = $deliverableQty + $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];
2545
2546 print '<!-- subj=' . $subj . '/' . $nbofsuggested . ' --><tr ' . ((($subj + 1) == $nbofsuggested) ? 'oddeven' : '') . '><td colspan="3"></td><td class="center">';
2547 $qtylValue = $deliverableQty;
2548 if (getDolGlobalBool('SHIPMENT_DONT_PREFILL_QTY', false)) {
2549 $qtylValue = '';
2550 } elseif (is_numeric($qtylValue)) {
2551 $qtylValue = price($qtylValue);
2552 }
2553 print '<input class="qtyl right ' . $tooltipClass . '" title="' . $tooltipTitle . '" name="' . $inputName . '" id="' . $inputName . '" type="text" size="4" value="' . $qtylValue . '">';
2554 print '</td>';
2555
2556 print '<td class="left">';
2557
2558 print $tmpwarehouseObject->getNomUrl(0) . ' / ';
2559
2560 print '<!-- Show details of lot -->';
2561 print '<input name="batchl' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $dbatch->id . '">';
2562 print '<input name="entl' . $indiceAsked . '_'.$subj.'" type="hidden" value="' . $tmpwarehouseObject->id . '">';
2563
2564 //print '|'.$line->fk_product.'|'.$dbatch->batch.'|<br>';
2565 print $langs->trans("Batch") . ': ';
2566 $result = $productlotObject->fetch(0, $line->fk_product, $dbatch->batch);
2567 if ($result > 0) {
2568 print $productlotObject->getNomUrl(1);
2569 } else {
2570 print $langs->trans("TableLotIncompleteRunRepairWithParamStandardEqualConfirmed");
2571 }
2572 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && !empty($dbatch->sellby)) {
2573 print ' - ' . $langs->trans("SellByDate") . ': ' . dol_print_date($dbatch->sellby, "day");
2574 }
2575 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && !empty($dbatch->eatby)) {
2576 print ' - ' . $langs->trans("EatByDate") . ': ' . dol_print_date($dbatch->eatby, "day");
2577 }
2578 print ' (' . $dbatch->qty . ')';
2579 $quantityToBeDelivered -= $deliverableQty;
2580 if ($quantityToBeDelivered < 0) {
2581 $quantityToBeDelivered = 0;
2582 }
2583 //dol_syslog('deliverableQty = '.$deliverableQty.' batchStock = '.$batchStock);
2584 $subj++;
2585 print '</td>';
2586 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2587 print '<td class="left">' . dol_print_date($dbatch->context['stock_entry_date'], 'day') . '</td>';
2588 }
2589 print '</tr>';
2590 }
2591 }
2592 }
2593 }
2594 if ($subj == 0) { // Line not shown yet, we show it
2595 $warehouse_selected_id = GETPOSTINT('entrepot_id');
2596
2597 print '<!-- line not shown yet, we show it -->';
2598 print '<tr class="oddeven"><td colspan="3"></td><td class="center">';
2599
2600 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2601 $disabled = '';
2602 $alt = '';
2603 if (isModEnabled('productbatch') && $product->hasbatch()) {
2604 $disabled = 'disabled="disabled"';
2605 $alt = 'Product need serial or batch number';
2606 }
2607 if ($warehouse_selected_id <= 0) { // We did not force a given warehouse, so we won't have no warehouse to change qty.
2608 $disabled = 'disabled="disabled"';
2609 }
2610 // finally we overwrite the input with the product status stockable_product if it's disabled
2611 if ($product->stockable_product == Product::ENABLED_STOCK) {
2612 $disabled = '';
2613 }
2614 print '<input class="qtyl right" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0"'.($disabled ? ' '.$disabled : '').($alt ? ' title="'.dolPrintHTMLForAttribute($alt).'"' : '').'> ';
2615 if (empty($disabled) && (!getDolGlobalInt('STOCK_DISALLOW_NEGATIVE_TRANSFER') || $product->stockable_product == Product::DISABLED_STOCK)) {
2616 print '<input name="ent1' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $warehouse_selected_id . '">';
2617 }
2618 } elseif ($line->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {
2619 // If we are here, it means STOCK_SUPPORTS_SERVICES is off (otherwise the previous test would be true)
2620 // So a service has no stock here, so neither a preselected warehouse nor STOCK_DISALLOW_NEGATIVE_TRANSFER is relevant here.
2621 $disabled = '';
2622 if (isModEnabled('productbatch') && $product->hasbatch()) {
2623 $disabled = 'disabled="disabled"';
2624 }
2625 print '<input class="qtyl right" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$quantityToBeDelivered.'"'.($disabled ? ' '.$disabled : '').'> ';
2626 // This hidden field must always be output: it is the marker the POST handler uses to detect that the quantities
2627 // of this line are named qtyl<i>_<subj>. Without it the handler looks for qtyl<i> instead, finds nothing and
2628 // silently drops the line. Value 0 = no warehouse, same as entl<i> in the single warehouse case above.
2629 print '<input name="ent1' . $indiceAsked . '_' . $subj . '" type="hidden" value="0">';
2630 } else {
2631 print $langs->trans("NA");
2632 }
2633 print '</td>';
2634
2635 print '<td class="left">';
2636 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
2637 // product may use stock management
2638 if (($warehouse_selected_id > 0 && $product->stockable_product == Product::ENABLED_STOCK)) {
2639 $warehouseObject = new Entrepot($db);
2640 $warehouseObject->fetch($warehouse_selected_id);
2641 print img_warning() . ' ' . $langs->trans("NoProductToShipFoundIntoStock", $warehouseObject->label);
2642 } else {
2643 if ($line->fk_product) {
2644 if ($product->stockable_product != Product::ENABLED_STOCK) {
2645 print img_warning() . ' ' . $langs->trans('StockDisabled');
2646 } else {
2647 print img_warning() . ' ' . $langs->trans('StockTooLow');
2648 }
2649 } else {
2650 print '';
2651 }
2652 }
2653 } else {
2654 print '<span class="opacitymedium">(' . $langs->trans("Service") . ')</span>';
2655 }
2656 print '</td>';
2657 if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {
2658 print '<td></td>';
2659 } //StockEntrydate
2660 print '</tr>';
2661 }
2662 }
2663 } elseif (empty($reshook) && $line->special_code == SUBTOTALS_SPECIAL_CODE && !in_array($line->id, $title_lines_to_disable)) {
2664 require dol_buildpath('/core/tpl/subtotalline_select.tpl.php');
2665 }
2666
2667 $indiceAsked++;
2668 }
2669
2670 print "</table>";
2671 print '</div>';
2672
2673 print '<br>';
2674
2675 print $form->buttonsSaveCancel("Create");
2676
2677 print '</form>';
2678
2679 print '<br>';
2680 } else {
2682 }
2683 }
2684} elseif ($object->id > 0) {
2685 '@phan-var-force Expedition $object'; // Need to force it (type overridden earlier)
2686
2687 // Edit and view mode
2688
2689 $lines = $object->lines;
2690
2691 $num_prod = count($lines);
2692
2693 if (!empty($object->origin) && $object->origin_id > 0) {
2694 $typeobject = $object->origin;
2695 $origin = (string) $object->origin; // Cast to string because origin is type hinted as object too.
2696 $origin_id = $object->origin_id;
2697
2698 $object->fetch_origin(); // Load property $object->origin_object (old $object->commande, $object->propal, ...)
2699 }
2700
2701 $soc = new Societe($db);
2702 $soc->fetch($object->socid);
2703
2704 $res = $object->fetch_optionals();
2705
2706 $head = shipping_prepare_head($object);
2707 print dol_get_fiche_head($head, 'shipping', $langs->trans("Shipment"), -1, $object->picto);
2708
2709 $formconfirm = '';
2710
2711 // Confirm deletion
2712 if ($action == 'delete') {
2713 $formquestion = array();
2714 if ($object->status == Expedition::STATUS_CLOSED && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2715 $formquestion = array(
2716 array(
2717 'label' => $langs->trans('ShipmentIncrementStockOnDelete'),
2718 'name' => 'alsoUpdateStock',
2719 'type' => 'checkbox',
2720 'value' => 0
2721 ),
2722 );
2723 }
2724 $formconfirm = $form->formconfirm(
2725 $_SERVER['PHP_SELF'] . '?id=' . $object->id,
2726 $langs->trans('DeleteSending'),
2727 $langs->trans("ConfirmDeleteSending", $object->ref),
2728 'confirm_delete',
2729 $formquestion,
2730 0,
2731 1
2732 );
2733 }
2734
2735 // Confirm delete of subtotal line
2736 if ($action == 'ask_subtotal_deleteline') {
2737 $lineid = GETPOSTINT('lineid');
2738 $langs->load("subtotals");
2739 $title = "DeleteSubtotalLine";
2740 $question = "ConfirmDeleteSubtotalLine";
2741 if (GETPOST('type') == 'title') {
2742 $formconfirm = array(array('type' => 'checkbox', 'name' => 'deletecorrespondingsubtotalline', 'label' => $langs->trans("DeleteCorrespondingSubtotalLine"), 'value' => 0));
2743 $title = "DeleteTitleLine";
2744 $question = "ConfirmDeleteTitleLine";
2745 }
2746 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans($title), $langs->trans($question), 'confirm_delete_subtotalline', $formconfirm, 'no', 1);
2747 }
2748
2749 // Confirm validation
2750 if ($action == 'valid') {
2751 $objectref = substr($object->ref, 1, 4);
2752 if ($objectref == 'PROV') {
2753 $numref = $object->getNextNumRef($soc);
2754 } else {
2755 $numref = (string) $object->ref;
2756 }
2757
2758 $text = $langs->trans("ConfirmValidateSending", $numref);
2759 if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) {
2760 $text .= '<br>' . img_picto('', 'movement', 'class="pictofixedwidth"') . $langs->trans("StockMovementWillBeRecorded") . '.';
2761 } elseif (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {
2762 $text .= '<br>' . img_picto('', 'movement', 'class="pictofixedwidth"') . $langs->trans("StockMovementNotYetRecorded") . '.';
2763 }
2764
2765 if (isModEnabled('notification')) {
2766 require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
2767 $notify = new Notify($db);
2768 $text .= '<br>';
2769 $text .= $notify->confirmMessage('SHIPPING_VALIDATE', $object->socid, $object);
2770 }
2771
2772 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateSending'), $text, 'confirm_valid', '', 0, 1, 260);
2773 }
2774
2775 // Confirm cancellation
2776 if ($action == 'cancel') {
2777 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?id=' . $object->id, $langs->trans('CancelSending'), $langs->trans("ConfirmCancelSending", $object->ref), 'confirm_cancel', '', 0, 1);
2778 }
2779
2780 // Confirm sign
2781 if ($action == 'sign') {
2782 $text = $langs->trans('ConfirmSignShipping');
2783 if (isModEnabled('notification')) {
2784 require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
2785 $notify = new Notify($db);
2786 $text .= '<br>';
2787 $text .= $notify->confirmMessage('SHIPPING_MODIFY', $object->socid, $object);
2788 }
2789 $formquestion = [];
2790 $formquestion[] = [
2791 'type' => 'select',
2792 'name' => 'signed_status',
2793 'select_show_empty' => 0,
2794 'label' => '<span class="fieldrequired">' . $langs->trans('SignStatus') . '</span>',
2795 'values' => $object->getSignedStatusLocalisedArray()
2796 ];
2797 $formconfirm = $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id]), $langs->trans('SignShipping'), $text, 'confirm_sign', $formquestion, 0, 1);
2798 }
2799
2800 // Confirm unsign
2801 if ($action == 'unsign') {
2802 $text = $langs->trans('ConfirmUnsignShipping');
2803 if (isModEnabled('notification')) {
2804 require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
2805 $notify = new Notify($db);
2806 $text .= '<br>';
2807 $text .= $notify->confirmMessage('SHIPPING_MODIFY', $object->socid, $object);
2808 }
2809 $formconfirm = $form->formconfirm(dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id]), $langs->trans('UnsignShipping'), $text, 'confirm_unsign', '', 0, 1);
2810 }
2811
2812 // Call Hook formConfirm
2813 $parameters = array('formConfirm' => $formconfirm);
2814 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2815 if (empty($reshook)) {
2816 $formconfirm .= $hookmanager->resPrint;
2817 } elseif ($reshook > 0) {
2818 $formconfirm = $hookmanager->resPrint;
2819 }
2820
2821 // Print form confirm
2822 print $formconfirm;
2823
2824 // Calculate totalWeight and totalVolume for all products
2825 // by adding weight and volume of each product line.
2826 $tmparray = $object->getTotalWeightVolume();
2827 $totalWeight = $tmparray['weight'];
2828 $totalVolume = $tmparray['volume'];
2829
2830 if (!empty($typeobject) && $typeobject === 'commande' && is_object($object->origin_object) && $object->origin_object->id && isModEnabled('order')) {
2831 $objectsrc = new Commande($db);
2832 $objectsrc->fetch($object->origin_object->id);
2833 }
2834 if (!empty($typeobject) && $typeobject === 'propal' && is_object($object->origin_object) && $object->origin_object->id && isModEnabled("propal")) {
2835 $objectsrc = new Propal($db);
2836 $objectsrc->fetch($object->origin_object->id);
2837 }
2838
2839 // Shipment card
2840 $linkback = '<a href="' . DOL_URL_ROOT . '/expedition/list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
2841 $morehtmlref = '<div class="refidno">';
2842 // Ref customer shipment
2843 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string', '', 0, 1);
2844 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string' . (isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':' . getDolGlobalString('THIRDPARTY_REF_INPUT_SIZE') : ''), '', null, null, '', 1);
2845
2846 // Thirdparty
2847 $morehtmlref .= '<br>' . $object->thirdparty->getNomUrl(1);
2848
2849 // Project
2850 if ($origin && $origin_id > 0) {
2851 if (isModEnabled('project')) {
2852 $langs->load("projects");
2853 $morehtmlref .= '<br>';
2854 if (0) { // @phpstan-ignore-line Do not change on shipment
2855 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
2856 if ($action != 'classify') {
2857 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
2858 }
2859 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, (string) $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
2860 } else {
2861 if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
2862 $proj = new Project($db);
2863 $proj->fetch($objectsrc->fk_project);
2864 $morehtmlref .= $proj->getNomUrl(1);
2865 if ($proj->title) {
2866 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
2867 }
2868 }
2869 }
2870 }
2871 } elseif (!$origin && getDolGlobalString('SHIPMENT_STANDALONE')) {
2872 // Project
2873 if (isModEnabled('project')) {
2874 $langs->load("projects");
2875 $morehtmlref .= '<br>';
2876 if ($permissiontoadd) {
2877 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
2878 if ($action != 'classify') {
2879 $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
2880 }
2881 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
2882 } else {
2883 if (!empty($object->fk_project)) {
2884 $proj = new Project($db);
2885 $proj->fetch($object->fk_project);
2886 $morehtmlref .= $proj->getNomUrl(1);
2887 if ($proj->title) {
2888 $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
2889 }
2890 }
2891 }
2892 }
2893 }
2894
2895 $morehtmlref .= '</div>';
2896 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
2897
2898 print '<div class="fichecenter">';
2899 print '<div class="fichehalfleft">';
2900 print '<div class="underbanner clearboth"></div>';
2901
2902 print '<table class="border tableforfield centpercent">';
2903
2904 // Linked documents
2905 if (!empty($typeobject) && $typeobject == 'commande' && $object->origin_object->id && isModEnabled('order')) {
2906 print '<tr><td>';
2907 print $langs->trans("RefOrder") . '</td>';
2908 print '<td>';
2909 print $objectsrc->getNomUrl(1, 'commande');
2910 print "</td>\n";
2911 print '</tr>';
2912 }
2913 if (!empty($typeobject) && $typeobject == 'propal' && $object->origin_object->id && isModEnabled("propal")) {
2914 print '<tr><td>';
2915 print $langs->trans("RefProposal") . '</td>';
2916 print '<td>';
2917 print $objectsrc->getNomUrl(1, 'expedition');
2918 print "</td>\n";
2919 print '</tr>';
2920 }
2921
2922 // Date creation
2923 print '<tr><td class="titlefieldmiddle">' . $langs->trans("DateCreation") . '</td>';
2924 print '<td>' . dol_print_date($object->date_creation, "dayhour") . "</td>\n";
2925 print '</tr>';
2926
2927 // Delivery date planned
2928 print '<tr><td height="10">';
2929 print '<table class="nobordernopadding centpercent"><tr><td>';
2930 print $langs->trans('DateDeliveryPlanned');
2931 print '</td>';
2932 if ($action != 'editdate_livraison') {
2933 print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editdate_livraison&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->trans('SetDeliveryDate'), 1) . '</a></td>';
2934 }
2935 print '</tr></table>';
2936 print '</td><td>';
2937 if ($action == 'editdate_livraison') {
2938 print '<form name="setdate_livraison" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
2939 print '<input type="hidden" name="token" value="' . newToken() . '">';
2940 print '<input type="hidden" name="action" value="setdate_livraison">';
2941 print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, 0, "setdate_livraison", 1, 0);
2942 print '<input type="submit" class="button button-edit smallpaddingimp" value="' . $langs->trans('Modify') . '">';
2943 print '</form>';
2944 } else {
2945 print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
2946 }
2947 print '</td>';
2948 print '</tr>';
2949
2950 // Delivery sending date
2951 print '<tr><td height="10">';
2952 print '<table class="nobordernopadding centpercent"><tr><td>';
2953 print $langs->trans('DateShipping');
2954 print '</td>';
2955 if ($action != 'editdate_shipping') {
2956 print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editdate_shipping&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->trans('SetShippingDate'), 1) . '</a></td>';
2957 }
2958 print '</tr></table>';
2959 print '</td><td>';
2960 if ($action == 'editdate_shipping') {
2961 print '<form name="setdate_shipping" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
2962 print '<input type="hidden" name="token" value="' . newToken() . '">';
2963 print '<input type="hidden" name="action" value="setdate_shipping">';
2964 print $form->selectDate($object->date_shipping ? $object->date_shipping : -1, 'ship_', 1, 1, 0, "setdate_shipping", 1, 0);
2965 print '<input type="submit" class="button button-edit smallpaddingimp" value="' . $langs->trans('Modify') . '">';
2966 print '</form>';
2967 } else {
2968 print $object->date_shipping ? dol_print_date($object->date_shipping, 'dayhour') : '&nbsp;';
2969 }
2970 print '</td>';
2971 print '</tr>';
2972
2973 // Weight
2974 print '<tr><td>';
2975 print $form->editfieldkey("Weight", 'trueWeight', $object->trueWeight, $object, $user->hasRight('expedition', 'creer'));
2976 print '</td><td>';
2977
2978 if ($action == 'edittrueWeight') {
2979 print '<form name="settrueweight" action="' . $_SERVER["PHP_SELF"] . '" method="post">';
2980 print '<input name="action" value="settrueWeight" type="hidden">';
2981 print '<input name="id" value="' . $object->id . '" type="hidden">';
2982 print '<input type="hidden" name="token" value="' . newToken() . '">';
2983 print '<input id="trueWeight" name="trueWeight" value="' . $object->trueWeight . '" type="text" class="width50 valignmiddle">';
2984 print $formproduct->selectMeasuringUnits("weight_units", "weight", (string) $object->weight_units, 0, 2, 'maxwidth125 valignmiddle');
2985 print ' <input class="button smallpaddingimp valignmiddle" name="modify" value="' . $langs->trans("Modify") . '" type="submit">';
2986 print ' <input class="button button-cancel smallpaddingimp valignmiddle" name="cancel" value="' . $langs->trans("Cancel") . '" type="submit">';
2987 print '</form>';
2988 } else {
2989 print $object->trueWeight;
2990 print ($object->trueWeight && $object->weight_units != '') ? ' ' . measuringUnitString(0, "weight", $object->weight_units) : '';
2991 }
2992
2993 // Calculated
2994 if ($totalWeight > 0) {
2995 if (!empty($object->trueWeight)) {
2996 print ' (' . $langs->trans("SumOfProductWeights") . ': ';
2997 }
2998 print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, getDolGlobalInt('MAIN_WEIGHT_DEFAULT_ROUND', -1), getDolGlobalString('MAIN_WEIGHT_DEFAULT_UNIT', 'no'));
2999 if (!empty($object->trueWeight)) {
3000 print ')';
3001 }
3002 }
3003 print '</td></tr>';
3004
3005 // Width
3006 print '<tr><td>' . $form->editfieldkey("Width", 'trueWidth', $object->trueWidth, $object, $user->hasRight('expedition', 'creer')) . '</td><td>';
3007 print $form->editfieldval("Width", 'trueWidth', $object->trueWidth, $object, $user->hasRight('expedition', 'creer'));
3008 print ($object->trueWidth && $object->width_units != '') ? ' ' . measuringUnitString(0, "size", $object->width_units) : '';
3009 print '</td></tr>';
3010
3011 // Height
3012 print '<tr><td>' . $form->editfieldkey("Height", 'trueHeight', $object->trueHeight, $object, $user->hasRight('expedition', 'creer')) . '</td><td>';
3013 if ($action == 'edittrueHeight') {
3014 print '<form name="settrueHeight" action="' . $_SERVER["PHP_SELF"] . '" method="post">';
3015 print '<input name="action" value="settrueHeight" type="hidden">';
3016 print '<input name="id" value="' . $object->id . '" type="hidden">';
3017 print '<input type="hidden" name="token" value="' . newToken() . '">';
3018 print '<input id="trueHeight" name="trueHeight" value="' . $object->trueHeight . '" type="text" class="width50">';
3019 print $formproduct->selectMeasuringUnits("size_units", "size", $object->size_units, 0, 2);
3020 print ' <input class="button smallpaddingimp" name="modify" value="' . $langs->trans("Modify") . '" type="submit">';
3021 print ' <input class="button button-cancel smallpaddingimp" name="cancel" value="' . $langs->trans("Cancel") . '" type="submit">';
3022 print '</form>';
3023 } else {
3024 print $object->trueHeight;
3025 print ($object->trueHeight && $object->height_units != '') ? ' ' . measuringUnitString(0, "size", $object->height_units) : '';
3026 }
3027
3028 print '</td></tr>';
3029
3030 // Depth
3031 print '<tr><td>' . $form->editfieldkey("Depth", 'trueDepth', $object->trueDepth, $object, $user->hasRight('expedition', 'creer')) . '</td><td>';
3032 print $form->editfieldval("Depth", 'trueDepth', $object->trueDepth, $object, $user->hasRight('expedition', 'creer'));
3033 print ($object->trueDepth && $object->depth_units != '') ? ' ' . measuringUnitString(0, "size", $object->depth_units) : '';
3034 print '</td></tr>';
3035
3036 // Volume
3037 print '<tr><td>';
3038 print $langs->trans("Volume");
3039 print '</td>';
3040 print '<td>';
3041 $calculatedVolume = 0;
3042 $volumeUnit = 0;
3043 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
3044 $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
3045 $volumeUnit = $object->size_units * 3;
3046 }
3047 // If sending volume not defined we use sum of products
3048 if ($calculatedVolume > 0) {
3049 if ($volumeUnit < 50) {
3050 print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, getDolGlobalInt('MAIN_VOLUME_DEFAULT_ROUND', -1), getDolGlobalString('MAIN_VOLUME_DEFAULT_UNIT', 'no'));
3051 } else {
3052 print $calculatedVolume . ' ' . measuringUnitString(0, "volume", $volumeUnit);
3053 }
3054 }
3055 if ($totalVolume > 0) {
3056 if ($calculatedVolume) {
3057 print ' (' . $langs->trans("SumOfProductVolumes") . ': ';
3058 }
3059 print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, getDolGlobalInt('MAIN_VOLUME_DEFAULT_ROUND', -1), getDolGlobalString('MAIN_VOLUME_DEFAULT_UNIT', 'no'));
3060 //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
3061 if ($calculatedVolume) {
3062 print ')';
3063 }
3064 }
3065 print "</td>\n";
3066 print '</tr>';
3067
3068 // Other attributes
3069 //$cols = 2;
3070 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
3071
3072 print '</table>';
3073
3074 print '</div>';
3075 print '<div class="fichehalfright">';
3076 print '<div class="underbanner clearboth"></div>';
3077
3078 print '<table class="border centpercent tableforfield">';
3079
3080 // Sending method
3081 print '<tr><td>';
3082 print '<table class="nobordernopadding centpercent"><tr><td>';
3083 print $langs->trans('SendingMethod');
3084 print '</td>';
3085
3086 if ($action != 'editshipping_method_id' && $permissiontoadd) {
3087 print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editshipping_method_id&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->trans('SetSendingMethod'), 1) . '</a></td>';
3088 }
3089 print '</tr></table>';
3090 print '</td><td>';
3091 if ($action == 'editshipping_method_id') {
3092 print '<form name="setshipping_method_id" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
3093 print '<input type="hidden" name="token" value="' . newToken() . '">';
3094 print '<input type="hidden" name="action" value="setshipping_method_id">';
3095 $object->fetch_delivery_methods();
3096 print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1);
3097 if ($user->admin) {
3098 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
3099 }
3100 print '<input type="submit" class="button button-edit smallpaddingimp" value="' . $langs->trans('Modify') . '">';
3101 print '</form>';
3102 } else {
3103 if ($object->shipping_method_id > 0) {
3104 // Get code using getLabelFromKey
3105 $code = $langs->getLabelFromKey($db, (string) $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
3106 print $langs->trans("SendingMethod" . strtoupper($code));
3107 }
3108 }
3109 print '</td>';
3110 print '</tr>';
3111
3112 // Tracking Number
3113 print '<tr><td class="titlefieldmiddle">' . $form->editfieldkey("TrackingNumber", 'tracking_number', $object->tracking_number, $object, $user->hasRight('expedition', 'creer')) . '</td><td>';
3114 print $form->editfieldval("TrackingNumber", 'tracking_number', $object->tracking_url, $object, $user->hasRight('expedition', 'creer'), 'safehtmlstring', $object->tracking_number);
3115 print '</td></tr>';
3116
3117 // Incoterms
3118 if (isModEnabled('incoterm')) {
3119 print '<tr><td>';
3120 print '<table class="nobordernopadding centpercent"><tr><td>';
3121 print $langs->trans('IncotermLabel');
3122 print '<td><td class="right">';
3123 if ($permissiontoadd) {
3124 print '<a class="editfielda" href="' . DOL_URL_ROOT . '/expedition/card.php?id=' . $object->id . '&action=editincoterm&token=' . newToken() . '">' . img_edit() . '</a>';
3125 } else {
3126 print '&nbsp;';
3127 }
3128 print '</td></tr></table>';
3129 print '</td>';
3130 print '<td>';
3131 if ($action != 'editincoterm') {
3132 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3133 } else {
3134 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'] . '?id=' . $object->id);
3135 }
3136 print '</td></tr>';
3137 }
3138
3139 // Other attributes
3140 $parameters = array();
3141 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3142 print $hookmanager->resPrint;
3143
3144 print "</table>";
3145
3146 print '</div>';
3147 print '</div>';
3148
3149 print '<div class="clearboth"></div>';
3150
3151 print dol_get_fiche_end();
3152
3153
3154 /*
3155 * Lines of simple shipment
3156 */
3157 if (!$origin && getDolGlobalString('SHIPMENT_STANDALONE')) {
3158 if (!empty($object->table_element_line)) {
3159 // Show object lines
3160 $result = $object->getLinesArray();
3161
3162 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOSTINT('lineid')).'" method="POST">
3163 <input type="hidden" name="token" value="' . newToken().'">
3164 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
3165 <input type="hidden" name="mode" value="">
3166 <input type="hidden" name="page_y" value="">
3167 <input type="hidden" name="id" value="' . $object->id.'">
3168 ';
3169
3170 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
3171 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
3172 }
3173
3174 print '<div class="div-table-responsive-no-min">';
3175 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
3176 print '<table id="tablelines" class="noborder noshadow" width="100%">';
3177 }
3178
3179 if (!empty($object->lines)) {
3180 $object->printObjectLines($action, $mysoc, null, GETPOSTINT('lineid'), 1, '/expedition/tpl');
3181 }
3182
3183 // Form to add new line
3184 if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
3185 if ($action != 'editline') {
3186 // Add products/services form
3187
3188 $parameters = array();
3189 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3190 if ($reshook < 0) {
3191 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
3192 }
3193 if (empty($reshook)) {
3194 $object->formAddObjectLine(1, $mysoc, $soc);
3195 }
3196 }
3197 }
3198
3199 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
3200 print '</table>';
3201 }
3202 print '</div>';
3203
3204 print "</form>\n";
3205 }
3206 }
3207
3208 // Lines of products of origin
3209 if (!empty($object->origin) && $object->origin_id > 0) {
3210 if ($action == 'editline') {
3211 print ' <form name="updateline" id="updateline" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;lineid=' . $line_id . '" method="POST">
3212 <input type="hidden" name="token" value="' . newToken() . '">
3213 <input type="hidden" name="action" value="updateline">
3214 <input type="hidden" name="mode" value="">
3215 <input type="hidden" name="id" value="' . $object->id . '">
3216 ';
3217 }
3218 print '<br>';
3219 if (!empty($conf->use_javascript_ajax) && $object->status == Expedition::STATUS_DRAFT && $usercancreate && $num_prod > 1) {
3220 include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
3221 }
3222
3223 print '<div class="div-table-responsive-no-min">';
3224 print '<table class="noborder centpercent" id="tablelines" >';
3225 print '<thead>';
3226 print '<tr class="liste_titre">';
3227 // Adds a line numbering column
3228 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
3229 print '<td width="5" class="center linecolnum">&nbsp;</td>';
3230 }
3231 // Product/Service
3232 print '<td class="linecoldescription" >' . $langs->trans("Products") . '</td>';
3233 // Qty
3234 print '<td class="center linecolqty">' . $langs->trans("QtyOrdered") . '</td>';
3235 if ($origin_id > 0) {
3236 print '<td class="center linecolqtyinothershipments">' . $langs->trans("QtyInOtherShipments") . '</td>';
3237 }
3238 if ($action == 'editline') {
3239 $editColspan = 3;
3240 if (!isModEnabled('stock')) {
3241 $editColspan--;
3242 }
3243 if (!isModEnabled('productbatch')) {
3244 $editColspan--;
3245 }
3246 print '<td class="center linecoleditlineotherinfo" colspan="' . $editColspan . '">';
3247 if ($object->status <= 1) {
3248 print $langs->trans("QtyToShip");
3249 } else {
3250 print $langs->trans("QtyShipped");
3251 }
3252 if (isModEnabled('stock')) {
3253 print ' - ' . $langs->trans("WarehouseSource");
3254 }
3255 if (isModEnabled('productbatch')) {
3256 print ' - ' . $langs->trans("Batch");
3257 }
3258 print '</td>';
3259 } else {
3260 if ($object->status <= 1) {
3261 print '<td class="center linecolqtytoship">' . $langs->trans("QtyToShip") . '</td>';
3262 } else {
3263 print '<td class="center linecolqtyshipped">' . $langs->trans("QtyShipped") . '</td>';
3264 }
3265 if (isModEnabled('stock')) {
3266 print '<td class="left linecolwarehousesource">' . $langs->trans("WarehouseSource") . '</td>';
3267 }
3268
3269 if (isModEnabled('productbatch')) {
3270 print '<td class="left linecolbatch">' . $langs->trans("Batch") . '</td>';
3271 }
3272 }
3273 print '<td class="center linecolweight">' . $langs->trans("CalculatedWeight") . '</td>';
3274 print '<td class="center linecolvolume">' . $langs->trans("CalculatedVolume") . '</td>';
3275 //print '<td class="center">'.$langs->trans("Size").'</td>';
3276 if ($object->status == 0) {
3277 print '<td class="linecoledit"></td>';
3278 print '<td class="linecoldelete" width="10"></td>';
3279 print '<td class="linecolmove"></td>';
3280 }
3281 print "</tr>\n";
3282 print '</thead>';
3283
3284 $outputlangs = $langs;
3285
3286 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
3287 $object->fetch_thirdparty();
3288 $newlang = '';
3289 if (/* empty($newlang) && */GETPOST('lang_id', 'aZ09')) {
3290 $newlang = GETPOST('lang_id', 'aZ09');
3291 }
3292 if (empty($newlang)) {
3293 $newlang = $object->thirdparty->default_lang;
3294 }
3295 if (!empty($newlang)) {
3296 $outputlangs = new Translate("", $conf);
3297 $outputlangs->setDefaultLang($newlang);
3298 }
3299 }
3300
3301 $origin = (string) $origin;
3302 if (empty($origin) || $origin == 'order') {
3303 $origin = 'commande';
3304 }
3305
3306 // List of allowed value of $origin
3307 if (!in_array($origin, array('supplier_proposal', 'supplier_order', 'commande_fournisseur', 'facture_fourn', 'propal', 'commande', 'facture'))) {
3308 dol_print_error($db, 'Bad value for parameter origin in expedition/card.php');
3309 exit;
3310 }
3311
3312 // Get list of products already sent for same source object into $alreadysent
3313 $alreadysent = array();
3314 if ($origin_id > 0) {
3315 $tablenametouse = (($origin == 'supplier_order') ? 'commande_fournisseur' : (($origin == 'facture_fourn') ? 'facture_fourn_' : $origin));
3316
3317 $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.fk_unit, obj.date_start, obj.date_end, obj.special_code";
3318 $sql .= ", ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_elementdet, ed.fk_entrepot";
3319 $sql .= ", e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition";
3320 $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch';
3321 $sql .= ', p.description as product_desc';
3322 $sql .= " FROM " . MAIN_DB_PREFIX . "expeditiondet as ed";
3323 $sql .= ", " . MAIN_DB_PREFIX . "expedition as e";
3324 $sql .= ", " . MAIN_DB_PREFIX . $db->sanitize($tablenametouse) . "det as obj";
3325 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON obj.fk_product = p.rowid";
3326 $sql .= " WHERE e.entity IN (" . getEntity('expedition') . ")";
3327 $sql .= " AND obj.fk_" . $db->sanitize((string) $origin) . " = " . ((int) $origin_id);
3328 $sql .= " AND obj.rowid = ed.fk_elementdet";
3329 $sql .= " AND ed.fk_expedition = e.rowid";
3330 //if ($filter) $sql.= $filter;
3331 $sql .= " ORDER BY obj.fk_product";
3332
3333 dol_syslog("expedition/card.php get list of shipment lines", LOG_DEBUG);
3334 $resql = $db->query($sql);
3335 if ($resql) {
3336 $num = $db->num_rows($resql);
3337 $i = 0;
3338
3339 while ($i < $num) {
3340 $obj = $db->fetch_object($resql);
3341 if ($obj) {
3342 // $obj->rowid is rowid in $origin."det" table
3343 $alreadysent[$obj->rowid][$obj->shipmentline_id] = array(
3344 'shipment_ref' => $obj->shipment_ref,
3345 'shipment_id' => $obj->shipment_id,
3346 'warehouse' => $obj->fk_entrepot,
3347 'qty_shipped' => $obj->qty_shipped,
3348 'product_tosell' => $obj->product_tosell,
3349 'product_tobuy' => $obj->product_tobuy,
3350 'product_tobatch' => $obj->product_tobatch,
3351 'date_valid' => $db->jdate($obj->date_valid),
3352 'date_delivery' => $db->jdate($obj->date_delivery));
3353 }
3354 $i++;
3355 }
3356 }
3357 //var_dump($alreadysent);
3358 }
3359
3360 print '<tbody>';
3361
3362 // Loop on each product to send/sent
3363 $conf->cache['product'] = array();
3364 $conf->cache['warehouse'] = array();
3365 for ($i = 0; $i < $num_prod; $i++) {
3366 $parameters = array('i' => $i, 'line' => $lines[$i], 'line_id' => $line_id, 'num' => $num_prod, 'alreadysent' => $alreadysent, 'editColspan' => !empty($editColspan) ? $editColspan : 0, 'outputlangs' => $outputlangs);
3367 $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);
3368 if ($reshook < 0) {
3369 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
3370 }
3371
3372 if (empty($reshook) && $lines[$i]->product_type != "9") {
3373 print '<!-- origin line id = ' . $lines[$i]->origin_line_id . ' -->'; // id of order line
3374 print '<tr class="oddeven" id="row-' . $lines[$i]->id . '" data-id="' . $lines[$i]->id . '" data-element="' . $lines[$i]->element . '" >';
3375 $line = $lines[$i];
3376 $line->fetch_optionals();
3377
3378 // #
3379 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
3380 print '<td class="center linecolnum">' . ($i + 1) . '</td>';
3381 }
3382
3383 // Predefined product or service
3384 if ($lines[$i]->fk_product > 0) {
3385 // Define output language
3386 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
3387 $product_id = $lines[$i]->fk_product;
3388 if (!isset($conf->cache['product'][$product_id])) {
3389 $prod = new Product($db);
3390 $prod->fetch($product_id);
3391 $conf->cache['product'][$product_id] = $prod;
3392 } else {
3393 $prod = $conf->cache['product'][$product_id];
3394 }
3395 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;
3396 } else {
3397 $label = (!empty($lines[$i]->label) ? $lines[$i]->label : $lines[$i]->product_label);
3398 }
3399
3400 print '<td class="linecoldescription">';
3401
3402 // Show product and description
3403 $product_static->type = $lines[$i]->fk_product_type;
3404 $product_static->id = $lines[$i]->fk_product;
3405 $product_static->ref = $lines[$i]->ref;
3406 $product_static->status = $lines[$i]->product_tosell;
3407 $product_static->status_buy = $lines[$i]->product_tobuy;
3408 $product_static->status_batch = $lines[$i]->product_tobatch;
3409
3410 $product_static->weight = $lines[$i]->weight;
3411 $product_static->weight_units = $lines[$i]->weight_units;
3412 $product_static->length = $lines[$i]->length;
3413 $product_static->length_units = $lines[$i]->length_units;
3414 $product_static->width = !empty($lines[$i]->width) ? $lines[$i]->width : 0;
3415 $product_static->width_units = !empty($lines[$i]->width_units) ? $lines[$i]->width_units : 0;
3416 $product_static->height = !empty($lines[$i]->height) ? $lines[$i]->height : 0;
3417 $product_static->height_units = !empty($lines[$i]->height_units) ? $lines[$i]->height_units : 0;
3418 $product_static->surface = $lines[$i]->surface;
3419 $product_static->surface_units = $lines[$i]->surface_units;
3420 $product_static->volume = $lines[$i]->volume;
3421 $product_static->volume_units = $lines[$i]->volume_units;
3422 $product_static->stockable_product = $lines[$i]->stockable_product;
3423
3424 $text = $product_static->getNomUrl(1);
3425 $text .= ' - ' . $label;
3426 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($lines[$i]->description));
3427 print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
3428 print_date_range(!empty($lines[$i]->date_start) ? $lines[$i]->date_start : '', !empty($lines[$i]->date_end) ? $lines[$i]->date_end : '');
3429 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
3430 print (!empty($lines[$i]->description) && $lines[$i]->description != $lines[$i]->product) ? '<br>' . dol_htmlentitiesbr($lines[$i]->description) : '';
3431 }
3432 $lineExtrafieldsHtml = $line->showOptionals($extrafields, ($action == 'editline' && $line->id == $line_id) ? 'edit' : 'view', array(), '', '', '1', 'line');
3433 if (!empty($lineExtrafieldsHtml)) {
3434 print '<div style="padding-top: 10px" id="extrafield_lines_area_' . $line->id . '" name="extrafield_lines_area_' . $line->id . '">';
3435 print $lineExtrafieldsHtml;
3436 print '</div>';
3437 }
3438 print "</td>\n";
3439 } else {
3440 print '<td class="linecoldescription" >';
3441 if ($lines[$i]->product_type == Product::TYPE_SERVICE) {
3442 $text = img_object($langs->trans('Service'), 'service');
3443 } else {
3444 $text = img_object($langs->trans('Product'), 'product');
3445 }
3446
3447 if (!empty($lines[$i]->label)) {
3448 $text .= ' <strong>' . $lines[$i]->label . '</strong>';
3449 print $form->textwithtooltip($text, $lines[$i]->description, 3, 0, '', (string) $i);
3450 } else {
3451 print $text . ' ' . nl2br($lines[$i]->description);
3452 }
3453
3454 print_date_range($lines[$i]->date_start, $lines[$i]->date_end);
3455 $lineExtrafieldsHtml = $line->showOptionals($extrafields, ($action == 'editline' && $line->id == $line_id) ? 'edit' : 'view', array(), '', '', '1', 'line');
3456 if (!empty($lineExtrafieldsHtml)) {
3457 print '<div style="padding-top: 10px" id="extrafield_lines_area_' . $line->id . '" name="extrafield_lines_area_' . $line->id . '">';
3458 print $lineExtrafieldsHtml;
3459 print '</div>';
3460 }
3461 print "</td>\n";
3462 }
3463
3464 $unit_order = '';
3465 if (getDolGlobalString('PRODUCT_USE_UNITS')) {
3466 $unit_order = measuringUnitString((int) $lines[$i]->fk_unit);
3467 }
3468
3469 // Qty ordered
3470 print '<td class="center linecolqty">' . $lines[$i]->qty_asked . ' ' . $unit_order . '</td>';
3471
3472 // Qty in other shipments (with shipment and warehouse used)
3473 if ($origin_id > 0) {
3474 print '<td class="linecolqtyinothershipments center nowrap">';
3475 $htmltooltip = '';
3476 $qtyalreadysent = 0;
3477 foreach ($alreadysent as $key => $val) {
3478 if ($lines[$i]->fk_elementdet == $key) {
3479 $j = 0;
3480 foreach ($val as $shipmentline_id => $shipmentline_var) {
3481 if ($shipmentline_var['shipment_id'] == $lines[$i]->fk_expedition) {
3482 continue; // We want to show only "other shipments"
3483 }
3484
3485 $j++;
3486 if ($j > 1) {
3487 $htmltooltip .= '<br>';
3488 }
3489 $shipment_static->fetch($shipmentline_var['shipment_id']);
3490 $htmltooltip .= $shipment_static->getNomUrl(1, '', 0, 0, 1);
3491 $htmltooltip .= ' - ' . $shipmentline_var['qty_shipped'];
3492 $htmltooltip .= ' - ' . $langs->trans("DateValidation") . ' : ' . (empty($shipmentline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($shipmentline_var['date_valid'], 'dayhour'));
3493 /*if (isModEnabled('stock') && $shipmentline_var['warehouse'] > 0) {
3494 $warehousestatic->fetch($shipmentline_var['warehouse']);
3495 $htmltext .= '<br>'.$langs->trans("FromLocation").' : '.$warehousestatic->getNomUrl(1, '', 0, 1);
3496 }*/
3497 //print ' '.$form->textwithpicto('', $htmltext, 1);
3498
3499 $qtyalreadysent += $shipmentline_var['qty_shipped'];
3500 }
3501 if ($j) {
3502 $htmltooltip = $langs->trans("QtyInOtherShipments") . '...<br><br>' . $htmltooltip . '<br><input type="submit" name="dummyhiddenbuttontogetfocus" style="display:none" autofocus>';
3503 }
3504 }
3505 }
3506 print $form->textwithpicto((string) $qtyalreadysent, $htmltooltip, 1, 'info', '', 0, 3, 'tooltip' . $lines[$i]->id);
3507 print '</td>';
3508 }
3509
3510 if ($action == 'editline' && $lines[$i]->id == $line_id) {
3511 // edit mode
3512 print '<td colspan="' . $editColspan . '" class="center"><table class="nobordernopadding centpercent">';
3513 if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) {
3514 print '<!-- case edit 1 -->';
3515 $line = new ExpeditionLigne($db);
3516 foreach ($lines[$i]->detail_batch as $detail_batch) {
3517 print '<tr>';
3518 // Qty to ship or shipped
3519 print '<td><input class="qtyl right" name="qtyl' . $detail_batch->fk_expeditiondet . '_' . $detail_batch->id . '" id="qtyl' . $line_id . '_' . $detail_batch->id . '" type="text" size="4" value="' . $detail_batch->qty . '"></td>';
3520 // Batch number management
3521 if ($lines[$i]->entrepot_id == 0) {
3522 // only show lot numbers from src warehouse when shipping from multiple warehouses
3523 $line->fetch($detail_batch->fk_expeditiondet);
3524 }
3525 $entrepot_id = !empty($detail_batch->entrepot_id) ? $detail_batch->entrepot_id : $lines[$i]->entrepot_id;
3526 print '<td>' . $formproduct->selectLotStock($detail_batch->fk_origin_stock, 'batchl' . $detail_batch->fk_expeditiondet . '_' . $detail_batch->fk_origin_stock, '', 1, 0, $lines[$i]->fk_product, $entrepot_id) . '</td>';
3527 print '</tr>';
3528 }
3529 // add a 0 qty lot row to be able to add a lot
3530 print '<tr>';
3531 // Qty to ship or shipped
3532 print '<td><input class="qtyl" name="qtyl' . $line_id . '_0" id="qtyl' . $line_id . '_0" type="text" size="4" value="0"></td>';
3533 // Batch number management
3534 print '<td>' . $formproduct->selectLotStock('', 'batchl' . $line_id . '_0', '', 1, 0, $lines[$i]->fk_product) . '</td>';
3535 print '</tr>';
3536 } elseif (isModEnabled('stock')) {
3537 if ($lines[$i]->fk_product > 0) {
3538 if ($lines[$i]->entrepot_id > 0) {
3539 print '<!-- case edit 2 -->';
3540 print '<tr>';
3541 // Qty to ship or shipped
3542 print '<td><input class="qtyl right" name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines[$i]->qty_shipped . '">' . $unit_order . '</td>';
3543 // Warehouse source
3544 print '<td>' . $formproduct->selectWarehouses($lines[$i]->entrepot_id, 'entl' . $line_id, '', 1, 0, $lines[$i]->fk_product, '', 1, 0, array(), 'minwidth200') . '</td>';
3545 // Batch number management
3546 print '<td>';
3547 if (isModEnabled('productbatch')) {
3548 print ' - ' . $langs->trans("NA");
3549 }
3550 print '</td>';
3551 print '</tr>';
3552 } elseif (count($lines[$i]->details_entrepot) > 1) {
3553 print '<!-- case edit 3 -->';
3554 foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
3555 print '<tr>';
3556 // Qty to ship or shipped
3557 print '<td><input class="qtyl right" name="qtyl' . $detail_entrepot->line_id . '" id="qtyl' . $detail_entrepot->line_id . '" type="text" size="4" value="' . $detail_entrepot->qty_shipped . '">' . $unit_order . '</td>';
3558 // Warehouse source
3559 print '<td>' . $formproduct->selectWarehouses($detail_entrepot->entrepot_id, 'entl' . $detail_entrepot->line_id, '', 1, 0, $lines[$i]->fk_product, '', 1, 0, array(), 'minwidth200') . '</td>';
3560 // Batch number management
3561 print '<td>';
3562 if (isModEnabled('productbatch')) {
3563 print ' - ' . $langs->trans("NA");
3564 }
3565 print '</td>';
3566 print '</tr>';
3567 }
3568 } elseif ($lines[$i]->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {
3569 print '<!-- case edit 4 -->';
3570 print '<tr>';
3571 // Qty to ship or shipped
3572 print '<td><input class="qtyl right" name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines[$i]->qty_shipped . '"></td>';
3573 print '<td><span class="opacitymedium">(' . $langs->trans("Service") . ')</span></td>';
3574 print '<td></td>';
3575 print '</tr>';
3576 } else {
3577 print '<!-- case edit 5 -->';
3578 print '<tr><td colspan="3">' . $langs->trans("ErrorStockIsNotEnough") . '</td></tr>';
3579 }
3580 } else {
3581 print '<!-- case edit 6 -->';
3582 print '<tr>';
3583 // Qty to ship or shipped
3584 print '<td><input class="qtyl right" name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines[$i]->qty_shipped . '">' . $unit_order . '</td>';
3585 // Warehouse source
3586 print '<td></td>';
3587 // Batch number management
3588 print '<td></td>';
3589 print '</tr>';
3590 }
3591 } else { // both product batch and stock are not activated.
3592 print '<!-- case edit 7 -->';
3593 print '<tr>';
3594 // Qty to ship or shipped
3595 print '<td><input class="qtyl right" name="qtyl' . $line_id . '" id="qtyl' . $line_id . '" type="text" size="4" value="' . $lines[$i]->qty_shipped . '"></td>';
3596 // Warehouse source
3597 print '<td></td>';
3598 // Batch number management
3599 print '<td></td>';
3600 print '</tr>';
3601 }
3602
3603 print '</table></td>';
3604 } else {
3605 // Qty to ship or shipped
3606 print '<td class="linecolqtytoship center">' . $lines[$i]->qty_shipped . ' ' . $unit_order . '</td>';
3607
3608 // Warehouse source
3609 if (isModEnabled('stock')) {
3610 print '<td class="linecolwarehousesource tdoverflowmax200">';
3611 if ($lines[$i]->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {
3612 print '<span class="opacitymedium">(' . $langs->trans("Service") . ')</span>';
3613 } elseif ($lines[$i]->entrepot_id > 0 && $lines[$i]->stockable_product == Product::ENABLED_STOCK) {
3614 $warehouse_id = $lines[$i]->entrepot_id;
3615 if (!isset($conf->cache['warehouse'][$warehouse_id])) {
3616 $warehouse = new Entrepot($db);
3617 $warehouse->fetch($warehouse_id);
3618 $conf->cache['warehouse'][$warehouse_id] = $warehouse;
3619 } else {
3620 $warehouse = $conf->cache['warehouse'][$warehouse_id];
3621 }
3622 print $warehouse->getNomUrl(1);
3623 } elseif (count($lines[$i]->details_entrepot) > 1) {
3624 $detail = '';
3625 foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
3626 $warehouse_id = $detail_entrepot->entrepot_id;
3627 if ($warehouse_id > 0) {
3628 if (!isset($conf->cache['warehouse'][$warehouse_id])) {
3629 $warehouse = new Entrepot($db);
3630 $warehouse->fetch($warehouse_id);
3631 $conf->cache['warehouse'][$warehouse_id] = $warehouse;
3632 } else {
3633 $warehouse = $conf->cache['warehouse'][$warehouse_id];
3634 }
3635 $detail .= $langs->trans("DetailWarehouseFormat", $warehouse->label, $detail_entrepot->qty_shipped) . '<br>';
3636 }
3637 }
3638 print $form->textwithtooltip(img_picto('', 'object_stock') . ' ' . $langs->trans("DetailWarehouseNumber"), $detail);
3639 } elseif (count($lines[$i]->detail_children ?? []) > 1) {
3640 $detail = '';
3641 foreach ($lines[$i]->detail_children as $child_product_id => $child_stock_list) {
3642 foreach ($child_stock_list as $warehouse_id => $total_qty) {
3643 // get product from cache
3644 $child_product_label = '';
3645 if (!isset($conf->cache['product'][$child_product_id])) {
3646 $child_product = new Product($db);
3647 $child_product->fetch($child_product_id);
3648 $conf->cache['product'][$child_product_id] = $child_product;
3649 } else {
3650 $child_product = $conf->cache['product'][$child_product_id];
3651 }
3652 $child_product_label = $child_product->ref . ' ' . $child_product->label;
3653
3654 // get warehouse from cache
3655 if (!isset($conf->cache['warehouse'][$warehouse_id])) {
3656 $child_warehouse = new Entrepot($db);
3657 $child_warehouse->fetch($warehouse_id);
3658 $conf->cache['warehouse'][$warehouse_id] = $child_warehouse;
3659 } else {
3660 $child_warehouse = $conf->cache['warehouse'][$warehouse_id];
3661 }
3662 $detail .= $langs->trans('DetailChildrenFormat', $child_product_label, $child_warehouse->label, price2num($total_qty, 'MS')) . '<br>';
3663 }
3664 }
3665 print $form->textwithtooltip(img_picto('', 'object_stock') . ' ' . $langs->trans('DetailWarehouseNumber'), $detail);
3666 }
3667 print '</td>';
3668 }
3669
3670 // Batch number management
3671 if (isModEnabled('productbatch')) {
3672 if (isset($lines[$i]->detail_batch)) {
3673 print '<!-- Detail of lot -->';
3674 print '<td class="linecolbatch">';
3675 if ($lines[$i]->product_tobatch) {
3676 $detail = '';
3677 foreach ($lines[$i]->detail_batch as $dbatch) { // $dbatch is instance of ExpeditionLineBatch
3678 $detail .= $langs->trans("Batch") . ': ' . $dbatch->batch;
3679 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
3680 $detail .= ' - ' . $langs->trans("SellByDate") . ': ' . dol_print_date($dbatch->sellby, "day");
3681 }
3682 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
3683 $detail .= ' - ' . $langs->trans("EatByDate") . ': ' . dol_print_date($dbatch->eatby, "day");
3684 }
3685 $detail .= ' - ' . $langs->trans("Qty") . ': ' . $dbatch->qty;
3686 $detail .= '<br>';
3687 }
3688 print $form->textwithtooltip(img_picto('', 'object_barcode') . ' ' . $langs->trans("DetailBatchNumber"), $detail);
3689 } else {
3690 print $langs->trans("NA");
3691 }
3692 print '</td>';
3693 } else {
3694 print '<td class="linecolbatch" ></td>';
3695 }
3696 }
3697 }
3698
3699 // Weight
3700 print '<td class="center linecolweight">';
3701 if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
3702 print $lines[$i]->weight * $lines[$i]->qty_shipped . ' ' . measuringUnitString(0, "weight", $lines[$i]->weight_units);
3703 } else {
3704 print '&nbsp;';
3705 }
3706 print '</td>';
3707
3708 // Volume
3709 print '<td class="center linecolvolume">';
3710 if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
3711 print $lines[$i]->volume * $lines[$i]->qty_shipped . ' ' . measuringUnitString(0, "volume", $lines[$i]->volume_units);
3712 } else {
3713 print '&nbsp;';
3714 }
3715 print '</td>';
3716
3717 // Size
3718 //print '<td class="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units).'</td>';
3719
3720 $showmovecol = ($object->status == Expedition::STATUS_DRAFT);
3721
3722 if ($action == 'editline' && $lines[$i]->id == $line_id) {
3723 print '<td class="center" colspan="2" valign="middle">';
3724 print '<input type="submit" class="button button-save" id="savelinebutton marginbottomonly" name="save" value="' . $langs->trans("Save") . '"><br>';
3725 print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="cancel" value="' . $langs->trans("Cancel") . '"><br>';
3726 print '</td>';
3727 if ($showmovecol) {
3728 print '<td class="linecolmove tdlineupdown center"></td>';
3729 }
3730 } elseif ($showmovecol) {
3731 $edit_url = $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=editline&token=' . newToken() . '&lineid=' . $lines[$i]->id;
3732 if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) {
3733 $product_id = $lines[$i]->fk_product;
3734 if (!isset($conf->cache['product'][$product_id])) {
3735 $product = new Product($db);
3736 $product->fetch($product_id);
3737 $conf->cache['product'][$product_id] = $product;
3738 } else {
3739 $product = $conf->cache['product'][$product_id];
3740 }
3741
3742 if ($product->hasFatherOrChild(1)) {
3743 $edit_url = dol_buildpath('/expedition/dispatch.php?id=' . $object->id, 1);
3744 }
3745 }
3746
3747 // edit-delete buttons
3748 print '<td class="linecoledit center">';
3749 print '<a class="editfielda reposition" href="' . $edit_url . '">' . img_edit() . '</a>';
3750 print '</td>';
3751 print '<td class="linecoldelete" width="10">';
3752 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=deleteline&token=' . newToken() . '&lineid=' . $lines[$i]->id . '">' . img_delete() . '</a>';
3753 print '</td>';
3754 print '<td class="linecolmove tdlineupdown center">';
3755 if ($usercancreate && $num_prod > 1) {
3756 if ($i > 0) {
3757 print '<a class="lineupdown" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=up&token=' . newToken() . '&rowid=' . $lines[$i]->id . '">' . img_up('default', 0, 'imgupforline') . '</a>';
3758 }
3759 if ($i < $num_prod - 1) {
3760 print '<a class="lineupdown" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=down&token=' . newToken() . '&rowid=' . $lines[$i]->id . '">' . img_down('default', 0, 'imgdownforline') . '</a>';
3761 }
3762 }
3763 print '</td>';
3764 // Display lines extrafields
3765 if (!empty($rowExtrafieldsStart)) {
3766 print $rowExtrafieldsStart;
3767 print $rowExtrafieldsView;
3768 print $rowEnd;
3769 }
3770 }
3771 print "</tr>";
3772 } elseif (empty($reshook) && $lines[$i]->product_type == "9") {
3773 $objectsrc = new OrderLine($db);
3774 $objectsrc->fetch($lines[$i]->origin_line_id);
3775 if ($objectsrc->special_code == SUBTOTALS_SPECIAL_CODE) {
3776 $line = $lines[$i];
3777 require dol_buildpath('/core/tpl/subtotal_expedition_view.tpl.php');
3778 }
3779 }
3780 }
3781 // TODO Show also lines ordered but not delivered
3782 if (empty($num_prod)) {
3783 print '<tr><td colspan="8"><span class="opacitymedium">' . $langs->trans("NoLineGoOnTabToAddSome", $langs->transnoentitiesnoconv("ShipmentDistribution")) . '</span></td></tr>';
3784 }
3785
3786 print '</tbody>';
3787 print "</table>\n";
3788 print '</div>';
3789 if ($action == 'editline') {
3790 print "</form>\n";
3791 }
3792
3793 $object->fetchObjectLinked($object->id, $object->element);
3794 }
3795
3796 /*
3797 * Boutons actions
3798 */
3799
3800 if (($user->socid == 0) && ($action != 'presend')) {
3801 print '<div class="tabsAction">';
3802
3803 $parameters = array();
3804 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
3805 // modified by hook
3806 if (empty($reshook)) {
3807 if ($object->status == Expedition::STATUS_DRAFT && $num_prod > 0) {
3808 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'creer'))
3809 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'shipping_advance', 'validate'))
3810 ) {
3811 print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"] . '?action=valid&token=' . newToken() . '&id=' . $object->id, '');
3812 } else {
3813 print dolGetButtonAction($langs->trans('NotAllowed'), $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF'] . '#', '', false);
3814 }
3815 }
3816
3817 // 0=draft, 1=validated/delivered, 2=closed/delivered
3818 if ($object->status == Expedition::STATUS_VALIDATED && !getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) {
3819 if ($user->hasRight('expedition', 'creer')) {
3820 print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"] . '?action=setdraft&token=' . newToken() . '&id=' . $object->id, '');
3821 }
3822 }
3823 if ($object->status == Expedition::STATUS_CLOSED) {
3824 if ($user->hasRight('expedition', 'creer')) {
3825 print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"] . '?action=reopen&token=' . newToken() . '&id=' . $object->id, '');
3826 }
3827 }
3828
3829 // Send
3830 if (empty($user->socid)) {
3831 if ($object->status > 0) {
3832 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('expedition', 'shipping_advance', 'send')) {
3833 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"] . '?action=presend&token=' . newToken() . '&id=' . $object->id . '&mode=init#formmailbeforetitle', '');
3834 } else {
3835 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER['PHP_SELF'] . '#', '', false);
3836 }
3837 }
3838 }
3839
3840 // This is just to generate a delivery receipt when option to do this is on
3841 //var_dump($object->linkedObjectsIds['delivery']);
3842 if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && ($object->status == Expedition::STATUS_VALIDATED || $object->status == Expedition::STATUS_CLOSED) && $user->hasRight('expedition', 'delivery', 'creer') && empty($object->linkedObjectsIds['delivery'])) {
3843 print dolGetButtonAction('', $langs->trans('CreateDeliveryOrder'), 'default', $_SERVER["PHP_SELF"] . '?action=create_delivery&token=' . newToken() . '&id=' . $object->id, '');
3844 }
3845
3846 // Sign (to set to status "Signed" without using the online signature page)
3847 if ($object->status > Expedition::STATUS_DRAFT) {
3848 if ($object->signed_status != Expedition::$SIGNED_STATUSES['STATUS_SIGNED_ALL']) {
3849 print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=sign&token=' . newToken() . '">' . $langs->trans("SignShipping") . '</a></div>';
3850 } else {
3851 print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=unsign&token=' . newToken() . '">' . $langs->trans("UnsignShipping") . '</a></div>';
3852 }
3853 }
3854
3855 // Create bill
3856 if (isModEnabled('invoice') && ($object->status == Expedition::STATUS_VALIDATED || $object->status == Expedition::STATUS_CLOSED)) {
3857 if ($user->hasRight('facture', 'creer')) {
3858 if (getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT') !== '0') {
3859 print dolGetButtonAction('', $langs->trans('CreateBill'), 'default', DOL_URL_ROOT . '/compta/facture/card.php?action=create&origin=' . $object->element . '&originid=' . $object->id . '&socid=' . $object->socid, '');
3860 }
3861 }
3862 }
3863
3864 // Set Billed and Closed
3865 if ($object->status == Expedition::STATUS_VALIDATED) {
3866 if ($user->hasRight('expedition', 'creer') && $object->status > 0) {
3867 if (!$object->billed && getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT') !== '0') {
3868 print dolGetButtonAction('', $langs->trans('ClassifyBilled'), 'default', $_SERVER["PHP_SELF"] . '?action=classifybilled&token=' . newToken() . '&id=' . $object->id, '');
3869 }
3870 print dolGetButtonAction('', $langs->trans("Close"), 'default', $_SERVER["PHP_SELF"] . '?action=classifyclosed&token=' . newToken() . '&id=' . $object->id, '');
3871 }
3872 }
3873
3874 // Cancel
3875 if ($object->status == Expedition::STATUS_VALIDATED) {
3876 if ($user->hasRight('expedition', 'creer')) {
3877 print dolGetButtonAction('', $langs->trans('Cancel'), 'danger', $_SERVER["PHP_SELF"] . '?action=cancel&token=' . newToken() . '&id=' . $object->id . '&mode=init#formmailbeforetitle', '');
3878 }
3879 }
3880
3881 // Delete
3882 if ($user->hasRight('expedition', 'supprimer')) {
3883 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"] . '?action=delete&token=' . newToken() . '&id=' . $object->id, '');
3884 }
3885 }
3886
3887 print '</div>';
3888 }
3889
3890
3891 /*
3892 * Documents generated
3893 */
3894
3895 if ($action != 'presend' && $action != 'editline') {
3896 print '<div class="fichecenter"><div class="fichehalfleft">';
3897
3898 $objectref = dol_sanitizeFileName((string) $object->ref);
3899 $filedir = $conf->expedition->dir_output . "/sending/" . $objectref;
3900
3901 $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
3902
3903 $genallowed = $user->hasRight('expedition', 'lire');
3904 $delallowed = $user->hasRight('expedition', 'creer');
3905
3906 print $formfile->showdocuments('expedition', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
3907
3908
3909 // Show links to link elements
3910 $tmparray = $form->showLinkToObjectBlock($object, array(), array('shipping'), 1);
3911 $linktoelem = $tmparray['linktoelem'];
3912 $htmltoenteralink = $tmparray['htmltoenteralink'];
3913 print $htmltoenteralink;
3914
3915 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
3916
3917 // Show online signature link
3918 $useonlinesignature = getDolGlobalInt('EXPEDITION_ALLOW_ONLINESIGN');
3919
3920 if ($object->statut != Expedition::STATUS_DRAFT && $useonlinesignature) {
3921 print '<br><!-- Link to sign -->';
3922 require_once DOL_DOCUMENT_ROOT . '/core/lib/signature.lib.php';
3923 print showOnlineSignatureUrl('expedition', $object->ref, $object) . '<br>';
3924 }
3925
3926 print '</div><div class="fichehalfright">';
3927
3928
3929 // List of actions on element
3930 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
3931 $formactions = new FormActions($db);
3932
3933 //button to go to messaging from the events box
3934 $MAXEVENT = 10;
3935 $morehtmlcenter = dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT . '/expedition/messaging.php?id=' . $object->id);
3936
3937 $somethingshown = $formactions->showactions($object, 'shipping', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter);
3938 print '</div></div>';
3939 }
3940
3941
3942 /*
3943 * Action presend
3944 */
3945
3946 //Select mail models is same action as presend
3947 if (GETPOST('modelselected')) {
3948 $action = 'presend';
3949 }
3950
3951 // Presend form
3952 $modelmail = 'shipping_send';
3953 $defaulttopic = 'SendShippingRef';
3954 $diroutput = $conf->expedition->dir_output . '/sending';
3955 $trackid = 'shi' . $object->id;
3956
3957 include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php';
3958}
3959
3960// End of page
3961llxFooter();
3962$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage customers orders.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
const STATUS_DRAFT
Draft status.
const STATUS_CANCELED
Canceled status.
const STATUS_CLOSED
Closed status -> parcel was received by customer / end of process prev status : validated or shipment...
const STATUS_VALIDATED
Validated status -> parcel is ready to be sent prev status : draft next status : closed or shipment_i...
Class to manage lines of shipment.
CRUD class for batch number management within shipment.
Class to manage building of HTML components.
Class to offer components to list and upload files.
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 manage building of HTML components.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage the table of subscription to notifications.
Class to manage order lines.
Class ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage products or services.
const DISABLED_STOCK
Stockable product.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Manage record for batch number management.
Class with list of lots and properties.
Class to manage projects.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
print_date_range($date_start, $date_end, $format='', $outputlangs=null)
Format output for start and end date.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
shipping_prepare_head($object)
Prepare array with list of tabs.