card.php 26 KB

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