card.php 28 KB

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