dolibarr 25.0.0-alpha
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 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
192 $result = $object->delete($user);
193
194 if ($result > 0) {
195 $db->commit();
196 if (!empty($backtopage)) {
197 header("Location: ".$backtopage);
198 } else {
199 header("Location: ".DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1');
200 }
201 exit;
202 } else {
203 $db->rollback();
204 setEventMessages($object->error, $object->errors, 'errors');
205 }
206}
207
208if ($action == 'setdate_delivery' && $permissiontoadd) {
209 $datedelivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
210 $result = $object->setDeliveryDate($user, $datedelivery);
211 if ($result < 0) {
212 $mesg = '<div class="error">'.$object->error.'</div>';
213 }
214} elseif ($action == 'set_incoterms' && isModEnabled('incoterm') && $permissiontoadd) {
215 // Set incoterm
216 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
217}
218
219// Update extrafields
220if ($action == 'update_extras' && $permissiontoeditextra) {
221 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
222
223 $attribute_name = GETPOST('attribute', 'aZ09');
224
225 // Fill array 'array_options' with data from update form
226 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
227 if ($ret < 0) {
228 $error++;
229 }
230
231 if (!$error) {
232 $result = $object->updateExtraField($attribute_name, 'DELIVERY_MODIFY');
233 if ($result < 0) {
234 setEventMessages($object->error, $object->errors, 'errors');
235 $error++;
236 }
237 }
238
239 if ($error) {
240 $action = 'edit_extras';
241 }
242}
243
244// Extrafields line
245if ($action == 'update_extras_line' && $permissiontoeditextraline) {
246 $array_options = array();
247 $num = count($object->lines);
248
249 for ($i = 0; $i < $num; $i++) {
250 // Extrafields
251 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
252 $array_options[$i] = $extrafields->getOptionalsFromPost($extralabelsline, (string) $i);
253 // Unset extrafield
254 if (is_array($extralabelsline)) {
255 // Get extra fields
256 foreach ($extralabelsline as $key => $value) {
257 unset($_POST["options_".$key]);
258 }
259 }
260
261 $ret = $object->update_line($object->lines[$i]->id, $array_options[$i]); // extrafields update
262 if ($ret < 0) {
263 $mesg = '<div class="error">'.$object->error.'</div>';
264 $error++;
265 }
266 }
267}
268
269
270// Actions to build doc
271$upload_dir = $conf->expedition->dir_output.'/receipt';
272include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
273// Provided by include of ...builddoc...:
274'
275@phan-var-force int<0,1> $hidedetails
276@phan-var-force int<0,1> $hidedesc
277@phan-var-force int<0,1> $hideref
278';
279
280include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
281
282// Actions to send emails
283
284$triggersendname = 'DELIVERY_SENTBYMAIL';
285$paramname = 'id';
286$autocopy = 'MAIN_MAIL_AUTOCOPY_DELIVERY_TO';
287$mode = 'emailfromdelivery';
288$trackid = 'del' . $object->id;
289include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
290
291
292/*
293 * View
294 */
295
296$title = $langs->trans('Delivery');
297
298llxHeader('', $title, 'Livraison', '', 0, 0, '', '', '', 'mod-delivery page-card');
299
300$form = new Form($db);
301$formfile = new FormFile($db);
302$objectsrc = null;
303
304if ($action == 'create') {
305 // Create. Seems to no be used
306} else {
307 // View
308 if ($object->id > 0) {
309 // Origin of a 'livraison' (delivery receipt) is ALWAYS 'expedition' (shipment).
310 // However, origin of shipment in future may differs (commande, proposal, ...)
311 $expedition = new Expedition($db);
312 $result = $expedition->fetch($object->origin_id);
313
314 $typeobject = $expedition->origin; // example: commande
315 if ($object->origin_id > 0) {
316 $object->fetch_origin();
317 }
318
319 if ($object->id > 0) {
320 $soc = new Societe($db);
321 $soc->fetch($object->socid);
322
323 $head = delivery_prepare_head($object);
324
325 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
326 print '<input type="hidden" name="token" value="'.newToken().'">';
327 print '<input type="hidden" name="action" value="update_extras_line">';
328 print '<input type="hidden" name="origin" value="'.$object->origin.'">';
329 print '<input type="hidden" name="id" value="'.$object->id.'">';
330 print '<input type="hidden" name="ref" value="'.$object->ref.'">';
331
332 print dol_get_fiche_head($head, 'delivery', $langs->trans("Shipment"), -1, 'dolly');
333
334 /*
335 * Confirmation de la suppression
336 *
337 */
338 if ($action == 'delete') {
339 $expedition_id = GETPOST("expid");
340 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);
341 }
342
343 /*
344 * Confirmation de la validation
345 */
346 if ($action == 'valid') {
347 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidateDeliveryReceipt"), $langs->trans("ValidateDeliveryReceiptConfirm", $object->ref), 'confirm_valid', '', '', 1);
348 }
349
350
351 /*
352 * Delivery
353 */
354
355 if ($typeobject == 'commande' && $expedition->origin_id > 0 && isModEnabled('order')) {
356 $objectsrc = new Commande($db);
357 $objectsrc->fetch($expedition->origin_id);
358 }
359 if ($typeobject == 'propal' && $expedition->origin_id > 0 && isModEnabled("propal")) {
360 $objectsrc = new Propal($db);
361 $objectsrc->fetch($expedition->origin_id);
362 }
363
364 // Shipment card
365 $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
366
367 $morehtmlref = '<div class="refidno">';
368 // Ref customer shipment
369 $morehtmlref .= $form->editfieldkey("RefCustomer", '', $expedition->ref_customer, $expedition, $user->hasRight('expedition', 'creer'), 'string', '', 0, 1);
370 $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);
371 $morehtmlref .= '<br>'.$langs->trans("RefDeliveryReceipt").' : '.$object->ref;
372 // Thirdparty
373 $morehtmlref .= '<br>'.$expedition->thirdparty->getNomUrl(1);
374 // Project
375 if (isModEnabled('project') && $objectsrc !== null) {
376 $langs->load("projects");
377 $morehtmlref .= '<br>';
378 if (0) { // @phpstan-ignore-line Do not change on shipment
379 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
380 if ($action != 'classify') {
381 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
382 }
383 $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');
384 } else {
385 if (!empty($objectsrc->fk_project)) {
386 $proj = new Project($db);
387 $proj->fetch($objectsrc->fk_project);
388 $morehtmlref .= $proj->getNomUrl(1);
389 if ($proj->title) {
390 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
391 }
392 }
393 }
394 }
395 $morehtmlref .= '</div>';
396
397 $morehtmlstatus = $langs->trans("StatusReceipt").' : '.$object->getLibStatut(6).'<br><br class="small">';
398
399 dol_banner_tab($expedition, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
400
401
402 print '<div class="fichecenter">';
403 print '<div class="underbanner clearboth"></div>';
404
405 print '<table class="border tableforfield" width="100%">';
406
407 // Shipment
408 /*
409 if (($object->origin == 'shipment' || $object->origin == 'expedition') && $object->origin_id > 0)
410 {
411 $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
412
413 // Ref
414 print '<tr><td width="20%">'.$langs->trans("RefSending").'</td>';
415 print '<td colspan="3">';
416 // 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)
417 //print $form->showrefnav($expedition, 'refshipment', $linkback, 1, 'ref', 'ref');
418 print $form->showrefnav($expedition, 'refshipment', $linkback, 0, 'ref', 'ref');
419 print '</td></tr>';
420 }
421
422 // Ref
423 print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
424 print '<td colspan="3">';
425 print $object->ref;
426 print '</td></tr>';
427
428 // Client
429 print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
430 print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
431 print "</tr>";
432 */
433
434 // Document origine
435 if ($typeobject == 'commande' && $expedition->origin_id && isModEnabled('order')) {
436 print '<tr><td class="titlefield">'.$langs->trans("RefOrder").'</td>';
437 $order = new Commande($db);
438 $order->fetch($expedition->origin_id);
439 print '<td colspan="3">';
440 print $order->getNomUrl(1, 'commande');
441 print "</td>\n";
442 print '</tr>';
443 }
444 if ($typeobject == 'propal' && $expedition->origin_id && isModEnabled("propal")) {
445 $propal = new Propal($db);
446 $propal->fetch($expedition->origin_id);
447 print '<tr><td class="titlefield">'.$langs->trans("RefProposal").'</td>';
448 print '<td colspan="3">';
449 print $propal->getNomUrl(1, 'expedition');
450 print "</td>\n";
451 print '</tr>';
452 }
453
454 // Date
455 print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
456 print '<td colspan="3">'.dol_print_date($object->date_creation, 'dayhour')."</td>\n";
457 print '</tr>';
458
459 // Date delivery real / Received
460 print '<tr><td height="10">';
461 print '<table class="nobordernopadding" width="100%"><tr><td>';
462 print $langs->trans('DateReceived');
463 print '</td>';
464
465 if ($action != 'editdate_delivery') {
466 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>';
467 }
468 print '</tr></table>';
469 print '</td><td colspan="2">';
470 if ($action == 'editdate_delivery') {
471 print '<form name="setdate_delivery" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
472 print '<input type="hidden" name="token" value="'.newToken().'">';
473 print '<input type="hidden" name="action" value="setdate_delivery">';
474 print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, 0, "setdate_delivery", 1, 1);
475 print '<input type="submit" class="button smallpaddingimp button-edit" value="'.$langs->trans('Modify').'">';
476 print '</form>';
477 } else {
478 print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
479 }
480 print '</td>';
481 print '</tr>';
482
483 // Incoterms
484 if (isModEnabled('incoterm')) {
485 print '<tr><td>';
486 print '<table class="centpercent nobordernopadding"><tr><td>';
487 print $langs->trans('IncotermLabel');
488 print '<td><td class="right">';
489 if ($user->hasRight('expedition', 'delivery', 'creer')) {
490 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
491 } else {
492 print '&nbsp;';
493 }
494 print '</td></tr></table>';
495 print '</td>';
496 print '<td colspan="3">';
497 if ($action != 'editincoterm') {
498 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
499 } else {
500 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
501 }
502 print '</td></tr>';
503 }
504
505 /* A delivery note should be just more properties of a shipment, so notes are on shipment
506 // Note Public
507 print '<tr><td>'.$langs->trans("NotePublic").'</td>';
508 print '<td colspan="3">';
509 print dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_public));
510 print "</td></tr>";
511
512 // Note Private
513 print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
514 print '<td colspan="3">';
515 print dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_private));
516 print "</td></tr>";
517 */
518
519 // Statut
520 /*print '<tr><td>'.$langs->trans("Status").'</td>';
521 print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
522 print '</tr>';*/
523
524
525 if (!getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && isModEnabled('stock')) {
526 // Entrepot
527 $entrepot = new Entrepot($db);
528 $entrepot->fetch($expedition->entrepot_id);
529 print '<tr><td width="20%">'.$langs->trans("Warehouse").'</td>';
530 print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/product/stock/card.php?id='.$entrepot->id.'">'.$entrepot->label.'</a></td>';
531 print '</tr>';
532 }
533
534 // Other attributes
535 if ($action == 'create_delivery') {
536 // copy from expedition
537 $extrafields->fetch_name_optionals_label($expedition->table_element);
538 if ($expedition->fetch_optionals() > 0) {
539 $object->array_options = array_merge($object->array_options, $expedition->array_options);
540 }
541 }
542 $cols = 2;
543 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
544
545 print "</table><br>\n";
546
547 print '</div>';
548
549 /*
550 * Products lines
551 */
552
553 $num_prod = count($object->lines);
554 $i = 0;
555 $total = 0;
556
557 print '<table class="noborder centpercent">';
558
559 if ($num_prod) {
560 $i = 0;
561
562 print '<tr class="liste_titre">';
563 print '<td>'.$langs->trans("Products").'</td>';
564 print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
565 print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
566 print "</tr>\n";
567 }
568 while ($i < $num_prod) {
569 $parameters = array('i' => $i, 'line' => $object->lines[$i], 'num' => $num_prod);
570 $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);
571 if ($reshook < 0) {
572 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
573 }
574
575 if (empty($reshook)) {
576 print '<tr class="oddeven">';
577 if ($object->lines[$i]->fk_product > 0) {
578 $product = new Product($db);
579 $product->fetch($object->lines[$i]->fk_product);
580
581 // Define output language
582 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
583 $outputlangs = $langs;
584 $newlang = '';
585 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
586 $newlang = GETPOST('lang_id', 'aZ09');
587 }
588 if (empty($newlang)) {
589 $newlang = $object->thirdparty->default_lang;
590 }
591 if (!empty($newlang)) {
592 $outputlangs = new Translate("", $conf);
593 $outputlangs->setDefaultLang($newlang);
594 }
595
596 $label = (!empty($product->multilangs[$outputlangs->defaultlang]["label"])) ? $product->multilangs[$outputlangs->defaultlang]["label"] : $object->lines[$i]->product_label;
597 } else {
598 $label = (!empty($object->lines[$i]->label) ? $object->lines[$i]->label : $object->lines[$i]->product_label);
599 }
600
601 print '<td>';
602
603 // Show product line
604 $text = '<a href="'.DOL_URL_ROOT.'/product/card.php?id='.$object->lines[$i]->fk_product.'">';
605 if ($object->lines[$i]->fk_product_type == 1) {
606 $text .= img_object($langs->trans('ShowService'), 'service');
607 } else {
608 $text .= img_object($langs->trans('ShowProduct'), 'product');
609 }
610 $text .= ' '.$object->lines[$i]->product_ref.'</a>';
611 $text .= ' - '.$label;
612 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($object->lines[$i]->description));
613 //print $description;
614 print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
615 //print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
616 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
617 print (!empty($object->lines[$i]->description) && $object->lines[$i]->description != $object->lines[$i]->product_label) ? '<br>'.dol_htmlentitiesbr($object->lines[$i]->description) : '';
618 }
619 } else {
620 print "<td>";
621 if ($object->lines[$i]->fk_product_type == 1) {
622 $text = img_object($langs->trans('Service'), 'service');
623 } else {
624 $text = img_object($langs->trans('Product'), 'product');
625 }
626
627 if (!empty($object->lines[$i]->label)) {
628 $text .= ' <strong>'.$object->lines[$i]->label.'</strong>';
629 print $form->textwithtooltip($text, $object->lines[$i]->description, 3, 0, '', (string) $i);
630 } else {
631 print $text.' '.nl2br($object->lines[$i]->description);
632 }
633
634 //print_date_range($objp->date_start, $objp->date_end);
635 print "</td>\n";
636 }
637
638 print '<td class="center">'.$object->lines[$i]->qty_asked.'</td>';
639 print '<td class="center">'.$object->lines[$i]->qty_shipped.'</td>';
640
641 print "</tr>";
642
643 // Display lines extrafields
644 //if (!empty($extrafields)) {
645 $colspan = 2;
646 $mode = ($object->statut == 0) ? 'edit' : 'view';
647
648 $object->lines[$i]->fetch_optionals();
649
650 if ($action == 'create_delivery') {
651 $srcLine = new ExpeditionLigne($db);
652
653 $extrafields->fetch_name_optionals_label($srcLine->table_element);
654 $srcLine->id = $expedition->lines[$i]->id;
655 $srcLine->fetch_optionals();
656
657 $object->lines[$i]->array_options = array_merge($object->lines[$i]->array_options, $srcLine->array_options);
658 } else {
659 $srcLine = new DeliveryLine($db);
660 $extrafields->fetch_name_optionals_label($srcLine->table_element);
661 }
662 print $object->lines[$i]->showOptionals($extrafields, $mode, array('style' => 'class="oddeven"', 'colspan' => $colspan), '');
663 //}
664 }
665
666 $i++;
667 }
668
669 print "</table>\n";
670
671 print dol_get_fiche_end();
672
673 //if ($object->statut == 0) // only if draft
674 // print $form->buttonsSaveCancel("Save", '');
675
676 print '</form>';
677
678
679 /*
680 * Boutons actions
681 */
682
683 if ($user->socid == 0) {
684 print '<div class="tabsAction">';
685
686 if ($object->statut == 0 && $num_prod > 0) {
687 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery', 'creer'))
688 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery_advance', 'validate'))) {
689 print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=valid&token='.newToken().'&id='.$object->id, '');
690 }
691 }
692 if ($user->hasRight('expedition', 'delivery', 'supprimer') && $action != 'presend') {
693 if ($object->status == Delivery::STATUS_VALIDATED && $action != 'presend' && $expedition->status == Expedition::STATUS_VALIDATED) {
694 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');
695 }
696 if (getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION')) {
697 print dolGetButtonAction($langs->trans('Delete'), $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), '', true, array('attr' => array('class' => 'reposition')))."\n";
698 } else {
699 print dolGetButtonAction($langs->trans('Delete'), $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '', true, array('attr' => array('class' => 'reposition')))."\n";
700 }
701 }
702
703 print '</div>';
704 }
705 print "\n";
706
707 print '<div class="fichecenter"><div class="fichehalfleft">';
708
709 /*
710 * Documents generated
711 */
712 if ($action != 'presend') {
713 $objectref = dol_sanitizeFileName((string) $object->ref);
714 $filedir = $conf->expedition->dir_output."/receipt/".$objectref;
715 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
716
717 $genallowed = $user->hasRight('expedition', 'delivery', 'lire');
718 $delallowed = $user->hasRight('expedition', 'delivery', 'creer');
719
720 print $formfile->showdocuments('delivery', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
721
722 /*
723 * Linked object block (of linked shipment)
724 */
725
726 // Show links to link elements
727 print '</div><div class="fichehalfright">';
728
729 // List of actions on element
730 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
731
732 //$tmparray = $form->showLinkToObjectBlock($object, null, array('order'), 1);
733 $somethingshown = $form->showLinkedObjectBlock($object, '');
734 }
735
736
737 print '</div><div class="fichehalfright">';
738
739 // Nothing on right
740
741 print '</div></div>';
742 } else {
743 /* Expedition non trouvee */
744 print "Expedition inexistante ou access refuse";
745 }
746 } else {
747 /* Expedition non trouvee */
748 print "Expedition inexistante ou access refuse";
749 }
750
751 /*
752 * Action presend
753 */
754 //Select mail models is same action as presend
755 if (GETPOST('modelselected')) {
756 $action = 'presend';
757 }
758
759 // Presend form
760 $modelmail = 'delivery_send';
761 $defaulttopic = 'SendDeliveryRef';
762 $diroutput = $conf->expedition->dir_output . '/receipt';
763 $trackid = 'del' . $object->id;
764
765 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
766}
767
768// End of page
769llxFooter();
770$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:
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...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
delivery_prepare_head($object)
Prepare array with list of tabs.