30 require
'../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/delivery/class/delivery.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/modules/delivery/modules_delivery.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/sendings.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
37 if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
38 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
40 if (!empty($conf->expedition_bon->enabled)) {
41 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
43 if (!empty($conf->stock->enabled)) {
44 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
46 if (!empty($conf->project->enabled)) {
47 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
52 $langs->loadLangs(array(
"sendings",
"bills",
'deliveries',
'orders'));
54 if (!empty($conf->incoterm->enabled)) {
55 $langs->load(
'incoterm');
58 $action =
GETPOST(
'action',
'aZ09');
59 $confirm =
GETPOST(
'confirm',
'alpha');
60 $backtopage =
GETPOST(
'backtopage',
'alpha');
65 $socid = $user->socid;
67 $result =
restrictedArea($user,
'expedition', $id,
'delivery',
'delivery');
73 $extrafields->fetch_name_optionals_label($object->table_element);
76 $extrafields->fetch_name_optionals_label($object->table_element_line);
79 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
82 $hookmanager->initHooks(array(
'deliverycard',
'globalcard'));
92 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
94 $permissiondellink = $user->rights->expedition->delivery->supprimer;
95 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
97 if ($action ==
'add') {
100 $object->date_delivery =
dol_now();
101 $object->note =
GETPOST(
"note",
'restricthtml');
102 $object->note_private =
GETPOST(
"note",
'restricthtml');
103 $object->commande_id =
GETPOST(
"commande_id",
'int');
104 $object->fk_incoterms =
GETPOST(
'incoterm_id',
'int');
106 if (!$conf->expedition_bon->enabled && !empty($conf->stock->enabled)) {
107 $expedition->entrepot_id =
GETPOST(
'entrepot_id',
'int');
112 $commande->fetch($object->commande_id);
113 $commande->fetch_lines();
114 $num = count($commande->lines);
115 for ($i = 0; $i < $num; $i++) {
124 $ret = $object->create($user);
127 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
135 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' &&
136 ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer))
137 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate)))
139 $result = $object->valid($user);
142 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
143 $outputlangs = $langs;
145 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
146 $newlang =
GETPOST(
'lang_id',
'aZ09');
148 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
149 $newlang = $object->thirdparty->default_lang;
151 if (!empty($newlang)) {
153 $outputlangs->setDefaultLang($newlang);
155 $model = $object->model_pdf;
156 $ret = $object->fetch($id);
158 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
165 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->expedition->delivery->supprimer) {
167 $result = $object->delete();
171 if (!empty($backtopage)) {
172 header(
"Location: ".$backtopage);
174 header(
"Location: ".DOL_URL_ROOT.
'/expedition/list.php?restore_lastsearch_values=1');
182 if ($action ==
'setdate_delivery' && $user->rights->expedition->delivery->creer) {
183 $datedelivery =
dol_mktime(
GETPOST(
'liv_hour',
'int'),
GETPOST(
'liv_min',
'int'), 0,
GETPOST(
'liv_month',
'int'),
GETPOST(
'liv_day',
'int'),
GETPOST(
'liv_year',
'int'));
184 $result = $object->setDeliveryDate($user, $datedelivery);
186 $mesg =
'<div class="error">'.$object->error.
'</div>';
188 } elseif ($action ==
'set_incoterms' && !empty($conf->incoterm->enabled)) {
190 $result = $object->setIncoterms((
int)
GETPOST(
'incoterm_id',
'int'),
GETPOST(
'location_incoterms',
'alpha'));
194 if ($action ==
'update_extras') {
198 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
205 $result = $object->insertExtraFields(
'DELIVERY_MODIFY');
213 $action =
'edit_extras';
218 if ($action ==
'update_extras_line') {
219 $array_options = array();
220 $num = count($object->lines);
222 for ($i = 0; $i < $num; $i++) {
224 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
225 $array_options[$i] = $extrafields->getOptionalsFromPost($extralabelsline, $i);
227 if (is_array($extralabelsline)) {
229 foreach ($extralabelsline as $key => $value) {
230 unset($_POST[
"options_".$key]);
234 $ret = $object->update_line($object->lines[$i]->id, $array_options[$i]);
236 $mesg =
'<div class="error">'.$object->error.
'</div>';
244 $upload_dir = $conf->expedition->dir_output.
'/receipt';
245 $permissiontoadd = $user->rights->expedition->creer;
246 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
248 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
255 $title = $langs->trans(
'Delivery');
262 if ($action ==
'create') {
266 if ($object->id > 0) {
270 $result = $expedition->fetch($object->origin_id);
271 $typeobject = $expedition->origin;
272 if ($object->origin_id > 0) {
273 $object->fetch_origin();
276 if ($object->id > 0) {
278 $soc->fetch($object->socid);
282 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
283 print
'<input type="hidden" name="token" value="'.newToken().
'">';
284 print
'<input type="hidden" name="action" value="update_extras_line">';
285 print
'<input type="hidden" name="origin" value="'.$origin.
'">';
286 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
287 print
'<input type="hidden" name="ref" value="'.$object->ref.
'">';
295 if ($action ==
'delete') {
296 $expedition_id =
GETPOST(
"expid");
297 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);
303 if ($action ==
'valid') {
304 print
$form->formconfirm($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $langs->trans(
"ValidateDeliveryReceipt"), $langs->trans(
"ValidateDeliveryReceiptConfirm", $object->ref),
'confirm_valid',
'',
'', 1);
312 if ($typeobject ==
'commande' && $expedition->origin_id > 0 && !empty($conf->commande->enabled)) {
314 $objectsrc->fetch($expedition->origin_id);
316 if ($typeobject ==
'propal' && $expedition->origin_id > 0 && !empty($conf->propal->enabled)) {
317 $objectsrc =
new Propal($db);
318 $objectsrc->fetch($expedition->origin_id);
322 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
324 $morehtmlref =
'<div class="refidno">';
326 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'', $expedition->ref_customer, $expedition, $user->rights->expedition->creer,
'string',
'', 0, 1);
327 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'', $expedition->ref_customer, $expedition, $user->rights->expedition->creer,
'string',
'',
null,
null,
'', 1);
328 $morehtmlref .=
'<br>'.$langs->trans(
"RefDeliveryReceipt").
' : '.$object->ref;
330 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$expedition->thirdparty->getNomUrl(1);
332 if (!empty($conf->project->enabled)) {
333 $langs->load(
"projects");
334 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
336 if ($action !=
'classify') {
337 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$expedition->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
339 if ($action ==
'classify') {
341 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$expedition->id.
'">';
342 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
343 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
344 $morehtmlref .= $formproject->select_projects($expedition->socid, $expedition->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
345 $morehtmlref .=
'<input type="submit" class="button button-edit" value="'.$langs->trans(
"Modify").
'">';
346 $morehtmlref .=
'</form>';
348 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$expedition->id, $expedition->socid, $expedition->fk_project,
'none', 0, 0, 0, 1);
351 $morehtmlref .=
' : ';
352 if (!empty($objectsrc->fk_project)) {
354 $proj->fetch($objectsrc->fk_project);
355 $morehtmlref .=
' : '.$proj->getNomUrl(1);
357 $morehtmlref .=
' - '.$proj->title;
364 $morehtmlref .=
'</div>';
366 $morehtmlstatus = $langs->trans(
"StatusReceipt").
' : '.$object->getLibStatut(6).
'<br><br class="small">';
368 dol_banner_tab($expedition,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref,
'', 0,
'', $morehtmlstatus);
371 print
'<div class="fichecenter">';
372 print
'<div class="underbanner clearboth"></div>';
374 print
'<table class="border tableforfield" width="100%">';
404 if ($typeobject ==
'commande' && $expedition->origin_id && !empty($conf->commande->enabled)) {
405 print
'<tr><td class="titlefield">'.$langs->trans(
"RefOrder").
'</td>';
407 $order->fetch($expedition->origin_id);
408 print
'<td colspan="3">';
409 print $order->getNomUrl(1,
'commande');
413 if ($typeobject ==
'propal' && $expedition->origin_id && !empty($conf->propal->enabled)) {
414 $propal =
new Propal($db);
415 $propal->fetch($expedition->origin_id);
416 print
'<tr><td class="titlefield">'.$langs->trans(
"RefProposal").
'</td>';
417 print
'<td colspan="3">';
418 print $propal->getNomUrl(1,
'expedition');
424 print
'<tr><td class="titlefield">'.$langs->trans(
"DateCreation").
'</td>';
425 print
'<td colspan="3">'.dol_print_date($object->date_creation,
'dayhour').
"</td>\n";
429 print
'<tr><td height="10">';
430 print
'<table class="nobordernopadding" width="100%"><tr><td>';
431 print $langs->trans(
'DateReceived');
434 if ($action !=
'editdate_delivery') {
435 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>';
437 print
'</tr></table>';
438 print
'</td><td colspan="2">';
439 if ($action ==
'editdate_delivery') {
440 print
'<form name="setdate_delivery" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
441 print
'<input type="hidden" name="token" value="'.newToken().
'">';
442 print
'<input type="hidden" name="action" value="setdate_delivery">';
443 print
$form->selectDate($object->date_delivery ? $object->date_delivery : -1,
'liv_', 1, 1,
'',
"setdate_delivery", 1, 1);
444 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
447 print $object->date_delivery ?
dol_print_date($object->date_delivery,
'dayhour') :
' ';
453 if (!empty($conf->incoterm->enabled)) {
455 print
'<table width="100%" class="nobordernopadding"><tr><td>';
456 print $langs->trans(
'IncotermLabel');
457 print
'<td><td class="right">';
458 if ($user->rights->expedition->delivery->creer) {
459 print
'<a class="editfielda" href="'.DOL_URL_ROOT.
'/delivery/card.php?id='.$object->id.
'&action=editincoterm&token='.
newToken().
'">'.
img_edit().
'</a>';
463 print
'</td></tr></table>';
465 print
'<td colspan="3">';
466 if ($action !=
'editincoterm') {
467 print
$form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
469 print
$form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms :
''), (!empty($object->location_incoterms) ? $object->location_incoterms :
''), $_SERVER[
'PHP_SELF'].
'?id='.$object->id);
493 if (!$conf->expedition_bon->enabled && !empty($conf->stock->enabled)) {
496 $entrepot->fetch($object->entrepot_id);
497 print
'<tr><td width="20%">'.$langs->trans(
"Warehouse").
'</td>';
498 print
'<td colspan="3"><a href="'.DOL_URL_ROOT.
'/product/stock/card.php?id='.$entrepot->id.
'">'.$entrepot->label.
'</a></td>';
503 if ($action ==
'create_delivery') {
505 $extrafields->fetch_name_optionals_label($expedition->table_element);
506 if ($expedition->fetch_optionals() > 0) {
507 $object->array_options = array_merge($object->array_options, $expedition->array_options);
511 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
513 print
"</table><br>\n";
521 $num_prod = count($object->lines);
524 print
'<table class="noborder centpercent">';
529 print
'<tr class="liste_titre">';
530 print
'<td>'.$langs->trans(
"Products").
'</td>';
531 print
'<td class="center">'.$langs->trans(
"QtyOrdered").
'</td>';
532 print
'<td class="center">'.$langs->trans(
"QtyReceived").
'</td>';
535 while ($i < $num_prod) {
536 $parameters = array(
'i' => $i,
'line' => $object->lines[$i],
'num' => $num_prod);
537 $reshook = $hookmanager->executeHooks(
'printObjectLine',
$parameters, $object, $action);
542 if (empty($reshook)) {
543 print
'<tr class="oddeven">';
544 if ($object->lines[$i]->fk_product > 0) {
546 $product->fetch($object->lines[$i]->fk_product);
549 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
550 $outputlangs = $langs;
552 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
553 $newlang =
GETPOST(
'lang_id',
'aZ09');
555 if (empty($newlang)) {
556 $newlang = $object->thirdparty->default_lang;
558 if (!empty($newlang)) {
560 $outputlangs->setDefaultLang($newlang);
563 $label = (!empty($product->multilangs[$outputlangs->defaultlang][
"label"])) ? $product->multilangs[$outputlangs->defaultlang][
"label"] : $object->lines[$i]->product_label;
565 $label = (!empty($object->lines[$i]->label) ? $object->lines[$i]->label : $object->lines[$i]->product_label);
571 $text =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$object->lines[$i]->fk_product.
'">';
572 if ($object->lines[$i]->fk_product_type == 1) {
573 $text .=
img_object($langs->trans(
'ShowService'),
'service');
575 $text .=
img_object($langs->trans(
'ShowProduct'),
'product');
577 $text .=
' '.$object->lines[$i]->product_ref.
'</a>';
578 $text .=
' - '.$label;
579 $description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ?
'' :
dol_htmlentitiesbr($object->lines[$i]->description));
581 print
$form->textwithtooltip($text, $description, 3,
'',
'', $i);
582 print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
583 if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) {
584 print (!empty($object->lines[$i]->description) && $object->lines[$i]->description != $object->lines[$i]->product_label) ?
'<br>'.dol_htmlentitiesbr($object->lines[$i]->description) :
'';
588 if ($object->lines[$i]->fk_product_type == 1) {
589 $text =
img_object($langs->trans(
'Service'),
'service');
591 $text =
img_object($langs->trans(
'Product'),
'product');
594 if (!empty($object->lines[$i]->label)) {
595 $text .=
' <strong>'.$object->lines[$i]->label.
'</strong>';
596 print
$form->textwithtooltip($text, $object->lines[$i]->description, 3,
'',
'', $i);
598 print $text.
' '.nl2br($object->lines[$i]->description);
605 print
'<td class="center">'.$object->lines[$i]->qty_asked.
'</td>';
606 print
'<td class="center">'.$object->lines[$i]->qty_shipped.
'</td>';
613 $mode = ($object->statut == 0) ?
'edit' :
'view';
615 $object->lines[$i]->fetch_optionals();
617 if ($action ==
'create_delivery') {
620 $extrafields->fetch_name_optionals_label($srcLine->table_element);
621 $srcLine->id = $expedition->lines[$i]->id;
622 $srcLine->fetch_optionals();
624 $object->lines[$i]->array_options = array_merge($object->lines[$i]->array_options, $srcLine->array_options);
627 $extrafields->fetch_name_optionals_label($srcLine->table_element);
629 print $object->lines[$i]->showOptionals($extrafields, $mode, array(
'style' =>
'class="oddeven"',
'colspan' => $colspan),
'');
650 if ($user->socid == 0) {
651 print
'<div class="tabsAction">';
653 if ($object->statut == 0 && $num_prod > 0) {
654 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer))
655 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) {
656 print
dolGetButtonAction(
'', $langs->trans(
'Validate'),
'default', $_SERVER[
"PHP_SELF"].
'?action=valid&token='.
newToken().
'&id='.$object->id,
'');
660 if ($user->rights->expedition->delivery->supprimer) {
661 if ($conf->expedition_bon->enabled) {
662 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),
'');
664 print
dolGetButtonAction(
'', $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.$object->id,
'');
672 print
'<div class="fichecenter"><div class="fichehalfleft">';
679 $filedir = $conf->expedition->dir_output.
"/receipt/".$objectref;
680 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
682 $genallowed = $user->rights->expedition->delivery->lire;
683 $delallowed = $user->rights->expedition->delivery->creer;
685 print $formfile->showdocuments(
'delivery', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $soc->default_lang);
690 if ($object->origin ==
'expedition') {
692 $shipment->fetch($object->origin_id);
696 $somethingshown =
$form->showLinkedObjectBlock($object,
'');
700 print
'</div><div class="fichehalfright">';
704 print
'</div></div>';
707 print
"Expedition inexistante ou acces refuse";
711 print
"Expedition inexistante ou acces refuse";