card.php 26 KB

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