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