card.php 27 KB

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