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