dolibarr 23.0.3
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-2025 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2025 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';
34require_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
40if (isModEnabled("product") || isModEnabled("service")) {
41 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
42}
43if (isModEnabled('shipping')) {
44 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
45}
46if (isModEnabled('stock')) {
47 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
48}
49if (isModEnabled('project')) {
50 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
52}
53
62// Load translation files required by the page
63$langs->loadLangs(array('bills', 'orders', 'sendings'));
64
65if (isModEnabled('incoterm')) {
66 $langs->load('incoterm');
67}
68
69$action = GETPOST('action', 'aZ09');
70$confirm = GETPOST('confirm', 'alpha');
71$backtopage = GETPOST('backtopage', 'alpha');
72$id = GETPOSTINT('id');
73
74
75// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
76$hookmanager->initHooks(array('deliverycard', 'globalcard'));
77
78$object = new Delivery($db);
79$extrafields = new ExtraFields($db);
80
81// fetch optionals attributes and labels
82$extrafields->fetch_name_optionals_label($object->table_element);
83
84// fetch optionals attributes lines and labels
85$extrafields->fetch_name_optionals_label($object->table_element_line);
86
87// Load object. Make an object->fetch
88include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
89
90$error = 0;
91
92// Security check
93if ($user->socid) {
94 $socid = $user->socid;
95}
96$result = restrictedArea($user, 'expedition', $id, 'delivery', 'delivery');
97
98$permissiontoread = $user->hasRight('expedition', 'delivery', 'read');
99$permissiontoadd = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
100$permissiontodelete = $user->hasRight('expedition', 'delivery', 'supprimer') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
101$permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery_advance', 'validate')));
102$permissionnote = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_setnotes.inc.php
103$permissiondellink = $user->hasRight('expedition', 'delivery', 'creer'); // Used by the include of actions_dellink.inc.php
104$permissiontoeditextra = $permissiontoadd;
105if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
106 // For action 'update_extras', is there a specific permission set for the attribute to update
107 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
108}
109$permissiontoeditextraline = $permissiontoadd;
110if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element_line]['perms'][GETPOST('attribute', 'aZ09')])) {
111 // For action 'update_extras', is there a specific permission set for the attribute to update
112 $permissiontoeditextraline = dol_eval((string) $extrafields->attributes[$object->table_element_line]['perms'][GETPOST('attribute', 'aZ09')]);
113}
114
115
116/*
117 * Actions
118 */
119
120$parameters = array();
121$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
122// Delete Link
123$permissiondellink = $user->hasRight('expedition', 'delivery', 'supprimer'); // Used by the include of actions_dellink.inc.php
124include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
125
126if ($action == 'add' && $permissiontoadd) {
127 $array_options = array();
128 $db->begin();
129
130 $object->date_delivery = dol_now();
131 $object->note_private = GETPOST("note", 'restricthtml');
132 $object->note = $object->note_private; // deprecated
133 $object->commande_id = GETPOSTINT("commande_id");
134 $object->fk_incoterms = GETPOSTINT('incoterm_id');
135 // $object->entrepot_id = GETPOST('entrepot_id', 'int'); entrepot_id does not exists on delivery note, only on shipment document
136
137 // We loop on each line of order to complete object delivery with qty to delivery
138 $commande = new Commande($db);
139 $commande->fetch($object->commande_id);
140 $commande->fetch_lines();
141
142 $num = count($commande->lines);
143 for ($i = 0; $i < $num; $i++) {
144 $qty = "qtyl".$i;
145 $idl = "idl".$i;
146 $qtytouse = price2num(GETPOSTFLOAT($qty));
147 if ($qtytouse > 0) {
148 $object->addline(GETPOSTINT($idl), (float) price2num($qtytouse), $array_options);
149 }
150 }
151
152 $ret = $object->create($user);
153 if ($ret > 0) {
154 $db->commit();
155 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
156 exit;
157 } else {
158 setEventMessages($object->error, $object->errors, 'errors');
159 $db->rollback();
160
161 $action = 'create';
162 }
163} elseif ($action == 'confirm_valid' && $confirm == 'yes' && $permissiontovalidate) {
164 $result = $object->valid($user);
165
166 // Define output language
167 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
168 $outputlangs = $langs;
169 $newlang = '';
170 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
171 $newlang = GETPOST('lang_id', 'aZ09');
172 }
173 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
174 $newlang = $object->thirdparty->default_lang;
175 }
176 if (!empty($newlang)) {
177 $outputlangs = new Translate("", $conf);
178 $outputlangs->setDefaultLang($newlang);
179 }
180 $model = $object->model_pdf;
181 $ret = $object->fetch($id); // Reload to get new record
182
183 // Phan does not use suggested tyhpe for $hide*, ignore: @phan-suppress-next-line PhanTypeMismatchArgument
184 $result = $object->generateDocument($model, $outputlangs, 0, 0, 0);
185 if ($result < 0) {
186 dol_print_error($db, $object->error, $object->errors);
187 }
188 }
189}
190
191if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
192 $db->begin();
193 $result = $object->delete($user);
194
195 if ($result > 0) {
196 $db->commit();
197 if (!empty($backtopage)) {
198 header("Location: ".$backtopage);
199 } else {
200 header("Location: ".DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1');
201 }
202 exit;
203 } else {
204 $db->rollback();
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
303if ($action == 'create') {
304 // Create. Seems to no be used
305} else {
306 // View
307 if ($object->id > 0) {
308 // Origin of a 'livraison' (delivery receipt) is ALWAYS 'expedition' (shipment).
309 // However, origin of shipment in future may differs (commande, proposal, ...)
310 $expedition = new Expedition($db);
311 $result = $expedition->fetch($object->origin_id);
312
313 $typeobject = $expedition->origin; // example: commande
314 if ($object->origin_id > 0) {
315 $object->fetch_origin();
316 }
317
318 if ($object->id > 0) {
319 $soc = new Societe($db);
320 $soc->fetch($object->socid);
321
322 $head = delivery_prepare_head($object);
323
324 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
325 print '<input type="hidden" name="token" value="'.newToken().'">';
326 print '<input type="hidden" name="action" value="update_extras_line">';
327 print '<input type="hidden" name="origin" value="'.$object->origin.'">';
328 print '<input type="hidden" name="id" value="'.$object->id.'">';
329 print '<input type="hidden" name="ref" value="'.$object->ref.'">';
330
331 print dol_get_fiche_head($head, 'delivery', $langs->trans("Shipment"), -1, 'dolly');
332
333 /*
334 * Confirmation de la suppression
335 *
336 */
337 if ($action == 'delete') {
338 $expedition_id = GETPOST("expid");
339 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);
340 }
341
342 /*
343 * Confirmation de la validation
344 */
345 if ($action == 'valid') {
346 print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidateDeliveryReceipt"), $langs->trans("ValidateDeliveryReceiptConfirm", $object->ref), 'confirm_valid', '', '', 1);
347 }
348
349
350 /*
351 * Delivery
352 */
353
354 if ($typeobject == 'commande' && $expedition->origin_id > 0 && isModEnabled('order')) {
355 $objectsrc = new Commande($db);
356 $objectsrc->fetch($expedition->origin_id);
357 }
358 if ($typeobject == 'propal' && $expedition->origin_id > 0 && isModEnabled("propal")) {
359 $objectsrc = new Propal($db);
360 $objectsrc->fetch($expedition->origin_id);
361 }
362
363 // Shipment card
364 $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
365
366 $morehtmlref = '<div class="refidno">';
367 // Ref customer shipment
368 $morehtmlref .= $form->editfieldkey("RefCustomer", '', $expedition->ref_customer, $expedition, $user->hasRight('expedition', 'creer'), 'string', '', 0, 1);
369 $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);
370 $morehtmlref .= '<br>'.$langs->trans("RefDeliveryReceipt").' : '.$object->ref;
371 // Thirdparty
372 $morehtmlref .= '<br>'.$expedition->thirdparty->getNomUrl(1);
373 // Project
374 if (isModEnabled('project')) {
375 $langs->load("projects");
376 $morehtmlref .= '<br>';
377 if (0) { // @phpstan-ignore-line Do not change on shipment
378 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
379 if ($action != 'classify') {
380 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
381 }
382 $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');
383 } else {
384 if (!empty($objectsrc->fk_project)) {
385 $proj = new Project($db);
386 $proj->fetch($objectsrc->fk_project);
387 $morehtmlref .= $proj->getNomUrl(1);
388 if ($proj->title) {
389 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
390 }
391 }
392 }
393 }
394 $morehtmlref .= '</div>';
395
396 $morehtmlstatus = $langs->trans("StatusReceipt").' : '.$object->getLibStatut(6).'<br><br class="small">';
397
398 dol_banner_tab($expedition, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', $morehtmlstatus);
399
400
401 print '<div class="fichecenter">';
402 print '<div class="underbanner clearboth"></div>';
403
404 print '<table class="border tableforfield" width="100%">';
405
406 // Shipment
407 /*
408 if (($object->origin == 'shipment' || $object->origin == 'expedition') && $object->origin_id > 0)
409 {
410 $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
411
412 // Ref
413 print '<tr><td width="20%">'.$langs->trans("RefSending").'</td>';
414 print '<td colspan="3">';
415 // 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)
416 //print $form->showrefnav($expedition, 'refshipment', $linkback, 1, 'ref', 'ref');
417 print $form->showrefnav($expedition, 'refshipment', $linkback, 0, 'ref', 'ref');
418 print '</td></tr>';
419 }
420
421 // Ref
422 print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
423 print '<td colspan="3">';
424 print $object->ref;
425 print '</td></tr>';
426
427 // Client
428 print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
429 print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
430 print "</tr>";
431 */
432
433 // Document origine
434 if ($typeobject == 'commande' && $expedition->origin_id && isModEnabled('order')) {
435 print '<tr><td class="titlefield">'.$langs->trans("RefOrder").'</td>';
436 $order = new Commande($db);
437 $order->fetch($expedition->origin_id);
438 print '<td colspan="3">';
439 print $order->getNomUrl(1, 'commande');
440 print "</td>\n";
441 print '</tr>';
442 }
443 if ($typeobject == 'propal' && $expedition->origin_id && isModEnabled("propal")) {
444 $propal = new Propal($db);
445 $propal->fetch($expedition->origin_id);
446 print '<tr><td class="titlefield">'.$langs->trans("RefProposal").'</td>';
447 print '<td colspan="3">';
448 print $propal->getNomUrl(1, 'expedition');
449 print "</td>\n";
450 print '</tr>';
451 }
452
453 // Date
454 print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
455 print '<td colspan="3">'.dol_print_date($object->date_creation, 'dayhour')."</td>\n";
456 print '</tr>';
457
458 // Date delivery real / Received
459 print '<tr><td height="10">';
460 print '<table class="nobordernopadding" width="100%"><tr><td>';
461 print $langs->trans('DateReceived');
462 print '</td>';
463
464 if ($action != 'editdate_delivery') {
465 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>';
466 }
467 print '</tr></table>';
468 print '</td><td colspan="2">';
469 if ($action == 'editdate_delivery') {
470 print '<form name="setdate_delivery" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
471 print '<input type="hidden" name="token" value="'.newToken().'">';
472 print '<input type="hidden" name="action" value="setdate_delivery">';
473 print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, 0, "setdate_delivery", 1, 1);
474 print '<input type="submit" class="button smallpaddingimp button-edit" value="'.$langs->trans('Modify').'">';
475 print '</form>';
476 } else {
477 print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
478 }
479 print '</td>';
480 print '</tr>';
481
482 // Incoterms
483 if (isModEnabled('incoterm')) {
484 print '<tr><td>';
485 print '<table class="centpercent nobordernopadding"><tr><td>';
486 print $langs->trans('IncotermLabel');
487 print '<td><td class="right">';
488 if ($user->hasRight('expedition', 'delivery', 'creer')) {
489 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
490 } else {
491 print '&nbsp;';
492 }
493 print '</td></tr></table>';
494 print '</td>';
495 print '<td colspan="3">';
496 if ($action != 'editincoterm') {
497 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
498 } else {
499 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
500 }
501 print '</td></tr>';
502 }
503
504 /* A delivery note should be just more properties of a shipment, so notes are on shipment
505 // Note Public
506 print '<tr><td>'.$langs->trans("NotePublic").'</td>';
507 print '<td colspan="3">';
508 print dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_public));
509 print "</td></tr>";
510
511 // Note Private
512 print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
513 print '<td colspan="3">';
514 print dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_private));
515 print "</td></tr>";
516 */
517
518 // Statut
519 /*print '<tr><td>'.$langs->trans("Status").'</td>';
520 print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
521 print '</tr>';*/
522
523
524 if (!getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && isModEnabled('stock')) {
525 // Entrepot
526 $entrepot = new Entrepot($db);
527 $entrepot->fetch($expedition->entrepot_id);
528 print '<tr><td width="20%">'.$langs->trans("Warehouse").'</td>';
529 print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/product/stock/card.php?id='.$entrepot->id.'">'.$entrepot->label.'</a></td>';
530 print '</tr>';
531 }
532
533 // Other attributes
534 if ($action == 'create_delivery') {
535 // copy from expedition
536 $extrafields->fetch_name_optionals_label($expedition->table_element);
537 if ($expedition->fetch_optionals() > 0) {
538 $object->array_options = array_merge($object->array_options, $expedition->array_options);
539 }
540 }
541 $cols = 2;
542 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
543
544 print "</table><br>\n";
545
546 print '</div>';
547
548 /*
549 * Products lines
550 */
551
552 $num_prod = count($object->lines);
553 $i = 0;
554 $total = 0;
555
556 print '<table class="noborder centpercent">';
557
558 if ($num_prod) {
559 $i = 0;
560
561 print '<tr class="liste_titre">';
562 print '<td>'.$langs->trans("Products").'</td>';
563 print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
564 print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
565 print "</tr>\n";
566 }
567 while ($i < $num_prod) {
568 $parameters = array('i' => $i, 'line' => $object->lines[$i], 'num' => $num_prod);
569 $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);
570 if ($reshook < 0) {
571 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
572 }
573
574 if (empty($reshook)) {
575 print '<tr class="oddeven">';
576 if ($object->lines[$i]->fk_product > 0) {
577 $product = new Product($db);
578 $product->fetch($object->lines[$i]->fk_product);
579
580 // Define output language
581 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
582 $outputlangs = $langs;
583 $newlang = '';
584 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
585 $newlang = GETPOST('lang_id', 'aZ09');
586 }
587 if (empty($newlang)) {
588 $newlang = $object->thirdparty->default_lang;
589 }
590 if (!empty($newlang)) {
591 $outputlangs = new Translate("", $conf);
592 $outputlangs->setDefaultLang($newlang);
593 }
594
595 $label = (!empty($product->multilangs[$outputlangs->defaultlang]["label"])) ? $product->multilangs[$outputlangs->defaultlang]["label"] : $object->lines[$i]->product_label;
596 } else {
597 $label = (!empty($object->lines[$i]->label) ? $object->lines[$i]->label : $object->lines[$i]->product_label);
598 }
599
600 print '<td>';
601
602 // Affiche ligne produit
603 $text = '<a href="'.DOL_URL_ROOT.'/product/card.php?id='.$object->lines[$i]->fk_product.'">';
604 if ($object->lines[$i]->fk_product_type == 1) {
605 $text .= img_object($langs->trans('ShowService'), 'service');
606 } else {
607 $text .= img_object($langs->trans('ShowProduct'), 'product');
608 }
609 $text .= ' '.$object->lines[$i]->product_ref.'</a>';
610 $text .= ' - '.$label;
611 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($object->lines[$i]->description));
612 //print $description;
613 print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
614 //print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
615 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
616 print (!empty($object->lines[$i]->description) && $object->lines[$i]->description != $object->lines[$i]->product_label) ? '<br>'.dol_htmlentitiesbr($object->lines[$i]->description) : '';
617 }
618 } else {
619 print "<td>";
620 if ($object->lines[$i]->fk_product_type == 1) {
621 $text = img_object($langs->trans('Service'), 'service');
622 } else {
623 $text = img_object($langs->trans('Product'), 'product');
624 }
625
626 if (!empty($object->lines[$i]->label)) {
627 $text .= ' <strong>'.$object->lines[$i]->label.'</strong>';
628 print $form->textwithtooltip($text, $object->lines[$i]->description, 3, 0, '', (string) $i);
629 } else {
630 print $text.' '.nl2br($object->lines[$i]->description);
631 }
632
633 //print_date_range($objp->date_start, $objp->date_end);
634 print "</td>\n";
635 }
636
637 print '<td class="center">'.$object->lines[$i]->qty_asked.'</td>';
638 print '<td class="center">'.$object->lines[$i]->qty_shipped.'</td>';
639
640 print "</tr>";
641
642 // Display lines extrafields
643 //if (!empty($extrafields)) {
644 $colspan = 2;
645 $mode = ($object->statut == 0) ? 'edit' : 'view';
646
647 $object->lines[$i]->fetch_optionals();
648
649 if ($action == 'create_delivery') {
650 $srcLine = new ExpeditionLigne($db);
651
652 $extrafields->fetch_name_optionals_label($srcLine->table_element);
653 $srcLine->id = $expedition->lines[$i]->id;
654 $srcLine->fetch_optionals();
655
656 $object->lines[$i]->array_options = array_merge($object->lines[$i]->array_options, $srcLine->array_options);
657 } else {
658 $srcLine = new DeliveryLine($db);
659 $extrafields->fetch_name_optionals_label($srcLine->table_element);
660 }
661 print $object->lines[$i]->showOptionals($extrafields, $mode, array('style' => 'class="oddeven"', 'colspan' => $colspan), '');
662 //}
663 }
664
665 $i++;
666 }
667
668 print "</table>\n";
669
670 print dol_get_fiche_end();
671
672 //if ($object->statut == 0) // only if draft
673 // print $form->buttonsSaveCancel("Save", '');
674
675 print '</form>';
676
677
678 /*
679 * Boutons actions
680 */
681
682 if ($user->socid == 0) {
683 print '<div class="tabsAction">';
684
685 if ($object->statut == 0 && $num_prod > 0) {
686 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery', 'creer'))
687 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'delivery_advance', 'validate'))) {
688 print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=valid&token='.newToken().'&id='.$object->id, '');
689 }
690 }
691 if ($user->hasRight('expedition', 'delivery', 'supprimer') && $action != 'presend') {
692 if ($object->status == Delivery::STATUS_VALIDATED && $action != 'presend' && $expedition->status == Expedition::STATUS_VALIDATED) {
693 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');
694 }
695 if (getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION')) {
696 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), '');
697 } else {
698 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
699 }
700 }
701
702 print '</div>';
703 }
704 print "\n";
705
706 print '<div class="fichecenter"><div class="fichehalfleft">';
707
708 /*
709 * Documents generated
710 */
711 if ($action != 'presend') {
712 $objectref = dol_sanitizeFileName($object->ref);
713 $filedir = $conf->expedition->dir_output."/receipt/".$objectref;
714 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
715
716 $genallowed = $user->hasRight('expedition', 'delivery', 'lire');
717 $delallowed = $user->hasRight('expedition', 'delivery', 'creer');
718
719 print $formfile->showdocuments('delivery', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
720
721 /*
722 * Linked object block (of linked shipment)
723 */
724
725 // Show links to link elements
726 print '</div><div class="fichehalfright">';
727
728 // List of actions on element
729 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
730
731 //$tmparray = $form->showLinkToObjectBlock($object, null, array('order'), 1);
732 $somethingshown = $form->showLinkedObjectBlock($object, '');
733 }
734
735
736 print '</div><div class="fichehalfright">';
737
738 // Nothing on right
739
740 print '</div></div>';
741 } else {
742 /* Expedition non trouvee */
743 print "Expedition inexistante ou access refuse";
744 }
745 } else {
746 /* Expedition non trouvee */
747 print "Expedition inexistante ou access refuse";
748 }
749
750 /*
751 * Action presend
752 */
753 //Select mail models is same action as presend
754 if (GETPOST('modelselected')) {
755 $action = 'presend';
756 }
757
758 // Presend form
759 $modelmail = 'delivery_send';
760 $defaulttopic = 'SendDeliveryRef';
761 $diroutput = $conf->expedition->dir_output . '/receipt';
762 $trackid = 'del' . $object->id;
763
764 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
765}
766
767// End of page
768llxFooter();
769$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 manage standard extra fields.
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.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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.