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