dolibarr 24.0.0-beta
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
5 * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
9 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2025-2026 MDW <mdeweerd@users.noreply.github.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
47if (isModEnabled("product") || isModEnabled("service")) {
48 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
49}
50if (isModEnabled('shipping')) {
51 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
52}
53if (isModEnabled('stock')) {
54 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
55}
56if (isModEnabled('project')) {
57 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
58 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
59}
60
61// Load translation files required by the page
62$langs->loadLangs(array('bills', 'orders', 'sendings'));
63
64if (isModEnabled('incoterm')) {
65 $langs->load('incoterm');
66}
67
68$action = GETPOST('action', 'aZ09');
69$confirm = GETPOST('confirm', 'alpha');
70$backtopage = GETPOST('backtopage', 'alpha');
71$id = GETPOSTINT('id');
72
73
74// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
75$hookmanager->initHooks(array('deliverycard', 'globalcard'));
76
77$object = new Delivery($db);
78
79// fetch optionals attributes and labels
80$extrafields->fetch_name_optionals_label($object->table_element);
81
82// fetch optionals attributes lines and labels
83$extrafields->fetch_name_optionals_label($object->table_element_line);
84
85// Load object. Make an object->fetch
86include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
87
88$error = 0;
89
90// Security check
91if ($user->socid) {
92 $socid = $user->socid;
93}
94$result = restrictedArea($user, 'expedition', $id, 'delivery', 'delivery');
95
96$permissiontoread = $user->hasRight('expedition', 'delivery', 'read');
97$permissiontoadd = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
98$permissiontodelete = $user->hasRight('expedition', 'delivery', 'supprimer') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
99$permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery_advance', 'validate')));
100$permissionnote = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_setnotes.inc.php
101$permissiondellink = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_dellink.inc.php
102$permissiontoeditextra = $permissiontoadd;
103if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
104 // For action 'update_extras', is there a specific permission set for the attribute to update
105 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
106}
107$permissiontoeditextraline = $permissiontoadd;
108if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element_line]['perms'][GETPOST('attribute', 'aZ09')])) {
109 // For action 'update_extras', is there a specific permission set for the attribute to update
110 $permissiontoeditextraline = dol_eval((string) $extrafields->attributes[$object->table_element_line]['perms'][GETPOST('attribute', 'aZ09')]);
111}
112
113
114/*
115 * Actions
116 */
117
118$parameters = array();
119$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
120// Delete Link
121$permissiondellink = $user->hasRight('expedition', 'delivery', 'supprimer'); // Used by the include of actions_dellink.inc.php
122include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
123
124if ($action == 'add' && $permissiontoadd) {
125 $array_options = array();
126 $db->begin();
127
128 $object->date_delivery = dol_now();
129 $object->note_private = GETPOST("note", 'restricthtml');
130 $object->note = $object->note_private; // deprecated
131 $object->commande_id = GETPOSTINT("commande_id");
132 $object->fk_incoterms = GETPOSTINT('incoterm_id');
133 // $object->entrepot_id = GETPOST('entrepot_id', 'int'); entrepot_id does not exists on delivery note, only on shipment document
134
135 // We loop on each line of order to complete object delivery with qty to delivery
136 $commande = new Commande($db);
137 $commande->fetch($object->commande_id);
138 $commande->fetch_lines();
139
140 $num = count($commande->lines);
141 for ($i = 0; $i < $num; $i++) {
142 $qty = "qtyl".$i;
143 $idl = "idl".$i;
144 $qtytouse = price2num(GETPOSTFLOAT($qty));
145 if ($qtytouse > 0) {
146 $object->addline(GETPOSTINT($idl), (float) price2num($qtytouse), $array_options);
147 }
148 }
149
150 $ret = $object->create($user);
151 if ($ret > 0) {
152 $db->commit();
153 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
154 exit;
155 } else {
156 setEventMessages($object->error, $object->errors, 'errors');
157 $db->rollback();
158
159 $action = 'create';
160 }
161} elseif ($action == 'confirm_valid' && $confirm == 'yes' && $permissiontovalidate) {
162 $result = $object->valid($user);
163
164 // Define output language
165 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
166 $outputlangs = $langs;
167 $newlang = '';
168 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
169 $newlang = GETPOST('lang_id', 'aZ09');
170 }
171 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
172 $newlang = $object->thirdparty->default_lang;
173 }
174 if (!empty($newlang)) {
175 $outputlangs = new Translate("", $conf);
176 $outputlangs->setDefaultLang($newlang);
177 }
178 $model = $object->model_pdf;
179 $ret = $object->fetch($id); // Reload to get new record
180
181 // Phan does not use suggested tyhpe for $hide*, ignore: @phan-suppress-next-line PhanTypeMismatchArgument
182 $result = $object->generateDocument($model, $outputlangs, 0, 0, 0);
183 if ($result < 0) {
184 dol_print_error($db, $object->error, $object->errors);
185 }
186 }
187}
188
189if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
190 $db->begin();
191 $result = $object->delete($user);
192
193 if ($result > 0) {
194 $db->commit();
195 if (!empty($backtopage)) {
196 header("Location: ".$backtopage);
197 } else {
198 header("Location: ".DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1');
199 }
200 exit;
201 } else {
202 $db->rollback();
203 }
204}
205
206if ($action == 'setdate_delivery' && $permissiontoadd) {
207 $datedelivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
208 $result = $object->setDeliveryDate($user, $datedelivery);
209 if ($result < 0) {
210 $mesg = '<div class="error">'.$object->error.'</div>';
211 }
212} elseif ($action == 'set_incoterms' && isModEnabled('incoterm') && $permissiontoadd) {
213 // Set incoterm
214 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
215}
216
217// Update extrafields
218if ($action == 'update_extras' && $permissiontoeditextra) {
219 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
220
221 $attribute_name = GETPOST('attribute', 'aZ09');
222
223 // Fill array 'array_options' with data from update form
224 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
225 if ($ret < 0) {
226 $error++;
227 }
228
229 if (!$error) {
230 $result = $object->updateExtraField($attribute_name, 'DELIVERY_MODIFY');
231 if ($result < 0) {
232 setEventMessages($object->error, $object->errors, 'errors');
233 $error++;
234 }
235 }
236
237 if ($error) {
238 $action = 'edit_extras';
239 }
240}
241
242// Extrafields line
243if ($action == 'update_extras_line' && $permissiontoeditextraline) {
244 $array_options = array();
245 $num = count($object->lines);
246
247 for ($i = 0; $i < $num; $i++) {
248 // Extrafields
249 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
250 $array_options[$i] = $extrafields->getOptionalsFromPost($extralabelsline, (string) $i);
251 // Unset extrafield
252 if (is_array($extralabelsline)) {
253 // Get extra fields
254 foreach ($extralabelsline as $key => $value) {
255 unset($_POST["options_".$key]);
256 }
257 }
258
259 $ret = $object->update_line($object->lines[$i]->id, $array_options[$i]); // extrafields update
260 if ($ret < 0) {
261 $mesg = '<div class="error">'.$object->error.'</div>';
262 $error++;
263 }
264 }
265}
266
267
268// Actions to build doc
269$upload_dir = $conf->expedition->dir_output.'/receipt';
270include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
271// Provided by include of ...builddoc...:
272'
273@phan-var-force int<0,1> $hidedetails
274@phan-var-force int<0,1> $hidedesc
275@phan-var-force int<0,1> $hideref
276';
277
278include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
279
280// Actions to send emails
281
282$triggersendname = 'DELIVERY_SENTBYMAIL';
283$paramname = 'id';
284$autocopy = 'MAIN_MAIL_AUTOCOPY_DELIVERY_TO';
285$mode = 'emailfromdelivery';
286$trackid = 'del' . $object->id;
287include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
288
289
290/*
291 * View
292 */
293
294$title = $langs->trans('Delivery');
295
296llxHeader('', $title, 'Livraison', '', 0, 0, '', '', '', 'mod-delivery page-card');
297
298$form = new Form($db);
299$formfile = new FormFile($db);
300$objectsrc = null;
301
302if ($action == 'create') {
303 // Create. Seems to no be used
304} else {
305 // View
306 if ($object->id > 0) {
307 // Origin of a 'livraison' (delivery receipt) is ALWAYS 'expedition' (shipment).
308 // However, origin of shipment in future may differs (commande, proposal, ...)
309 $expedition = new Expedition($db);
310 $result = $expedition->fetch($object->origin_id);
311
312 $typeobject = $expedition->origin; // example: commande
313 if ($object->origin_id > 0) {
314 $object->fetch_origin();
315 }
316
317 if ($object->id > 0) {
318 $soc = new Societe($db);
319 $soc->fetch($object->socid);
320
321 $head = delivery_prepare_head($object);
322
323 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
324 print '<input type="hidden" name="token" value="'.newToken().'">';
325 print '<input type="hidden" name="action" value="update_extras_line">';
326 print '<input type="hidden" name="origin" value="'.$object->origin.'">';
327 print '<input type="hidden" name="id" value="'.$object->id.'">';
328 print '<input type="hidden" name="ref" value="'.$object->ref.'">';
329
330 print dol_get_fiche_head($head, 'delivery', $langs->trans("Shipment"), -1, 'dolly');
331
332 /*
333 * Confirmation de la suppression
334 *
335 */
336 if ($action == 'delete') {
337 $expedition_id = GETPOST("expid");
338 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&expid='.$expedition_id.'&backtopage='.urlencode($backtopage), $langs->trans("DeleteDeliveryReceipt"), $langs->trans("DeleteDeliveryReceiptConfirm", $object->ref), 'confirm_delete', '', '', 1);
339 }
340
341 /*
342 * Confirmation de la validation
343 */
344 if ($action == 'valid') {
345 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidateDeliveryReceipt"), $langs->trans("ValidateDeliveryReceiptConfirm", $object->ref), 'confirm_valid', '', '', 1);
346 }
347
348
349 /*
350 * Delivery
351 */
352
353 if ($typeobject == 'commande' && $expedition->origin_id > 0 && isModEnabled('order')) {
354 $objectsrc = new Commande($db);
355 $objectsrc->fetch($expedition->origin_id);
356 }
357 if ($typeobject == 'propal' && $expedition->origin_id > 0 && isModEnabled("propal")) {
358 $objectsrc = new Propal($db);
359 $objectsrc->fetch($expedition->origin_id);
360 }
361
362 // Shipment card
363 $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
364
365 $morehtmlref = '<div class="refidno">';
366 // Ref customer shipment
367 $morehtmlref .= $form->editfieldkey("RefCustomer", '', $expedition->ref_customer, $expedition, $user->hasRight('expedition', 'creer'), 'string', '', 0, 1);
368 $morehtmlref .= $form->editfieldval("RefCustomer", '', $expedition->ref_customer, $expedition, $user->hasRight('expedition', 'creer'), 'string'.(getDolGlobalString('THIRDPARTY_REF_INPUT_SIZE') ? ':' . getDolGlobalString('THIRDPARTY_REF_INPUT_SIZE') : ''), '', null, null, '', 1);
369 $morehtmlref .= '<br>'.$langs->trans("RefDeliveryReceipt").' : '.$object->ref;
370 // Thirdparty
371 $morehtmlref .= '<br>'.$expedition->thirdparty->getNomUrl(1);
372 // Project
373 if (isModEnabled('project') && $objectsrc !== null) {
374 $langs->load("projects");
375 $morehtmlref .= '<br>';
376 if (0) { // @phpstan-ignore-line Do not change on shipment
377 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
378 if ($action != 'classify') {
379 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
380 }
381 $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');
382 } else {
383 if (!empty($objectsrc->fk_project)) {
384 $proj = new Project($db);
385 $proj->fetch($objectsrc->fk_project);
386 $morehtmlref .= $proj->getNomUrl(1);
387 if ($proj->title) {
388 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
389 }
390 }
391 }
392 }
393 $morehtmlref .= '</div>';
394
395 $morehtmlstatus = $langs->trans("StatusReceipt").' : '.$object->getLibStatut(6).'<br><br class="small">';
396
397 dol_banner_tab($expedition, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
398
399
400 print '<div class="fichecenter">';
401 print '<div class="underbanner clearboth"></div>';
402
403 print '<table class="border tableforfield" width="100%">';
404
405 // Shipment
406 /*
407 if (($object->origin == 'shipment' || $object->origin == 'expedition') && $object->origin_id > 0)
408 {
409 $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
410
411 // Ref
412 print '<tr><td width="20%">'.$langs->trans("RefSending").'</td>';
413 print '<td colspan="3">';
414 // Nav is hidden because on a delivery receipt of a shipment, if we go on next shipment, we may find no tab (a shipment may not have delivery receipt yet)
415 //print $form->showrefnav($expedition, 'refshipment', $linkback, 1, 'ref', 'ref');
416 print $form->showrefnav($expedition, 'refshipment', $linkback, 0, 'ref', 'ref');
417 print '</td></tr>';
418 }
419
420 // Ref
421 print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
422 print '<td colspan="3">';
423 print $object->ref;
424 print '</td></tr>';
425
426 // Client
427 print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
428 print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
429 print "</tr>";
430 */
431
432 // Document origine
433 if ($typeobject == 'commande' && $expedition->origin_id && isModEnabled('order')) {
434 print '<tr><td class="titlefield">'.$langs->trans("RefOrder").'</td>';
435 $order = new Commande($db);
436 $order->fetch($expedition->origin_id);
437 print '<td colspan="3">';
438 print $order->getNomUrl(1, 'commande');
439 print "</td>\n";
440 print '</tr>';
441 }
442 if ($typeobject == 'propal' && $expedition->origin_id && isModEnabled("propal")) {
443 $propal = new Propal($db);
444 $propal->fetch($expedition->origin_id);
445 print '<tr><td class="titlefield">'.$langs->trans("RefProposal").'</td>';
446 print '<td colspan="3">';
447 print $propal->getNomUrl(1, 'expedition');
448 print "</td>\n";
449 print '</tr>';
450 }
451
452 // Date
453 print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
454 print '<td colspan="3">'.dol_print_date($object->date_creation, 'dayhour')."</td>\n";
455 print '</tr>';
456
457 // Date delivery real / Received
458 print '<tr><td height="10">';
459 print '<table class="nobordernopadding" width="100%"><tr><td>';
460 print $langs->trans('DateReceived');
461 print '</td>';
462
463 if ($action != 'editdate_delivery') {
464 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_delivery&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
465 }
466 print '</tr></table>';
467 print '</td><td colspan="2">';
468 if ($action == 'editdate_delivery') {
469 print '<form name="setdate_delivery" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
470 print '<input type="hidden" name="token" value="'.newToken().'">';
471 print '<input type="hidden" name="action" value="setdate_delivery">';
472 print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, 0, "setdate_delivery", 1, 1);
473 print '<input type="submit" class="button smallpaddingimp button-edit" value="'.$langs->trans('Modify').'">';
474 print '</form>';
475 } else {
476 print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
477 }
478 print '</td>';
479 print '</tr>';
480
481 // Incoterms
482 if (isModEnabled('incoterm')) {
483 print '<tr><td>';
484 print '<table class="centpercent nobordernopadding"><tr><td>';
485 print $langs->trans('IncotermLabel');
486 print '<td><td class="right">';
487 if ($user->hasRight('expedition', 'delivery', 'creer')) {
488 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
489 } else {
490 print '&nbsp;';
491 }
492 print '</td></tr></table>';
493 print '</td>';
494 print '<td colspan="3">';
495 if ($action != 'editincoterm') {
496 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
497 } else {
498 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
499 }
500 print '</td></tr>';
501 }
502
503 /* A delivery note should be just more properties of a shipment, so notes are on shipment
504 // Note Public
505 print '<tr><td>'.$langs->trans("NotePublic").'</td>';
506 print '<td colspan="3">';
507 print dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_public));
508 print "</td></tr>";
509
510 // Note Private
511 print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
512 print '<td colspan="3">';
513 print dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_private));
514 print "</td></tr>";
515 */
516
517 // Statut
518 /*print '<tr><td>'.$langs->trans("Status").'</td>';
519 print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
520 print '</tr>';*/
521
522
523 if (!getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && isModEnabled('stock')) {
524 // Entrepot
525 $entrepot = new Entrepot($db);
526 $entrepot->fetch($expedition->entrepot_id);
527 print '<tr><td width="20%">'.$langs->trans("Warehouse").'</td>';
528 print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/product/stock/card.php?id='.$entrepot->id.'">'.$entrepot->label.'</a></td>';
529 print '</tr>';
530 }
531
532 // Other attributes
533 if ($action == 'create_delivery') {
534 // copy from expedition
535 $extrafields->fetch_name_optionals_label($expedition->table_element);
536 if ($expedition->fetch_optionals() > 0) {
537 $object->array_options = array_merge($object->array_options, $expedition->array_options);
538 }
539 }
540 $cols = 2;
541 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
542
543 print "</table><br>\n";
544
545 print '</div>';
546
547 /*
548 * Products lines
549 */
550
551 $num_prod = count($object->lines);
552 $i = 0;
553 $total = 0;
554
555 print '<table class="noborder centpercent">';
556
557 if ($num_prod) {
558 $i = 0;
559
560 print '<tr class="liste_titre">';
561 print '<td>'.$langs->trans("Products").'</td>';
562 print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
563 print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
564 print "</tr>\n";
565 }
566 while ($i < $num_prod) {
567 $parameters = array('i' => $i, 'line' => $object->lines[$i], 'num' => $num_prod);
568 $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);
569 if ($reshook < 0) {
570 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
571 }
572
573 if (empty($reshook)) {
574 print '<tr class="oddeven">';
575 if ($object->lines[$i]->fk_product > 0) {
576 $product = new Product($db);
577 $product->fetch($object->lines[$i]->fk_product);
578
579 // Define output language
580 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
581 $outputlangs = $langs;
582 $newlang = '';
583 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
584 $newlang = GETPOST('lang_id', 'aZ09');
585 }
586 if (empty($newlang)) {
587 $newlang = $object->thirdparty->default_lang;
588 }
589 if (!empty($newlang)) {
590 $outputlangs = new Translate("", $conf);
591 $outputlangs->setDefaultLang($newlang);
592 }
593
594 $label = (!empty($product->multilangs[$outputlangs->defaultlang]["label"])) ? $product->multilangs[$outputlangs->defaultlang]["label"] : $object->lines[$i]->product_label;
595 } else {
596 $label = (!empty($object->lines[$i]->label) ? $object->lines[$i]->label : $object->lines[$i]->product_label);
597 }
598
599 print '<td>';
600
601 // Show product line
602 $text = '<a href="'.DOL_URL_ROOT.'/product/card.php?id='.$object->lines[$i]->fk_product.'">';
603 if ($object->lines[$i]->fk_product_type == 1) {
604 $text .= img_object($langs->trans('ShowService'), 'service');
605 } else {
606 $text .= img_object($langs->trans('ShowProduct'), 'product');
607 }
608 $text .= ' '.$object->lines[$i]->product_ref.'</a>';
609 $text .= ' - '.$label;
610 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($object->lines[$i]->description));
611 //print $description;
612 print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
613 //print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
614 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
615 print (!empty($object->lines[$i]->description) && $object->lines[$i]->description != $object->lines[$i]->product_label) ? '<br>'.dol_htmlentitiesbr($object->lines[$i]->description) : '';
616 }
617 } else {
618 print "<td>";
619 if ($object->lines[$i]->fk_product_type == 1) {
620 $text = img_object($langs->trans('Service'), 'service');
621 } else {
622 $text = img_object($langs->trans('Product'), 'product');
623 }
624
625 if (!empty($object->lines[$i]->label)) {
626 $text .= ' <strong>'.$object->lines[$i]->label.'</strong>';
627 print $form->textwithtooltip($text, $object->lines[$i]->description, 3, 0, '', (string) $i);
628 } else {
629 print $text.' '.nl2br($object->lines[$i]->description);
630 }
631
632 //print_date_range($objp->date_start, $objp->date_end);
633 print "</td>\n";
634 }
635
636 print '<td class="center">'.$object->lines[$i]->qty_asked.'</td>';
637 print '<td class="center">'.$object->lines[$i]->qty_shipped.'</td>';
638
639 print "</tr>";
640
641 // Display lines extrafields
642 //if (!empty($extrafields)) {
643 $colspan = 2;
644 $mode = ($object->statut == 0) ? 'edit' : 'view';
645
646 $object->lines[$i]->fetch_optionals();
647
648 if ($action == 'create_delivery') {
649 $srcLine = new ExpeditionLigne($db);
650
651 $extrafields->fetch_name_optionals_label($srcLine->table_element);
652 $srcLine->id = $expedition->lines[$i]->id;
653 $srcLine->fetch_optionals();
654
655 $object->lines[$i]->array_options = array_merge($object->lines[$i]->array_options, $srcLine->array_options);
656 } else {
657 $srcLine = new DeliveryLine($db);
658 $extrafields->fetch_name_optionals_label($srcLine->table_element);
659 }
660 print $object->lines[$i]->showOptionals($extrafields, $mode, array('style' => 'class="oddeven"', 'colspan' => $colspan), '');
661 //}
662 }
663
664 $i++;
665 }
666
667 print "</table>\n";
668
669 print dol_get_fiche_end();
670
671 //if ($object->statut == 0) // only if draft
672 // print $form->buttonsSaveCancel("Save", '');
673
674 print '</form>';
675
676
677 /*
678 * Boutons actions
679 */
680
681 if ($user->socid == 0) {
682 print '<div class="tabsAction">';
683
684 if ($object->statut == 0 && $num_prod > 0) {
685 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery', 'creer'))
686 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery_advance', 'validate'))) {
687 print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=valid&token='.newToken().'&id='.$object->id, '');
688 }
689 }
690 if ($user->hasRight('expedition', 'delivery', 'supprimer') && $action != 'presend') {
691 if ($object->status == Delivery::STATUS_VALIDATED && $action != 'presend' && $expedition->status == Expedition::STATUS_VALIDATED) {
692 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');
693 }
694 if (getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION')) {
695 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&expid='.$object->origin_id.'&action=delete&token='.newToken().'&backtopage='.urlencode(DOL_URL_ROOT.'/expedition/card.php?id='.$object->origin_id), '');
696 } else {
697 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
698 }
699 }
700
701 print '</div>';
702 }
703 print "\n";
704
705 print '<div class="fichecenter"><div class="fichehalfleft">';
706
707 /*
708 * Documents generated
709 */
710 if ($action != 'presend') {
711 $objectref = dol_sanitizeFileName((string) $object->ref);
712 $filedir = $conf->expedition->dir_output."/receipt/".$objectref;
713 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
714
715 $genallowed = $user->hasRight('expedition', 'delivery', 'lire');
716 $delallowed = $user->hasRight('expedition', 'delivery', 'creer');
717
718 print $formfile->showdocuments('delivery', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
719
720 /*
721 * Linked object block (of linked shipment)
722 */
723
724 // Show links to link elements
725 print '</div><div class="fichehalfright">';
726
727 // List of actions on element
728 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
729
730 //$tmparray = $form->showLinkToObjectBlock($object, null, array('order'), 1);
731 $somethingshown = $form->showLinkedObjectBlock($object, '');
732 }
733
734
735 print '</div><div class="fichehalfright">';
736
737 // Nothing on right
738
739 print '</div></div>';
740 } else {
741 /* Expedition non trouvee */
742 print "Expedition inexistante ou access refuse";
743 }
744 } else {
745 /* Expedition non trouvee */
746 print "Expedition inexistante ou access refuse";
747 }
748
749 /*
750 * Action presend
751 */
752 //Select mail models is same action as presend
753 if (GETPOST('modelselected')) {
754 $action = 'presend';
755 }
756
757 // Presend form
758 $modelmail = 'delivery_send';
759 $defaulttopic = 'SendDeliveryRef';
760 $diroutput = $conf->expedition->dir_output . '/receipt';
761 $trackid = 'del' . $object->id;
762
763 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
764}
765
766// End of page
767llxFooter();
768$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage customers orders.
Class to manage receptions.
Management class of delivery note lines.
Class to manage warehouses.
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.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage products or services.
Class to manage projects.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
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.
delivery_prepare_head($object)
Prepare array with list of tabs.