PageRenderTime 56ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/expedition/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1487 lines | 1090 code | 195 blank | 202 comment | 297 complexity | abf76e5e257b6904cd760bc6dedaec35 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* Copyright (C) 2003-2008 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-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/expedition/fiche.php
  23. * \ingroup expedition
  24. * \brief Fiche descriptive d'une expedition
  25. */
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  33. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  34. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  35. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  36. if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  37. $langs->load("sendings");
  38. $langs->load("companies");
  39. $langs->load("bills");
  40. $langs->load('deliveries');
  41. $langs->load('orders');
  42. $langs->load('stocks');
  43. $langs->load('other');
  44. $langs->load('propal');
  45. $origin = GETPOST('origin','alpha')?GETPOST('origin','alpha'):'expedition'; // Example: commande, propal
  46. $origin_id = GETPOST('id','int')?GETPOST('id','int'):'';
  47. if (empty($origin_id)) $origin_id = GETPOST('origin_id','int'); // Id of order or propal
  48. if (empty($origin_id)) $origin_id = GETPOST('object_id','int'); // Id of order or propal
  49. $id = $origin_id;
  50. $ref=GETPOST('ref','alpha');
  51. // Security check
  52. if ($user->societe_id) $socid=$user->societe_id;
  53. $result=restrictedArea($user,$origin,$origin_id);
  54. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  55. $hookmanager->initHooks(array('expeditioncard'));
  56. $action = GETPOST('action','alpha');
  57. $confirm = GETPOST('confirm','alpha');
  58. //PDF
  59. $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  60. $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  61. $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  62. $object = new Expedition($db);
  63. /*
  64. * Actions
  65. */
  66. if ($action == 'add')
  67. {
  68. $error=0;
  69. $db->begin();
  70. $object->note = GETPOST('note','alpha');
  71. $object->origin = $origin;
  72. $object->origin_id = $origin_id;
  73. $object->weight = GETPOST('weight','int')==''?"NULL":GETPOST('weight','int');
  74. $object->sizeH = GETPOST('sizeH','int')==''?"NULL":GETPOST('sizeH','int');
  75. $object->sizeW = GETPOST('sizeW','int')==''?"NULL":GETPOST('sizeW','int');
  76. $object->sizeS = GETPOST('sizeS','int')==''?"NULL":GETPOST('sizeS','int');
  77. $object->size_units = GETPOST('size_units','int');
  78. $object->weight_units = GETPOST('weight_units','int');
  79. $date_delivery = dol_mktime(GETPOST('date_deliveryhour','int'), GETPOST('date_deliverymin','int'), 0, GETPOST('date_deliverymonth','int'), GETPOST('date_deliveryday','int'), GETPOST('date_deliveryyear','int'));
  80. // On va boucler sur chaque ligne du document d'origine pour completer objet expedition
  81. // avec info diverses + qte a livrer
  82. $classname = ucfirst($object->origin);
  83. $objectsrc = new $classname($db);
  84. $objectsrc->fetch($object->origin_id);
  85. //$object->fetch_lines();
  86. $object->socid = $objectsrc->socid;
  87. $object->ref_customer = $objectsrc->ref_client;
  88. $object->date_delivery = $date_delivery; // Date delivery planed
  89. $object->fk_delivery_address = $objectsrc->fk_delivery_address;
  90. $object->expedition_method_id = GETPOST('expedition_method_id','int');
  91. $object->tracking_number = GETPOST('tracking_number','alpha');
  92. $object->ref_int = GETPOST('ref_int','alpha');
  93. $num=count($objectsrc->lines);
  94. $totalqty=0;
  95. for ($i = 0; $i < $num; $i++)
  96. {
  97. $qty = "qtyl".$i;
  98. if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int');
  99. }
  100. if ($totalqty > 0)
  101. {
  102. //var_dump($_POST);exit;
  103. for ($i = 0; $i < $num; $i++)
  104. {
  105. $qty = "qtyl".$i;
  106. if (GETPOST($qty,'int') > 0)
  107. {
  108. $ent = "entl".$i;
  109. $idl = "idl".$i;
  110. $entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int');
  111. if ($entrepot_id < 0) $entrepot_id='';
  112. $ret=$object->addline($entrepot_id,GETPOST($idl,'int'),GETPOST($qty,'int'));
  113. if ($ret < 0)
  114. {
  115. $mesg='<div class="error">'.$object->error.'</div>';
  116. $error++;
  117. }
  118. }
  119. }
  120. if (! $error)
  121. {
  122. $ret=$object->create($user);
  123. if ($ret <= 0)
  124. {
  125. $mesg='<div class="error">'.$object->error.'</div>';
  126. $error++;
  127. }
  128. }
  129. }
  130. else
  131. {
  132. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Qty")).'</div>';
  133. $error++;
  134. }
  135. if (! $error)
  136. {
  137. $db->commit();
  138. header("Location: fiche.php?id=".$object->id);
  139. exit;
  140. }
  141. else
  142. {
  143. $db->rollback();
  144. $_GET["commande_id"]=GETPOST('commande_id','int');
  145. $action='create';
  146. }
  147. }
  148. /*
  149. * Build a receiving receipt
  150. */
  151. else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
  152. {
  153. $object->fetch($id);
  154. $result = $object->create_delivery($user);
  155. if ($result > 0)
  156. {
  157. header("Location: ".DOL_URL_ROOT.'/livraison/fiche.php?id='.$result);
  158. exit;
  159. }
  160. else
  161. {
  162. $mesg=$object->error;
  163. }
  164. }
  165. else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider)
  166. {
  167. $object->fetch($id);
  168. $object->fetch_thirdparty();
  169. $result = $object->valid($user);
  170. // Define output language
  171. $outputlangs = $langs;
  172. $newlang='';
  173. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
  174. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  175. if (! empty($newlang))
  176. {
  177. $outputlangs = new Translate();
  178. $outputlangs->setDefaultLang($newlang);
  179. }
  180. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  181. {
  182. $ret=$object->fetch($id); // Reload to get new records
  183. $result=expedition_pdf_create($db,$object,$object->modelpdf,$outputlangs);
  184. }
  185. if ($result < 0)
  186. {
  187. dol_print_error($db,$result);
  188. exit;
  189. }
  190. }
  191. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)
  192. {
  193. $object->fetch($id);
  194. $object->fetch_thirdparty();
  195. $result = $object->delete();
  196. if ($result > 0)
  197. {
  198. header("Location: ".DOL_URL_ROOT.'/expedition/index.php');
  199. exit;
  200. }
  201. else
  202. {
  203. $mesg = $object->error;
  204. }
  205. }
  206. else if ($action == 'reopen' && $user->rights->expedition->valider)
  207. {
  208. $object->fetch($id);
  209. $result = $object->setStatut(0);
  210. if ($result < 0)
  211. {
  212. $mesg = $object->error;
  213. }
  214. }
  215. else if ($action == 'setdate_livraison' && $user->rights->expedition->creer)
  216. {
  217. //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
  218. $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
  219. $object->fetch($id);
  220. $result=$object->set_date_livraison($user,$datedelivery);
  221. if ($result < 0)
  222. {
  223. $mesg='<div class="error">'.$object->error.'</div>';
  224. }
  225. }
  226. // Action update description of emailing
  227. else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
  228. || $action == 'settrueWeight'
  229. || $action == 'settrueWidth'
  230. || $action == 'settrueHeight'
  231. || $action == 'settrueDepth'
  232. || $action == 'setexpedition_method_id')
  233. {
  234. $error=0;
  235. $shipping = new Expedition($db);
  236. $result=$shipping->fetch($id);
  237. if ($result < 0) dol_print_error($db,$shipping->error);
  238. if ($action == 'settrackingnumber') $shipping->tracking_number = trim(GETPOST('trackingnumber','alpha'));
  239. if ($action == 'settrackingurl') $shipping->tracking_url = trim(GETPOST('trackingurl','int'));
  240. if ($action == 'settrueWeight') $shipping->trueWeight = trim(GETPOST('trueWeight','int'));
  241. if ($action == 'settrueWidth') $shipping->trueWidth = trim(GETPOST('trueWidth','int'));
  242. if ($action == 'settrueHeight') $shipping->trueHeight = trim(GETPOST('trueHeight','int'));
  243. if ($action == 'settrueDepth') $shipping->trueDepth = trim(GETPOST('trueDepth','int'));
  244. if ($action == 'setexpedition_method_id') $shipping->expedition_method_id = trim(GETPOST('expedition_method_id','int'));
  245. if (! $error)
  246. {
  247. if ($shipping->update($user) >= 0)
  248. {
  249. header("Location: fiche.php?id=".$shipping->id);
  250. exit;
  251. }
  252. $mesg=$shipping->error;
  253. }
  254. $mesg='<div class="error">'.$mesg.'</div>';
  255. $action="";
  256. }
  257. // Build document
  258. else if ($action == 'builddoc') // En get ou en post
  259. {
  260. // Sauvegarde le dernier modele choisi pour generer un document
  261. $shipment = new Expedition($db);
  262. $shipment->fetch($id);
  263. $shipment->fetch_thirdparty();
  264. if (GETPOST('model','alpha'))
  265. {
  266. $shipment->setDocModel($user, GETPOST('model','alpha'));
  267. }
  268. // Define output language
  269. $outputlangs = $langs;
  270. $newlang='';
  271. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
  272. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$shipment->client->default_lang;
  273. if (! empty($newlang))
  274. {
  275. $outputlangs = new Translate();
  276. $outputlangs->setDefaultLang($newlang);
  277. }
  278. $result=expedition_pdf_create($db,$shipment,GETPOST('model','alpha'),$outputlangs);
  279. if ($result <= 0)
  280. {
  281. dol_print_error($db,$result);
  282. exit;
  283. }
  284. }
  285. // Delete file in doc form
  286. elseif ($action == 'remove_file')
  287. {
  288. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  289. $object = new Expedition($db);
  290. if ($object->fetch($id))
  291. {
  292. $object->fetch_thirdparty();
  293. $upload_dir = $conf->expedition->dir_output . "/sending";
  294. $file = $upload_dir . '/' . GETPOST('file');
  295. $ret=dol_delete_file($file,0,0,0,$object);
  296. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  297. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  298. }
  299. }
  300. /*
  301. * Add file in email form
  302. */
  303. if (GETPOST('addfile','alpha'))
  304. {
  305. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  306. // Set tmp user directory TODO Use a dedicated directory for temp mails files
  307. $vardir=$conf->user->dir_output."/".$user->id;
  308. $upload_dir_tmp = $vardir.'/temp';
  309. dol_add_file_process($upload_dir_tmp,0,0);
  310. $action ='presend';
  311. }
  312. /*
  313. * Remove file in email form
  314. */
  315. if (GETPOST('removedfile','alpha'))
  316. {
  317. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  318. // Set tmp user directory
  319. $vardir=$conf->user->dir_output."/".$user->id;
  320. $upload_dir_tmp = $vardir.'/temp';
  321. // TODO Delete only files that was uploaded from email form
  322. dol_remove_file_process(GETPOST('removedfile','int'),0);
  323. $action ='presend';
  324. }
  325. /*
  326. * Send mail
  327. */
  328. if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile','alpha') && ! GETPOST('cancel','alpha'))
  329. {
  330. $langs->load('mails');
  331. $result=$object->fetch($id);
  332. $result=$object->fetch_thirdparty();
  333. if ($result > 0)
  334. {
  335. // $ref = dol_sanitizeFileName($object->ref);
  336. // $file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf';
  337. // if (is_readable($file))
  338. // {
  339. if (GETPOST('sendto','alpha'))
  340. {
  341. // Le destinataire a ete fourni via le champ libre
  342. $sendto = GETPOST('sendto','alpha');
  343. $sendtoid = 0;
  344. }
  345. elseif (GETPOST('receiver','alpha') != '-1')
  346. {
  347. // Recipient was provided from combo list
  348. if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
  349. {
  350. $sendto = $object->client->email;
  351. $sendtoid = 0;
  352. }
  353. else // Id du contact
  354. {
  355. $sendto = $object->client->contact_get_property(GETPOST('receiver','alpha'),'email');
  356. $sendtoid = GETPOST('receiver','alpha');
  357. }
  358. }
  359. if (dol_strlen($sendto))
  360. {
  361. $langs->load("commercial");
  362. $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
  363. $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
  364. $message = GETPOST('message','alpha');
  365. $sendtocc = GETPOST('sendtocc','alpha');
  366. $deliveryreceipt = GETPOST('deliveryreceipt','alpha');
  367. if ($action == 'send')
  368. {
  369. if (dol_strlen(GETPOST('subject','alpha'))) $subject=GETPOST('subject','alpha');
  370. else $subject = $langs->transnoentities('Shipping').' '.$object->ref;
  371. $actiontypecode='AC_SHIP';
  372. $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
  373. if ($message)
  374. {
  375. $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
  376. $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
  377. $actionmsg.=$message;
  378. }
  379. $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
  380. }
  381. // Create form object
  382. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  383. $formmail = new FormMail($db);
  384. $attachedfiles=$formmail->get_attached_files();
  385. $filepath = $attachedfiles['paths'];
  386. $filename = $attachedfiles['names'];
  387. $mimetype = $attachedfiles['mimes'];
  388. // Send mail
  389. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  390. $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
  391. if ($mailfile->error)
  392. {
  393. $mesg='<div class="error">'.$mailfile->error.'</div>';
  394. }
  395. else
  396. {
  397. $result=$mailfile->sendfile();
  398. if ($result)
  399. {
  400. $error=0;
  401. // Initialisation donnees
  402. $object->sendtoid = $sendtoid;
  403. $object->actiontypecode = $actiontypecode;
  404. $object->actionmsg = $actionmsg;
  405. $object->actionmsg2 = $actionmsg2;
  406. $object->fk_element = $object->id;
  407. $object->elementtype = $object->element;
  408. // Appel des triggers
  409. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  410. $interface=new Interfaces($db);
  411. $result=$interface->run_triggers('SHIPPING_SENTBYMAIL',$object,$user,$langs,$conf);
  412. if ($result < 0) {
  413. $error++; $this->errors=$interface->errors;
  414. }
  415. // Fin appel triggers
  416. if ($error)
  417. {
  418. dol_print_error($db);
  419. }
  420. else
  421. {
  422. // Redirect here
  423. // This avoid sending mail twice if going out and then back to page
  424. $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
  425. setEventMessage($mesg);
  426. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  427. exit;
  428. }
  429. }
  430. else
  431. {
  432. $langs->load("other");
  433. $mesg='<div class="error">';
  434. if ($mailfile->error)
  435. {
  436. $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
  437. $mesg.='<br>'.$mailfile->error;
  438. }
  439. else
  440. {
  441. $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  442. }
  443. $mesg.='</div>';
  444. }
  445. }
  446. }
  447. else
  448. {
  449. $langs->load("other");
  450. $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
  451. $action='presend';
  452. dol_syslog('Recipient email is empty');
  453. }
  454. /* }
  455. else
  456. {
  457. $langs->load("errors");
  458. $mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
  459. dol_syslog('Failed to read file: '.$file);
  460. }*/
  461. }
  462. else
  463. {
  464. $langs->load("other");
  465. $mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Shipping")).'</div>';
  466. dol_syslog($langs->trans('ErrorFailedToReadEntity',$langs->trans("Shipping")));
  467. }
  468. }
  469. else if ($action == 'classifybilled')
  470. {
  471. $object->fetch($id);
  472. $object->set_billed();
  473. }
  474. /*
  475. * View
  476. */
  477. llxHeader('',$langs->trans('Sending'),'Expedition');
  478. $form = new Form($db);
  479. $formfile = new FormFile($db);
  480. $formproduct = new FormProduct($db);
  481. $product_static = new Product($db);
  482. if ($action == 'create2')
  483. {
  484. print_fiche_titre($langs->trans("CreateASending")).'<br>';
  485. print $langs->trans("ShipmentCreationIsDoneFromOrder");
  486. $action=''; $id=''; $ref='';
  487. }
  488. // Mode creation
  489. if ($action == 'create')
  490. {
  491. $expe = new Expedition($db);
  492. print_fiche_titre($langs->trans("CreateASending"));
  493. if (! $origin)
  494. {
  495. $mesg='<div class="error">'.$langs->trans("ErrorBadParameters").'</div>';
  496. }
  497. dol_htmloutput_mesg($mesg);
  498. if ($origin)
  499. {
  500. $classname = ucfirst($origin);
  501. $object = new $classname($db);
  502. if ($object->fetch($origin_id)) // This include the fetch_lines
  503. {
  504. //var_dump($object);
  505. $soc = new Societe($db);
  506. $soc->fetch($object->socid);
  507. $author = new User($db);
  508. $author->fetch($object->user_author_id);
  509. if (! empty($conf->stock->enabled)) $entrepot = new Entrepot($db);
  510. /*
  511. * Document source
  512. */
  513. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  514. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  515. print '<input type="hidden" name="action" value="add">';
  516. print '<input type="hidden" name="origin" value="'.$origin.'">';
  517. print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
  518. print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';
  519. if (GETPOST('entrepot_id','int'))
  520. {
  521. print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id','int').'">';
  522. }
  523. print '<table class="border" width="100%">';
  524. // Ref
  525. print '<tr><td width="30%" class="fieldrequired">';
  526. if ($origin == 'commande' && ! empty($conf->commande->enabled))
  527. {
  528. print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$object->ref;
  529. }
  530. if ($origin == 'propal' && ! empty($conf->propal->enabled))
  531. {
  532. print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/fiche.php?id='.$object->id.'">'.img_object($langs->trans("ShowProposal"),'propal').' '.$object->ref;
  533. }
  534. print '</a></td>';
  535. print "</tr>\n";
  536. // Ref client
  537. print '<tr><td>';
  538. print $langs->trans('RefCustomer').'</td><td colspan="3">';
  539. print $object->ref_client;
  540. print '</td>';
  541. print '</tr>';
  542. // Tiers
  543. print '<tr><td class="fieldrequired">'.$langs->trans('Company').'</td>';
  544. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  545. print '</tr>';
  546. // Date delivery planned
  547. print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
  548. print '<td colspan="3">';
  549. //print dol_print_date($object->date_livraison,"day"); // date_livraison come from order and will be stored into date_delivery planed.
  550. print $form->select_date($object->date_livraison?$object->date_livraison:-1,'date_delivery',1,1);
  551. print "</td>\n";
  552. print '</tr>';
  553. // Note
  554. if ($object->note && ! $user->societe_id)
  555. {
  556. print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
  557. print '<td colspan="3">'.nl2br($object->note)."</td></tr>";
  558. }
  559. // Weight
  560. print '<tr><td>';
  561. print $langs->trans("Weight");
  562. print '</td><td><input name="weight" size="4" value="'.GETPOST('weight','int').'"></td><td>';
  563. print $formproduct->select_measuring_units("weight_units","weight",GETPOST('weight_units','int'));
  564. print '</td></tr><tr><td>';
  565. print $langs->trans("Width");
  566. print ' </td><td><input name="sizeW" size="4" value="'.GETPOST('sizeW','int').'"></td><td rowspan="3">';
  567. print $formproduct->select_measuring_units("size_units","size");
  568. print '</td></tr><tr><td>';
  569. print $langs->trans("Height");
  570. print '</td><td><input name="sizeH" size="4" value="'.GETPOST('sizeH','int').'"></td>';
  571. print '</tr><tr><td>';
  572. print $langs->trans("Depth");
  573. print '</td><td><input name="sizeS" size="4" value="'.GETPOST('sizeS','int').'"></td>';
  574. print '</tr>';
  575. // Delivery method
  576. print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";
  577. print '<td colspan="3">';
  578. $expe->fetch_delivery_methods();
  579. print $form->selectarray("expedition_method_id",$expe->meths,GETPOST('expedition_method_id','int'),1,0,0,"",1);
  580. print "</td></tr>\n";
  581. // Tracking number
  582. print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
  583. print '<td colspan="3">';
  584. print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number','alpha').'">';
  585. print "</td></tr>\n";
  586. // Other attributes
  587. $parameters=array('colspan' => ' colspan="3"');
  588. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$expe,$action); // Note that $action and $object may have been modified by hook
  589. print "</table>";
  590. /*
  591. * Lignes de commandes
  592. *
  593. */
  594. print '<br><table class="nobordernopadding" width="100%">';
  595. //$lines = $object->fetch_lines(1);
  596. $numAsked = count($object->lines);
  597. /* Lecture des expeditions deja effectuees */
  598. $object->loadExpeditions();
  599. if ($numAsked)
  600. {
  601. print '<tr class="liste_titre">';
  602. print '<td>'.$langs->trans("Description").'</td>';
  603. print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
  604. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  605. print '<td align="left">'.$langs->trans("QtyToShip").'</td>';
  606. if (! empty($conf->stock->enabled))
  607. {
  608. print '<td align="left">'.$langs->trans("Warehouse").' / '.$langs->trans("Stock").'</td>';
  609. }
  610. print "</tr>\n";
  611. }
  612. $var=true;
  613. $indiceAsked = 0;
  614. while ($indiceAsked < $numAsked)
  615. {
  616. $product = new Product($db);
  617. $line = $object->lines[$indiceAsked];
  618. $var=!$var;
  619. // Show product and description
  620. $type=$line->product_type?$line->product_type:$line->fk_product_type;
  621. // Try to enhance type detection using date_start and date_end for free lines where type
  622. // was not saved.
  623. if (! empty($line->date_start)) $type=1;
  624. if (! empty($line->date_end)) $type=1;
  625. print "<tr ".$bc[$var].">\n";
  626. // Product label
  627. if ($line->fk_product > 0)
  628. {
  629. $product->fetch($line->fk_product);
  630. $product->load_stock();
  631. print '<td>';
  632. print '<a name="'.$line->rowid.'"></a>'; // ancre pour retourner sur la ligne
  633. // Show product and description
  634. $product_static->type=$line->fk_product_type;
  635. $product_static->id=$line->fk_product;
  636. $product_static->ref=$line->ref;
  637. $text=$product_static->getNomUrl(1);
  638. $text.= ' - '.(! empty($line->label)?$line->label:$line->product_label);
  639. $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->desc));
  640. print $form->textwithtooltip($text,$description,3,'','',$i);
  641. // Show range
  642. print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
  643. // Add description in form
  644. if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
  645. {
  646. print ($line->desc && $line->desc!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->desc):'';
  647. }
  648. print '</td>';
  649. }
  650. else
  651. {
  652. print "<td>";
  653. if ($type==1) $text = img_object($langs->trans('Service'),'service');
  654. else $text = img_object($langs->trans('Product'),'product');
  655. if (! empty($line->label)) {
  656. $text.= ' <strong>'.$line->label.'</strong>';
  657. print $form->textwithtooltip($text,$line->desc,3,'','',$i);
  658. } else {
  659. print $text.' '.nl2br($line->desc);
  660. }
  661. // Show range
  662. print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
  663. print "</td>\n";
  664. }
  665. // Qty
  666. print '<td align="center">'.$line->qty.'</td>';
  667. $qtyProdCom=$line->qty;
  668. // Qty already sent
  669. print '<td align="center">';
  670. $quantityDelivered = $object->expeditions[$line->id];
  671. print $quantityDelivered;
  672. print '</td>';
  673. $quantityAsked = $line->qty;
  674. $quantityToBeDelivered = $quantityAsked - $quantityDelivered;
  675. $defaultqty=0;
  676. if (GETPOST('entrepot_id','int') > 0)
  677. {
  678. //var_dump($product);
  679. $stock = $product->stock_warehouse[GETPOST('entrepot_id','int')]->real;
  680. $stock+=0; // Convertit en numerique
  681. $defaultqty=min($quantityToBeDelivered, $stock);
  682. if (($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES)) || $defaultqty < 0) $defaultqty=0;
  683. }
  684. // Quantity to send
  685. print '<td align="left">';
  686. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  687. {
  688. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  689. print '<input name="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$defaultqty.'">';
  690. }
  691. else print '0';
  692. print '</td>';
  693. // Stock
  694. if (! empty($conf->stock->enabled))
  695. {
  696. print '<td align="left">';
  697. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  698. {
  699. // Show warehouse combo list
  700. $ent = "entl".$indiceAsked;
  701. $idl = "idl".$indiceAsked;
  702. $tmpentrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int');
  703. print $formproduct->selectWarehouses($tmpentrepot_id,'entl'.$indiceAsked,'',1,0,$line->fk_product);
  704. if ($tmpentrepot_id > 0 && $tmpentrepot_id == GETPOST('entrepot_id','int'))
  705. {
  706. //print $stock.' '.$quantityToBeDelivered;
  707. if ($stock < $quantityToBeDelivered)
  708. {
  709. print ' '.img_warning($langs->trans("StockTooLow")); // Stock too low for entrepot_id but we may have change warehouse
  710. }
  711. }
  712. }
  713. else
  714. {
  715. print $langs->trans("Service");
  716. }
  717. print '</td>';
  718. }
  719. print "</tr>\n";
  720. // Show subproducts of product
  721. if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)
  722. {
  723. $product->get_sousproduits_arbo();
  724. $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
  725. if(count($prods_arbo) > 0)
  726. {
  727. foreach($prods_arbo as $key => $value)
  728. {
  729. //print $value[0];
  730. $img='';
  731. if ($value['stock'] < $value['stock_alert'])
  732. {
  733. $img=img_warning($langs->trans("StockTooLow"));
  734. }
  735. print "<tr ".$bc[$var]."><td>&nbsp; &nbsp; &nbsp; ->
  736. <a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$value['id']."\">".$value['fullpath']."
  737. </a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
  738. <td align=\"center\">".$value['stock']." ".$img."</td></tr>";
  739. }
  740. }
  741. }
  742. $indiceAsked++;
  743. }
  744. print '<tr><td align="center" colspan="5"><br><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
  745. print "</table>";
  746. print '</form>';
  747. }
  748. else
  749. {
  750. dol_print_error($db);
  751. }
  752. }
  753. }
  754. else
  755. /* *************************************************************************** */
  756. /* */
  757. /* Edit and view mode */
  758. /* */
  759. /* *************************************************************************** */
  760. {
  761. if (! empty($id) || ! empty($ref))
  762. {
  763. $result = $object->fetch($id,$ref);
  764. if ($result < 0)
  765. {
  766. dol_print_error($db,$object->error);
  767. exit -1;
  768. }
  769. $lines = $object->lines;
  770. $num_prod = count($lines);
  771. if ($object->id > 0)
  772. {
  773. dol_htmloutput_mesg($mesg);
  774. if (!empty($object->origin))
  775. {
  776. $typeobject = $object->origin;
  777. $origin = $object->origin;
  778. $object->fetch_origin();
  779. }
  780. $soc = new Societe($db);
  781. $soc->fetch($object->socid);
  782. $head=shipping_prepare_head($object);
  783. dol_fiche_head($head, 'shipping', $langs->trans("Sending"), 0, 'sending');
  784. dol_htmloutput_mesg($mesg);
  785. /*
  786. * Confirmation de la suppression
  787. */
  788. if ($action == 'delete')
  789. {
  790. $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$object->ref),'confirm_delete','',0,1);
  791. if ($ret == 'html') print '<br>';
  792. }
  793. /*
  794. * Confirmation de la validation
  795. */
  796. if ($action == 'valid')
  797. {
  798. $objectref = substr($object->ref, 1, 4);
  799. if ($objectref == 'PROV')
  800. {
  801. $numref = $object->getNextNumRef($soc);
  802. }
  803. else
  804. {
  805. $numref = $object->ref;
  806. }
  807. $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$langs->trans("ConfirmValidateSending",$numref),'confirm_valid','',0,1);
  808. if ($ret == 'html') print '<br>';
  809. }
  810. /*
  811. * Confirmation de l'annulation
  812. */
  813. if ($action == 'annuler')
  814. {
  815. $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$object->ref),'confirm_cancel','',0,1);
  816. if ($ret == 'html') print '<br>';
  817. }
  818. // Calculate ture totalVeight and totalVolume for all products
  819. // by adding weight and volume of each line.
  820. $totalWeight = '';
  821. $totalVolume = '';
  822. $weightUnit=0;
  823. $volumeUnit=0;
  824. for ($i = 0 ; $i < $num_prod ; $i++)
  825. {
  826. $weightUnit=0;
  827. $volumeUnit=0;
  828. if (! empty($lines[$i]->weight_units)) $weightUnit = $lines[$i]->weight_units;
  829. if (! empty($lines[$i]->volume_units)) $volumeUnit = $lines[$i]->volume_units;
  830. // TODO Use a function addvalueunits(val1,unit1,val2,unit2)=>(val,unit)
  831. if ($lines[$i]->weight_units < 50)
  832. {
  833. $trueWeightUnit=pow(10,$weightUnit);
  834. $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped*$trueWeightUnit;
  835. }
  836. else
  837. {
  838. $trueWeightUnit=$weightUnit;
  839. $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped;
  840. }
  841. if ($lines[$i]->volume_units < 50)
  842. {
  843. //print $lines[$i]->volume."x".$lines[$i]->volume_units."x".($lines[$i]->volume_units < 50)."x".$volumeUnit;
  844. $trueVolumeUnit=pow(10,$volumeUnit);
  845. //print $lines[$i]->volume;
  846. $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped*$trueVolumeUnit;
  847. }
  848. else
  849. {
  850. $trueVolumeUnit=$volumeUnit;
  851. $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped;
  852. }
  853. }
  854. $totalVolume=$totalVolume;
  855. //print "totalVolume=".$totalVolume." volumeUnit=".$volumeUnit;
  856. print '<table class="border" width="100%">';
  857. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/liste.php">'.$langs->trans("BackToList").'</a>';
  858. // Ref
  859. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  860. print '<td colspan="3">';
  861. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  862. print '</td></tr>';
  863. // Customer
  864. print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
  865. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  866. print "</tr>";
  867. // Linked documents
  868. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  869. {
  870. print '<tr><td>';
  871. $objectsrc=new Commande($db);
  872. $objectsrc->fetch($object->$typeobject->id);
  873. print $langs->trans("RefOrder").'</td>';
  874. print '<td colspan="3">';
  875. print $objectsrc->getNomUrl(1,'commande');
  876. print "</td>\n";
  877. print '</tr>';
  878. }
  879. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  880. {
  881. print '<tr><td>';
  882. $objectsrc=new Propal($db);
  883. $objectsrc->fetch($object->$typeobject->id);
  884. print $langs->trans("RefProposal").'</td>';
  885. print '<td colspan="3">';
  886. print $objectsrc->getNomUrl(1,'expedition');
  887. print "</td>\n";
  888. print '</tr>';
  889. }
  890. // Ref customer
  891. print '<tr><td>'.$langs->trans("RefCustomer").'</td>';
  892. print '<td colspan="3">'.$object->ref_customer."</a></td>\n";
  893. print '</tr>';
  894. // Date creation
  895. print '<tr><td>'.$langs->trans("DateCreation").'</td>';
  896. print '<td colspan="3">'.dol_print_date($object->date_creation,"day")."</td>\n";
  897. print '</tr>';
  898. // Delivery date planed
  899. print '<tr><td height="10">';
  900. print '<table class="nobordernopadding" width="100%"><tr><td>';
  901. print $langs->trans('DateDeliveryPlanned');
  902. print '</td>';
  903. 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>';
  904. print '</tr></table>';
  905. print '</td><td colspan="2">';
  906. if ($action == 'editdate_livraison')
  907. {
  908. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  909. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  910. print '<input type="hidden" name="action" value="setdate_livraison">';
  911. $form->select_date($object->date_delivery?$object->date_delivery:-1,'liv_',1,1,'',"setdate_livraison");
  912. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  913. print '</form>';
  914. }
  915. else
  916. {
  917. print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhourtext') : '&nbsp;';
  918. }
  919. print '</td>';
  920. print '</tr>';
  921. // Weight
  922. print '<tr><td>'.$form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  923. print $form->editfieldval("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer);
  924. print $object->weight_units?measuring_units_string($object->weight_units,"weight"):'';
  925. print '</td></tr>';
  926. // Volume Total
  927. print '<tr><td>'.$langs->trans("Volume").'</td>';
  928. print '<td colspan="3">';
  929. if ($object->trueVolume)
  930. {
  931. // If sending volume defined
  932. print $object->trueVolume.' '.measuring_units_string($object->volumeUnit,"volume");
  933. }
  934. else
  935. {
  936. // If sending volume not defined we use sum of products
  937. if ($totalVolume > 0)
  938. {
  939. print $totalVolume.' ';
  940. if ($volumeUnit < 50) print measuring_units_string(0,"volume");
  941. else print measuring_units_string($volumeUnit,"volume");
  942. }
  943. else print '&nbsp;';
  944. }
  945. print "</td>\n";
  946. print '</tr>';
  947. // Width
  948. print '<tr><td>'.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  949. print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer);
  950. print $object->trueWidth?measuring_units_string($object->width_units,"size"):'';
  951. print '</td></tr>';
  952. // Height
  953. print '<tr><td>'.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  954. print $form->editfieldval("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer);
  955. print $object->trueHeight?measuring_units_string($object->height_units,"size"):'';
  956. print '</td></tr>';
  957. // Depth
  958. print '<tr><td>'.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  959. print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer);
  960. print $object->trueDepth?measuring_units_string($object->depth_units,"size"):'';
  961. print '</td></tr>';
  962. // Status
  963. print '<tr><td>'.$langs->trans("Status").'</td>';
  964. print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
  965. print '</tr>';
  966. // Sending method
  967. print '<tr><td height="10">';
  968. print '<table class="nobordernopadding" width="100%"><tr><td>';
  969. print $langs->trans('SendingMethod');
  970. print '</td>';
  971. if ($action != 'editexpedition_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editexpedition_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetSendingMethod'),1).'</a></td>';
  972. print '</tr></table>';
  973. print '</td><td colspan="2">';
  974. if ($action == 'editexpedition_method_id')
  975. {
  976. print '<form name="setexpedition_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  977. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  978. print '<input type="hidden" name="action" value="setexpedition_method_id">';
  979. $object->fetch_delivery_methods();
  980. print $form->selectarray("expedition_method_id",$object->meths,$object->expedition_method_id,1,0,0,"",1);
  981. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  982. print '</form>';
  983. }
  984. else
  985. {
  986. if ($object->expedition_method_id > 0)
  987. {
  988. // Get code using getLabelFromKey
  989. $code=$langs->getLabelFromKey($db,$object->expedition_method_id,'c_shipment_mode','rowid','code');
  990. print $langs->trans("SendingMethod".strtoupper($code));
  991. }
  992. }
  993. print '</td>';
  994. print '</tr>';
  995. // Tracking Number
  996. print '<tr><td>'.$form->editfieldkey("TrackingNumber",'trackingnumber',$object->tracking_number,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  997. print $form->editfieldval("TrackingNumber",'trackingnumber',$object->tracking_url,$object,$user->rights->expedition->creer,'string',$object->tracking_number);
  998. print '</td></tr>';
  999. // Other attributes
  1000. $parameters=array('colspan' => ' colspan="3"');
  1001. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1002. print "</table>\n";
  1003. /*
  1004. * Lignes produits
  1005. */
  1006. print '<br><table class="noborder" width="100%">';
  1007. print '<tr class="liste_titre">';
  1008. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1009. {
  1010. print '<td width="5" align="center">&nbsp;</td>';
  1011. }
  1012. print '<td>'.$langs->trans("Products").'</td>';
  1013. print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
  1014. if ($object->fk_statut <= 1)
  1015. {
  1016. print '<td align="center">'.$langs->trans("QtyToShip").'</td>';
  1017. }
  1018. else
  1019. {
  1020. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  1021. }
  1022. print '<td align="center">'.$langs->trans("CalculatedWeight").'</td>';
  1023. print '<td align="center">'.$langs->trans("CalculatedVolume").'</td>';
  1024. //print '<td align="center">'.$langs->trans("Size").'</td>';
  1025. if (! empty($conf->stock->enabled))
  1026. {
  1027. print '<td align="left">'.$langs->trans("WarehouseSource").'</td>';
  1028. }
  1029. print "</tr>\n";
  1030. $var=false;
  1031. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1032. {
  1033. $object->fetch_thirdparty();
  1034. $outputlangs = $langs;
  1035. $newlang='';
  1036. if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
  1037. if (empty($newlang)) $newlang=$object->client->default_lang;
  1038. if (! empty($newlang))
  1039. {
  1040. $outputlangs = new Translate();
  1041. $outputlangs->setDefaultLang($newlang);
  1042. }
  1043. }
  1044. for ($i = 0 ; $i < $num_prod ; $i++)
  1045. {
  1046. print "<tr ".$bc[$var].">";
  1047. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1048. {
  1049. print '<td align="center">'.($i+1).'</td>';
  1050. }
  1051. // Predefined product or service
  1052. if ($lines[$i]->fk_product > 0)
  1053. {
  1054. // Define output language
  1055. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1056. {
  1057. $prod = new Product($db);
  1058. $prod->fetch($lines[$i]->fk_product);
  1059. $label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;
  1060. }
  1061. else
  1062. $label = (! empty($lines[$i]->label)?$lines[$i]->label:$lines[$i]->product_label);
  1063. print '<td>';
  1064. // Show product and description
  1065. $product_static->type=$lines[$i]->fk_product_type;
  1066. $product_static->id=$lines[$i]->fk_product;
  1067. $product_static->ref=$lines[$i]->ref;
  1068. $text=$product_static->getNomUrl(1);
  1069. $text.= ' - '.$label;
  1070. $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($lines[$i]->description));
  1071. print $form->textwithtooltip($text,$description,3,'','',$i);
  1072. print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
  1073. if (! empty($conf->global->PRODUIT_DESC_IN_FORM))

Large files files are truncated, but you can click here to view the full file