card.php 25 KB

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