card.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/delivery/card.php
  25. * \ingroup livraison
  26. * \brief Page to describe a delivery receipt
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  35. if (!empty($conf->product->enabled) || !empty($conf->service->enabled))
  36. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  37. if (!empty($conf->expedition_bon->enabled))
  38. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  39. if (!empty($conf->stock->enabled))
  40. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  41. if (!empty($conf->projet->enabled)) {
  42. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  44. }
  45. // Load translation files required by the page
  46. $langs->loadLangs(array("sendings", "bills", 'deliveries', 'orders'));
  47. if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
  48. $action = GETPOST('action', 'aZ09');
  49. $confirm = GETPOST('confirm', 'alpha');
  50. $backtopage = GETPOST('backtopage', 'alpha');
  51. // Security check
  52. $id = GETPOST('id', 'int');
  53. if ($user->socid) $socid = $user->socid;
  54. $result = restrictedArea($user, 'expedition', $id, 'livraison', 'livraison');
  55. $object = new Delivery($db);
  56. $extrafields = new ExtraFields($db);
  57. // fetch optionals attributes and labels
  58. $extrafields->fetch_name_optionals_label($object->table_element);
  59. // fetch optionals attributes lines and labels
  60. $extrafields->fetch_name_optionals_label($object->table_element_line);
  61. // Load object. Make an object->fetch
  62. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  63. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  64. $hookmanager->initHooks(array('deliverycard', 'globalcard'));
  65. /*
  66. * Actions
  67. */
  68. $parameters = array();
  69. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  70. if ($action == 'add')
  71. {
  72. $db->begin();
  73. $object->date_livraison = time();
  74. $object->note = $_POST["note"];
  75. $object->commande_id = $_POST["commande_id"];
  76. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  77. if (!$conf->expedition_bon->enabled && !empty($conf->stock->enabled))
  78. {
  79. $expedition->entrepot_id = $_POST["entrepot_id"];
  80. }
  81. // On boucle sur chaque ligne de commande pour completer objet livraison
  82. // avec qte a livrer
  83. $commande = new Commande($db);
  84. $commande->fetch($object->commande_id);
  85. $commande->fetch_lines();
  86. $num = count($commande->lines);
  87. for ($i = 0; $i < $num; $i++)
  88. {
  89. $qty = "qtyl".$i;
  90. $idl = "idl".$i;
  91. if ($_POST[$qty] > 0)
  92. {
  93. $object->addline($_POST[$idl], $_POST[$qty]);
  94. }
  95. }
  96. $ret = $object->create($user);
  97. if ($ret > 0)
  98. {
  99. $db->commit();
  100. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  101. exit;
  102. } else {
  103. setEventMessages($object->error, $object->errors, 'errors');
  104. $db->rollback();
  105. $_GET["commande_id"] = $_POST["commande_id"];
  106. $action = 'create';
  107. }
  108. } elseif ($action == 'confirm_valid' && $confirm == 'yes' &&
  109. ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->livraison->creer))
  110. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->livraison_advance->validate)))
  111. )
  112. {
  113. $result = $object->valid($user);
  114. // Define output language
  115. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  116. {
  117. $outputlangs = $langs;
  118. $newlang = '';
  119. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
  120. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  121. if (!empty($newlang)) {
  122. $outputlangs = new Translate("", $conf);
  123. $outputlangs->setDefaultLang($newlang);
  124. }
  125. $model = $object->model_pdf;
  126. $ret = $object->fetch($id); // Reload to get new records
  127. $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  128. if ($result < 0) dol_print_error($db, $result);
  129. }
  130. }
  131. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->livraison->supprimer)
  132. {
  133. $db->begin();
  134. $result = $object->delete();
  135. if ($result > 0)
  136. {
  137. $db->commit();
  138. if (!empty($backtopage)) header("Location: ".$backtopage);
  139. else header("Location: ".DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1');
  140. exit;
  141. } else {
  142. $db->rollback();
  143. }
  144. }
  145. if ($action == 'setdate_livraison' && $user->rights->expedition->livraison->creer)
  146. {
  147. $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));
  148. $result = $object->set_delivery_date($user, $datedelivery);
  149. if ($result < 0)
  150. {
  151. $mesg = '<div class="error">'.$object->error.'</div>';
  152. }
  153. }
  154. // Set incoterm
  155. elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
  156. {
  157. $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
  158. }
  159. // Update extrafields
  160. if ($action == 'update_extras')
  161. {
  162. $object->oldcopy = dol_clone($object);
  163. // Fill array 'array_options' with data from update form
  164. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  165. if ($ret < 0) $error++;
  166. if (!$error)
  167. {
  168. // Actions on extra fields
  169. $result = $object->insertExtraFields('DELIVERY_MODIFY');
  170. if ($result < 0)
  171. {
  172. setEventMessages($object->error, $object->errors, 'errors');
  173. $error++;
  174. }
  175. }
  176. if ($error)
  177. $action = 'edit_extras';
  178. }
  179. // Extrafields line
  180. if ($action == 'update_extras_line')
  181. {
  182. $array_options = array();
  183. $num = count($object->lines);
  184. for ($i = 0; $i < $num; $i++)
  185. {
  186. // Extrafields
  187. $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
  188. $array_options[$i] = $extrafields->getOptionalsFromPost($extralabelsline, $i);
  189. // Unset extrafield
  190. if (is_array($extralabelsline)) {
  191. // Get extra fields
  192. foreach ($extralabelsline as $key => $value) {
  193. unset($_POST["options_".$key]);
  194. }
  195. }
  196. $ret = $object->update_line($object->lines[$i]->id, $array_options[$i]); // extrafields update
  197. if ($ret < 0)
  198. {
  199. $mesg = '<div class="error">'.$object->error.'</div>';
  200. $error++;
  201. }
  202. }
  203. }
  204. // Actions to build doc
  205. $upload_dir = $conf->expedition->dir_output.'/receipt';
  206. $permissiontoadd = $user->rights->expedition->creer;
  207. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  208. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  209. /*
  210. * View
  211. */
  212. llxHeader('', $langs->trans('Delivery'), 'Livraison');
  213. $form = new Form($db);
  214. $formfile = new FormFile($db);
  215. if ($action == 'create') // Create. Seems to no be used
  216. {
  217. } else // View
  218. {
  219. if ($object->id > 0)
  220. {
  221. // Origin of a 'livraison' (delivery receipt) is ALWAYS 'expedition' (shipment).
  222. // However, origin of shipment in future may differs (commande, proposal, ...)
  223. $expedition = new Expedition($db);
  224. $result = $expedition->fetch($object->origin_id);
  225. $typeobject = $expedition->origin; // example: commande
  226. if ($object->origin_id > 0)
  227. {
  228. $object->fetch_origin();
  229. }
  230. if ($object->id > 0)
  231. {
  232. $soc = new Societe($db);
  233. $soc->fetch($object->socid);
  234. $head = delivery_prepare_head($object);
  235. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  236. print '<input type="hidden" name="token" value="'.newToken().'">';
  237. print '<input type="hidden" name="action" value="update_extras_line">';
  238. print '<input type="hidden" name="origin" value="'.$origin.'">';
  239. print '<input type="hidden" name="id" value="'.$object->id.'">';
  240. print '<input type="hidden" name="ref" value="'.$object->ref.'">';
  241. dol_fiche_head($head, 'delivery', $langs->trans("Shipment"), -1, 'sending');
  242. /*
  243. * Confirmation de la suppression
  244. *
  245. */
  246. if ($action == 'delete')
  247. {
  248. $expedition_id = GETPOST("expid");
  249. 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);
  250. }
  251. /*
  252. * Confirmation de la validation
  253. */
  254. if ($action == 'valid')
  255. {
  256. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidateDeliveryReceipt"), $langs->trans("ValidateDeliveryReceiptConfirm", $object->ref), 'confirm_valid', '', '', 1);
  257. }
  258. /*
  259. * Delivery
  260. */
  261. if ($typeobject == 'commande' && $expedition->origin_id > 0 && !empty($conf->commande->enabled))
  262. {
  263. $objectsrc = new Commande($db);
  264. $objectsrc->fetch($expedition->origin_id);
  265. }
  266. if ($typeobject == 'propal' && $expedition->origin_id > 0 && !empty($conf->propal->enabled))
  267. {
  268. $objectsrc = new Propal($db);
  269. $objectsrc->fetch($expedition->origin_id);
  270. }
  271. // Shipment card
  272. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  273. $morehtmlref = '<div class="refidno">';
  274. // Ref customer shipment
  275. $morehtmlref .= $form->editfieldkey("RefCustomer", '', $expedition->ref_customer, $expedition, $user->rights->expedition->creer, 'string', '', 0, 1);
  276. $morehtmlref .= $form->editfieldval("RefCustomer", '', $expedition->ref_customer, $expedition, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
  277. $morehtmlref .= '<br>'.$langs->trans("RefDeliveryReceipt").' : '.$object->ref;
  278. // Thirdparty
  279. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$expedition->thirdparty->getNomUrl(1);
  280. // Project
  281. if (!empty($conf->projet->enabled)) {
  282. $langs->load("projects");
  283. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  284. if (0) { // Do not change on shipment
  285. if ($action != 'classify') {
  286. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$expedition->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  287. }
  288. if ($action == 'classify') {
  289. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $expedition->id, $expedition->socid, $expedition->fk_project, 'projectid', 0, 0, 1, 1);
  290. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$expedition->id.'">';
  291. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  292. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  293. $morehtmlref .= $formproject->select_projects($expedition->socid, $expedition->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  294. $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  295. $morehtmlref .= '</form>';
  296. } else {
  297. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$expedition->id, $expedition->socid, $expedition->fk_project, 'none', 0, 0, 0, 1);
  298. }
  299. } else {
  300. $morehtmlref .= ' : ';
  301. if (!empty($objectsrc->fk_project)) {
  302. $proj = new Project($db);
  303. $proj->fetch($objectsrc->fk_project);
  304. $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
  305. $morehtmlref .= $proj->ref;
  306. $morehtmlref .= '</a>';
  307. } else {
  308. $morehtmlref .= '';
  309. }
  310. }
  311. }
  312. $morehtmlref .= '</div>';
  313. $morehtmlright = $langs->trans("StatusReceipt").' : '.$object->getLibStatut(6).'<br>';
  314. dol_banner_tab($expedition, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
  315. print '<div class="fichecenter">';
  316. print '<div class="underbanner clearboth"></div>';
  317. print '<table class="border tableforfield" width="100%">';
  318. // Shipment
  319. /*
  320. if (($object->origin == 'shipment' || $object->origin == 'expedition') && $object->origin_id > 0)
  321. {
  322. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  323. // Ref
  324. print '<tr><td width="20%">'.$langs->trans("RefSending").'</td>';
  325. print '<td colspan="3">';
  326. // 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)
  327. //print $form->showrefnav($expedition, 'refshipment', $linkback, 1, 'ref', 'ref');
  328. print $form->showrefnav($expedition, 'refshipment', $linkback, 0, 'ref', 'ref');
  329. print '</td></tr>';
  330. }
  331. // Ref
  332. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  333. print '<td colspan="3">';
  334. print $object->ref;
  335. print '</td></tr>';
  336. // Client
  337. print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
  338. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  339. print "</tr>";
  340. */
  341. // Document origine
  342. if ($typeobject == 'commande' && $expedition->origin_id && !empty($conf->commande->enabled))
  343. {
  344. print '<tr><td class="titlefield">'.$langs->trans("RefOrder").'</td>';
  345. $order = new Commande($db);
  346. $order->fetch($expedition->origin_id);
  347. print '<td colspan="3">';
  348. print $order->getNomUrl(1, 'commande');
  349. print "</td>\n";
  350. print '</tr>';
  351. }
  352. if ($typeobject == 'propal' && $expedition->origin_id && !empty($conf->propal->enabled))
  353. {
  354. $propal = new Propal($db);
  355. $propal->fetch($expedition->origin_id);
  356. print '<tr><td class="titlefield">'.$langs->trans("RefProposal").'</td>';
  357. print '<td colspan="3">';
  358. print $propal->getNomUrl(1, 'expedition');
  359. print "</td>\n";
  360. print '</tr>';
  361. }
  362. // Date
  363. print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
  364. print '<td colspan="3">'.dol_print_date($object->date_creation, 'dayhour')."</td>\n";
  365. print '</tr>';
  366. // Date delivery real / Received
  367. print '<tr><td height="10">';
  368. print '<table class="nobordernopadding" width="100%"><tr><td>';
  369. print $langs->trans('DateReceived');
  370. print '</td>';
  371. if ($action != 'editdate_livraison') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
  372. print '</tr></table>';
  373. print '</td><td colspan="2">';
  374. if ($action == 'editdate_livraison')
  375. {
  376. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  377. print '<input type="hidden" name="token" value="'.newToken().'">';
  378. print '<input type="hidden" name="action" value="setdate_livraison">';
  379. print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 1);
  380. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  381. print '</form>';
  382. } else {
  383. print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
  384. }
  385. print '</td>';
  386. print '</tr>';
  387. // Incoterms
  388. if (!empty($conf->incoterm->enabled))
  389. {
  390. print '<tr><td>';
  391. print '<table width="100%" class="nobordernopadding"><tr><td>';
  392. print $langs->trans('IncotermLabel');
  393. print '<td><td class="right">';
  394. if ($user->rights->expedition->livraison->creer) print '<a class="editfielda" href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
  395. else print '&nbsp;';
  396. print '</td></tr></table>';
  397. print '</td>';
  398. print '<td colspan="3">';
  399. if ($action != 'editincoterm')
  400. {
  401. print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
  402. } else {
  403. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
  404. }
  405. print '</td></tr>';
  406. }
  407. /* A delivery note should be just more properties of a shipment, so notes are on shipment
  408. // Note Public
  409. print '<tr><td>'.$langs->trans("NotePublic").'</td>';
  410. print '<td colspan="3">';
  411. print nl2br($object->note_public);
  412. print "</td></tr>";
  413. // Note Private
  414. print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
  415. print '<td colspan="3">';
  416. print nl2br($object->note_private);
  417. print "</td></tr>";
  418. */
  419. // Statut
  420. /*print '<tr><td>'.$langs->trans("Status").'</td>';
  421. print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
  422. print '</tr>';*/
  423. if (!$conf->expedition_bon->enabled && !empty($conf->stock->enabled))
  424. {
  425. // Entrepot
  426. $entrepot = new Entrepot($db);
  427. $entrepot->fetch($object->entrepot_id);
  428. print '<tr><td width="20%">'.$langs->trans("Warehouse").'</td>';
  429. print '<td colspan="3"><a href="'.DOL_URL_ROOT.'/product/stock/card.php?id='.$entrepot->id.'">'.$entrepot->label.'</a></td>';
  430. print '</tr>';
  431. }
  432. // Other attributes
  433. if ($action == 'create_delivery') {
  434. // copy from expedition
  435. $extrafields->fetch_name_optionals_label($expedition->table_element);
  436. if ($expedition->fetch_optionals() > 0) {
  437. $object->array_options = array_merge($object->array_options, $expedition->array_options);
  438. }
  439. }
  440. $cols = 2;
  441. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  442. print "</table><br>\n";
  443. print '</div>';
  444. /*
  445. * Products lines
  446. */
  447. $num_prod = count($object->lines);
  448. $i = 0; $total = 0;
  449. print '<table class="noborder centpercent">';
  450. if ($num_prod)
  451. {
  452. $i = 0;
  453. print '<tr class="liste_titre">';
  454. print '<td>'.$langs->trans("Products").'</td>';
  455. print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
  456. print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
  457. print "</tr>\n";
  458. }
  459. while ($i < $num_prod)
  460. {
  461. $parameters = array('i' => $i, 'line' => $object->lines[$i], 'num' => $num_prod);
  462. $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);
  463. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  464. if (empty($reshook))
  465. {
  466. print '<tr class="oddeven">';
  467. if ($object->lines[$i]->fk_product > 0)
  468. {
  469. $product = new Product($db);
  470. $product->fetch($object->lines[$i]->fk_product);
  471. // Define output language
  472. if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  473. {
  474. $outputlangs = $langs;
  475. $newlang = '';
  476. if (empty($newlang) && !empty($_REQUEST['lang_id'])) $newlang = $_REQUEST['lang_id'];
  477. if (empty($newlang)) $newlang = $object->thirdparty->default_lang;
  478. if (!empty($newlang))
  479. {
  480. $outputlangs = new Translate("", $conf);
  481. $outputlangs->setDefaultLang($newlang);
  482. }
  483. $label = (!empty($product->multilangs[$outputlangs->defaultlang]["label"])) ? $product->multilangs[$outputlangs->defaultlang]["label"] : $object->lines[$i]->product_label;
  484. } else {
  485. $label = (!empty($object->lines[$i]->label) ? $object->lines[$i]->label : $object->lines[$i]->product_label);
  486. }
  487. print '<td>';
  488. // Affiche ligne produit
  489. $text = '<a href="'.DOL_URL_ROOT.'/product/card.php?id='.$object->lines[$i]->fk_product.'">';
  490. if ($object->lines[$i]->fk_product_type == 1) $text .= img_object($langs->trans('ShowService'), 'service');
  491. else $text .= img_object($langs->trans('ShowProduct'), 'product');
  492. $text .= ' '.$object->lines[$i]->product_ref.'</a>';
  493. $text .= ' - '.$label;
  494. $description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($object->lines[$i]->description));
  495. //print $description;
  496. print $form->textwithtooltip($text, $description, 3, '', '', $i);
  497. print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
  498. if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
  499. {
  500. print (!empty($object->lines[$i]->description) && $object->lines[$i]->description != $object->lines[$i]->product_label) ? '<br>'.dol_htmlentitiesbr($object->lines[$i]->description) : '';
  501. }
  502. } else {
  503. print "<td>";
  504. if ($object->lines[$i]->fk_product_type == 1) $text = img_object($langs->trans('Service'), 'service');
  505. else $text = img_object($langs->trans('Product'), 'product');
  506. if (!empty($object->lines[$i]->label)) {
  507. $text .= ' <strong>'.$object->lines[$i]->label.'</strong>';
  508. print $form->textwithtooltip($text, $object->lines[$i]->description, 3, '', '', $i);
  509. } else {
  510. print $text.' '.nl2br($object->lines[$i]->description);
  511. }
  512. print_date_range($objp->date_start, $objp->date_end);
  513. print "</td>\n";
  514. }
  515. print '<td class="center">'.$object->lines[$i]->qty_asked.'</td>';
  516. print '<td class="center">'.$object->lines[$i]->qty_shipped.'</td>';
  517. print "</tr>";
  518. // Display lines extrafields
  519. if (!empty($extrafields)) {
  520. $colspan = 2;
  521. $mode = ($object->statut == 0) ? 'edit' : 'view';
  522. $object->lines[$i]->fetch_optionals();
  523. if ($action == 'create_delivery') {
  524. $srcLine = new ExpeditionLigne($db);
  525. $extrafields->fetch_name_optionals_label($srcLine->table_element);
  526. $srcLine->id = $expedition->lines[$i]->id;
  527. $srcLine->fetch_optionals();
  528. $object->lines[$i]->array_options = array_merge($object->lines[$i]->array_options, $srcLine->array_options);
  529. }
  530. print $object->lines[$i]->showOptionals($extrafields, $mode, array('style' => 'class="oddeven"', 'colspan' => $colspan), $i);
  531. }
  532. }
  533. $i++;
  534. }
  535. print "</table>\n";
  536. dol_fiche_end();
  537. //if ($object->statut == 0) // only if draft
  538. // print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></div>';
  539. print '</form>';
  540. /*
  541. * Boutons actions
  542. */
  543. if ($user->socid == 0)
  544. {
  545. print '<div class="tabsAction">';
  546. if ($object->statut == 0 && $num_prod > 0)
  547. {
  548. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->livraison->creer))
  549. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->livraison_advance->validate)))
  550. {
  551. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
  552. }
  553. }
  554. if ($user->rights->expedition->livraison->supprimer)
  555. {
  556. if ($conf->expedition_bon->enabled)
  557. {
  558. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;expid='.$object->origin_id.'&amp;action=delete&amp;token='.newToken().'&amp;backtopage='.urlencode(DOL_URL_ROOT.'/expedition/card.php?id='.$object->origin_id).'">'.$langs->trans("Delete").'</a>';
  559. } else {
  560. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans("Delete").'</a>';
  561. }
  562. }
  563. print '</div>';
  564. }
  565. print "\n";
  566. print '<table width="100%" cellspacing="2"><tr><td width="50%" valign="top">';
  567. /*
  568. * Documents generated
  569. */
  570. $objectref = dol_sanitizeFileName($object->ref);
  571. $filedir = $conf->expedition->dir_output."/receipt/".$objectref;
  572. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  573. $genallowed = $user->rights->expedition->livraison->lire;
  574. $delallowed = $user->rights->expedition->livraison->creer;
  575. print $formfile->showdocuments('livraison', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  576. /*
  577. * Linked object block (of linked shipment)
  578. */
  579. if ($object->origin == 'expedition')
  580. {
  581. $shipment = new Expedition($db);
  582. $shipment->fetch($object->origin_id);
  583. // Show links to link elements
  584. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
  585. $somethingshown = $form->showLinkedObjectBlock($object, '');
  586. }
  587. print '</td><td valign="top" width="50%">';
  588. // Rien a droite
  589. print '</td></tr></table>';
  590. } else {
  591. /* Expedition non trouvee */
  592. print "Expedition inexistante ou acces refuse";
  593. }
  594. } else {
  595. /* Expedition non trouvee */
  596. print "Expedition inexistante ou acces refuse";
  597. }
  598. }
  599. // End of page
  600. llxFooter();
  601. $db->close();