PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/expedition/fiche.php

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