fiche.php 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. <?php
  2. /* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2013 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. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/expedition/fiche.php
  26. * \ingroup expedition
  27. * \brief Fiche descriptive d'une expedition
  28. */
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  37. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  38. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  39. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  40. if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  41. if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
  42. $langs->load("sendings");
  43. $langs->load("companies");
  44. $langs->load("bills");
  45. $langs->load('deliveries');
  46. $langs->load('orders');
  47. $langs->load('stocks');
  48. $langs->load('other');
  49. $langs->load('propal');
  50. if (! empty($conf->productbatch->enabled)) $langs->load('productbatch');
  51. $origin = GETPOST('origin','alpha')?GETPOST('origin','alpha'):'expedition'; // Example: commande, propal
  52. $origin_id = GETPOST('id','int')?GETPOST('id','int'):'';
  53. $id = $origin_id;
  54. if (empty($origin_id)) $origin_id = GETPOST('origin_id','int'); // Id of order or propal
  55. if (empty($origin_id)) $origin_id = GETPOST('object_id','int'); // Id of order or propal
  56. $ref=GETPOST('ref','alpha');
  57. // Security check
  58. $socid='';
  59. if ($user->societe_id) $socid=$user->societe_id;
  60. $result=restrictedArea($user, $origin, $origin_id);
  61. $action = GETPOST('action','alpha');
  62. $confirm = GETPOST('confirm','alpha');
  63. //PDF
  64. $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  65. $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  66. $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  67. $object = new Expedition($db);
  68. // Load object
  69. if ($id > 0 || ! empty($ref))
  70. {
  71. $ret=$object->fetch($id, $ref);
  72. }
  73. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  74. $hookmanager->initHooks(array('expeditioncard'));
  75. /*
  76. * Actions
  77. */
  78. $parameters=array();
  79. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  80. if ($action == 'add')
  81. {
  82. $error=0;
  83. $db->begin();
  84. $object->note = GETPOST('note','alpha');
  85. $object->origin = $origin;
  86. $object->origin_id = $origin_id;
  87. $object->weight = GETPOST('weight','int')==''?"NULL":GETPOST('weight','int');
  88. $object->sizeH = GETPOST('sizeH','int')==''?"NULL":GETPOST('sizeH','int');
  89. $object->sizeW = GETPOST('sizeW','int')==''?"NULL":GETPOST('sizeW','int');
  90. $object->sizeS = GETPOST('sizeS','int')==''?"NULL":GETPOST('sizeS','int');
  91. $object->size_units = GETPOST('size_units','int');
  92. $object->weight_units = GETPOST('weight_units','int');
  93. $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'));
  94. // On va boucler sur chaque ligne du document d'origine pour completer objet expedition
  95. // avec info diverses + qte a livrer
  96. $classname = ucfirst($object->origin);
  97. $objectsrc = new $classname($db);
  98. $objectsrc->fetch($object->origin_id);
  99. //$object->fetch_lines();
  100. $object->socid = $objectsrc->socid;
  101. $object->ref_customer = $objectsrc->ref_client;
  102. $object->date_delivery = $date_delivery; // Date delivery planed
  103. $object->fk_delivery_address = $objectsrc->fk_delivery_address;
  104. $object->shipping_method_id = GETPOST('shipping_method_id','int');
  105. $object->tracking_number = GETPOST('tracking_number','alpha');
  106. $object->ref_int = GETPOST('ref_int','alpha');
  107. $object->note_private = GETPOST('note_private');
  108. $object->note_public = GETPOST('note_public');
  109. $num=count($objectsrc->lines);
  110. $totalqty=0;
  111. for ($i = 0; $i < $num; $i++)
  112. {
  113. $qty = "qtyl".$i;
  114. $j=0;
  115. $sub_qty=array();
  116. $subtotalqty=0;
  117. $idl="idl".$i;
  118. $batch="batchl".$i."_0";
  119. if (isset($_POST[$batch])) {
  120. //shipment line with batch-enable product
  121. $qty .= '_'.$j;
  122. while (isset($_POST[$batch])) {
  123. $sub_qty[$j]['q']=GETPOST($qty,'int');
  124. $sub_qty[$j]['id_batch']=GETPOST($batch,'int');
  125. $subtotalqty+=$sub_qty[$j]['q'];
  126. $j++;
  127. $batch="batchl".$i."_".$j;
  128. $qty = "qtyl".$i.'_'.$j;
  129. }
  130. $batch_line[$i]['detail']=$sub_qty;
  131. $batch_line[$i]['qty']=$subtotalqty;
  132. $batch_line[$i]['ix_l']=GETPOST($idl,'int');
  133. $totalqty+=$subtotalqty;
  134. } else {
  135. //Standard product
  136. if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int');
  137. }
  138. }
  139. if ($totalqty > 0)
  140. {
  141. //var_dump($_POST);exit;
  142. for ($i = 0; $i < $num; $i++)
  143. {
  144. $qty = "qtyl".$i;
  145. if (! isset($batch_line[$i])) {
  146. if (GETPOST($qty,'int') > 0)
  147. {
  148. $ent = "entl".$i;
  149. $idl = "idl".$i;
  150. $entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int');
  151. if ($entrepot_id < 0) $entrepot_id='';
  152. $ret=$object->addline($entrepot_id,GETPOST($idl,'int'),GETPOST($qty,'int'));
  153. if ($ret < 0)
  154. {
  155. $mesg='<div class="error">'.$object->error.'</div>';
  156. $error++;
  157. }
  158. }
  159. } else {
  160. if ($batch_line[$i]['qty']>0) {
  161. $ret=$object->addline_batch($batch_line[$i]);
  162. if ($ret < 0)
  163. {
  164. $mesg='<div class="error">'.$object->error.'</div>';
  165. $error++;
  166. }
  167. }
  168. }
  169. }
  170. if (! $error)
  171. {
  172. $ret=$object->create($user);
  173. if ($ret <= 0)
  174. {
  175. $mesg='<div class="error">'.$object->error.'</div>';
  176. $error++;
  177. }
  178. }
  179. }
  180. else
  181. {
  182. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Qty")).'</div>';
  183. $error++;
  184. }
  185. if (! $error)
  186. {
  187. $db->commit();
  188. header("Location: fiche.php?id=".$object->id);
  189. exit;
  190. }
  191. else
  192. {
  193. $db->rollback();
  194. $_GET["commande_id"]=GETPOST('commande_id','int');
  195. $action='create';
  196. }
  197. }
  198. /*
  199. * Build a receiving receipt
  200. */
  201. else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
  202. {
  203. $result = $object->create_delivery($user);
  204. if ($result > 0)
  205. {
  206. header("Location: ".DOL_URL_ROOT.'/livraison/fiche.php?id='.$result);
  207. exit;
  208. }
  209. else
  210. {
  211. $mesg=$object->error;
  212. }
  213. }
  214. else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->expedition->valider)
  215. {
  216. $object->fetch_thirdparty();
  217. $result = $object->valid($user);
  218. // Define output language
  219. $outputlangs = $langs;
  220. $newlang='';
  221. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
  222. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  223. if (! empty($newlang))
  224. {
  225. $outputlangs = new Translate("",$conf);
  226. $outputlangs->setDefaultLang($newlang);
  227. }
  228. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  229. {
  230. $ret=$object->fetch($id); // Reload to get new records
  231. $result=expedition_pdf_create($db,$object,$object->modelpdf,$outputlangs);
  232. }
  233. if ($result < 0)
  234. {
  235. dol_print_error($db,$result);
  236. exit;
  237. }
  238. }
  239. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)
  240. {
  241. $result = $object->delete();
  242. if ($result > 0)
  243. {
  244. header("Location: ".DOL_URL_ROOT.'/expedition/index.php');
  245. exit;
  246. }
  247. else
  248. {
  249. $langs->load("errors");
  250. setEventMessage($langs->trans($object->error),'errors');
  251. }
  252. }
  253. else if ($action == 'reopen' && $user->rights->expedition->valider)
  254. {
  255. $result = $object->setStatut(0);
  256. if ($result < 0)
  257. {
  258. $mesg = $object->error;
  259. }
  260. }
  261. else if ($action == 'setdate_livraison' && $user->rights->expedition->creer)
  262. {
  263. //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
  264. $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
  265. $object->fetch($id);
  266. $result=$object->set_date_livraison($user,$datedelivery);
  267. if ($result < 0)
  268. {
  269. $mesg='<div class="error">'.$object->error.'</div>';
  270. }
  271. }
  272. // Action update description of emailing
  273. else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
  274. || $action == 'settrueWeight'
  275. || $action == 'settrueWidth'
  276. || $action == 'settrueHeight'
  277. || $action == 'settrueDepth'
  278. || $action == 'setshipping_method_id')
  279. {
  280. $error=0;
  281. if ($action == 'settrackingnumber') $object->tracking_number = trim(GETPOST('trackingnumber','alpha'));
  282. if ($action == 'settrackingurl') $object->tracking_url = trim(GETPOST('trackingurl','int'));
  283. if ($action == 'settrueWeight') {
  284. $object->trueWeight = trim(GETPOST('trueWeight','int'));
  285. $object->weight_units = GETPOST('weight_units','int');
  286. }
  287. if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth','int'));
  288. if ($action == 'settrueHeight'){
  289. $object->trueHeight = trim(GETPOST('trueHeight','int'));
  290. $object->size_units = GETPOST('size_units','int');
  291. }
  292. if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth','int'));
  293. if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
  294. if (! $error)
  295. {
  296. if ($object->update($user) >= 0)
  297. {
  298. header("Location: fiche.php?id=".$object->id);
  299. exit;
  300. }
  301. setEventMessage($object->error,'errors');
  302. }
  303. $action="";
  304. }
  305. // Build document
  306. else if ($action == 'builddoc') // En get ou en post
  307. {
  308. // Save last template used to generate document
  309. if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
  310. // Define output language
  311. $outputlangs = $langs;
  312. $newlang='';
  313. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
  314. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$shipment->client->default_lang;
  315. if (! empty($newlang))
  316. {
  317. $outputlangs = new Translate("",$conf);
  318. $outputlangs->setDefaultLang($newlang);
  319. }
  320. $result=expedition_pdf_create($db,$object,$object->modelpdf,$outputlangs);
  321. if ($result <= 0)
  322. {
  323. dol_print_error($db,$result);
  324. exit;
  325. }
  326. }
  327. // Delete file in doc form
  328. elseif ($action == 'remove_file')
  329. {
  330. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  331. $upload_dir = $conf->expedition->dir_output . "/sending";
  332. $file = $upload_dir . '/' . GETPOST('file');
  333. $ret=dol_delete_file($file,0,0,0,$object);
  334. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  335. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  336. }
  337. /*
  338. * Add file in email form
  339. */
  340. if (GETPOST('addfile','alpha'))
  341. {
  342. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  343. // Set tmp user directory TODO Use a dedicated directory for temp mails files
  344. $vardir=$conf->user->dir_output."/".$user->id;
  345. $upload_dir_tmp = $vardir.'/temp';
  346. dol_add_file_process($upload_dir_tmp,0,0);
  347. $action ='presend';
  348. }
  349. /*
  350. * Remove file in email form
  351. */
  352. if (GETPOST('removedfile','alpha'))
  353. {
  354. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  355. // Set tmp user directory
  356. $vardir=$conf->user->dir_output."/".$user->id;
  357. $upload_dir_tmp = $vardir.'/temp';
  358. // TODO Delete only files that was uploaded from email form
  359. dol_remove_file_process(GETPOST('removedfile','int'),0);
  360. $action ='presend';
  361. }
  362. /*
  363. * Send mail
  364. */
  365. if ($action == 'send' && ! GETPOST('addfile','alpha') && ! GETPOST('removedfile','alpha') && ! GETPOST('cancel','alpha'))
  366. {
  367. $langs->load('mails');
  368. // $ref = dol_sanitizeFileName($object->ref);
  369. // $file = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf';
  370. // if (is_readable($file))
  371. // {
  372. if (GETPOST('sendto','alpha'))
  373. {
  374. // Le destinataire a ete fourni via le champ libre
  375. $sendto = GETPOST('sendto','alpha');
  376. $sendtoid = 0;
  377. }
  378. elseif (GETPOST('receiver','alpha') != '-1')
  379. {
  380. // Recipient was provided from combo list
  381. if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
  382. {
  383. $sendto = $object->client->email;
  384. $sendtoid = 0;
  385. }
  386. else // Id du contact
  387. {
  388. $sendto = $object->client->contact_get_property(GETPOST('receiver','alpha'),'email');
  389. $sendtoid = GETPOST('receiver','alpha');
  390. }
  391. }
  392. if (dol_strlen($sendto))
  393. {
  394. $langs->load("commercial");
  395. $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
  396. $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
  397. $message = GETPOST('message');
  398. $sendtocc = GETPOST('sendtocc','alpha');
  399. $deliveryreceipt = GETPOST('deliveryreceipt','alpha');
  400. if ($action == 'send')
  401. {
  402. if (dol_strlen(GETPOST('subject','alpha'))) $subject=GETPOST('subject','alpha');
  403. else $subject = $langs->transnoentities('Shipping').' '.$object->ref;
  404. $actiontypecode='AC_SHIP';
  405. $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
  406. if ($message)
  407. {
  408. $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
  409. $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
  410. $actionmsg.=$message;
  411. }
  412. $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
  413. }
  414. // Create form object
  415. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  416. $formmail = new FormMail($db);
  417. $attachedfiles=$formmail->get_attached_files();
  418. $filepath = $attachedfiles['paths'];
  419. $filename = $attachedfiles['names'];
  420. $mimetype = $attachedfiles['mimes'];
  421. // Send mail
  422. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  423. $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
  424. if ($mailfile->error)
  425. {
  426. $mesg='<div class="error">'.$mailfile->error.'</div>';
  427. }
  428. else
  429. {
  430. $result=$mailfile->sendfile();
  431. if ($result)
  432. {
  433. $error=0;
  434. // Initialisation donnees
  435. $object->sendtoid = $sendtoid;
  436. $object->actiontypecode = $actiontypecode;
  437. $object->actionmsg = $actionmsg;
  438. $object->actionmsg2 = $actionmsg2;
  439. $object->fk_element = $object->id;
  440. $object->elementtype = $object->element;
  441. // Appel des triggers
  442. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  443. $interface=new Interfaces($db);
  444. $result=$interface->run_triggers('SHIPPING_SENTBYMAIL',$object,$user,$langs,$conf);
  445. if ($result < 0) {
  446. $error++; $this->errors=$interface->errors;
  447. }
  448. // Fin appel triggers
  449. if ($error)
  450. {
  451. dol_print_error($db);
  452. }
  453. else
  454. {
  455. // Redirect here
  456. // This avoid sending mail twice if going out and then back to page
  457. $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
  458. setEventMessage($mesg);
  459. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  460. exit;
  461. }
  462. }
  463. else
  464. {
  465. $langs->load("other");
  466. $mesg='<div class="error">';
  467. if ($mailfile->error)
  468. {
  469. $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
  470. $mesg.='<br>'.$mailfile->error;
  471. }
  472. else
  473. {
  474. $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  475. }
  476. $mesg.='</div>';
  477. }
  478. }
  479. }
  480. else
  481. {
  482. $langs->load("other");
  483. $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
  484. $action='presend';
  485. dol_syslog('Recipient email is empty');
  486. }
  487. /* }
  488. else
  489. {
  490. $langs->load("errors");
  491. $mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
  492. dol_syslog('Failed to read file: '.$file);
  493. }*/
  494. }
  495. else if ($action == 'classifybilled')
  496. {
  497. $object->fetch($id);
  498. $object->set_billed();
  499. }
  500. /*
  501. * View
  502. */
  503. llxHeader('',$langs->trans('Shipment'),'Expedition');
  504. $form = new Form($db);
  505. $formfile = new FormFile($db);
  506. $formproduct = new FormProduct($db);
  507. $product_static = new Product($db);
  508. if ($action == 'create2')
  509. {
  510. print_fiche_titre($langs->trans("CreateASending")).'<br>';
  511. print $langs->trans("ShipmentCreationIsDoneFromOrder");
  512. $action=''; $id=''; $ref='';
  513. }
  514. // Mode creation
  515. if ($action == 'create')
  516. {
  517. $expe = new Expedition($db);
  518. print_fiche_titre($langs->trans("CreateASending"));
  519. if (! $origin)
  520. {
  521. $mesg='<div class="error">'.$langs->trans("ErrorBadParameters").'</div>';
  522. }
  523. dol_htmloutput_mesg($mesg);
  524. if ($origin)
  525. {
  526. $classname = ucfirst($origin);
  527. $object = new $classname($db);
  528. if ($object->fetch($origin_id)) // This include the fetch_lines
  529. {
  530. //var_dump($object);
  531. $soc = new Societe($db);
  532. $soc->fetch($object->socid);
  533. $author = new User($db);
  534. $author->fetch($object->user_author_id);
  535. if (! empty($conf->stock->enabled)) $entrepot = new Entrepot($db);
  536. /*
  537. * Document source
  538. */
  539. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  540. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  541. print '<input type="hidden" name="action" value="add">';
  542. print '<input type="hidden" name="origin" value="'.$origin.'">';
  543. print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
  544. print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';
  545. if (GETPOST('entrepot_id','int'))
  546. {
  547. print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id','int').'">';
  548. }
  549. print '<table class="border" width="100%">';
  550. // Ref
  551. print '<tr><td width="30%" class="fieldrequired">';
  552. if ($origin == 'commande' && ! empty($conf->commande->enabled))
  553. {
  554. 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;
  555. }
  556. if ($origin == 'propal' && ! empty($conf->propal->enabled))
  557. {
  558. 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;
  559. }
  560. print '</a></td>';
  561. print "</tr>\n";
  562. // Ref client
  563. print '<tr><td>';
  564. if ($origin == 'commande') print $langs->trans('RefCustomerOrder');
  565. else if ($origin == 'propal') print $langs->trans('RefCustomerOrder');
  566. else print $langs->trans('RefCustomer');
  567. print '</td><td colspan="3">';
  568. print $object->ref_client;
  569. print '</td>';
  570. print '</tr>';
  571. // Tiers
  572. print '<tr><td class="fieldrequired">'.$langs->trans('Company').'</td>';
  573. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  574. print '</tr>';
  575. // Date delivery planned
  576. print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
  577. print '<td colspan="3">';
  578. //print dol_print_date($object->date_livraison,"day"); // date_livraison come from order and will be stored into date_delivery planed.
  579. print $form->select_date($object->date_livraison?$object->date_livraison:-1,'date_delivery',1,1);
  580. print "</td>\n";
  581. print '</tr>';
  582. // Note Public
  583. print '<tr><td>'.$langs->trans("NotePublic").'</td>';
  584. print '<td colspan="3">';
  585. $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  586. print $doleditor->Create(1);
  587. print "</td></tr>";
  588. // Note Private
  589. if ($object->note_private && ! $user->societe_id)
  590. {
  591. print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
  592. print '<td colspan="3">';
  593. $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  594. print $doleditor->Create(1);
  595. print "</td></tr>";
  596. }
  597. // Weight
  598. print '<tr><td>';
  599. print $langs->trans("Weight");
  600. print '</td><td width="90px"><input name="weight" size="5" value="'.GETPOST('weight','int').'"></td><td>';
  601. print $formproduct->select_measuring_units("weight_units","weight",GETPOST('weight_units','int'));
  602. print '</td></tr><tr><td>';
  603. print $langs->trans("Width");
  604. print ' </td><td><input name="sizeW" size="5" value="'.GETPOST('sizeW','int').'"></td><td rowspan="3">';
  605. print $formproduct->select_measuring_units("size_units","size");
  606. print '</td></tr><tr><td>';
  607. print $langs->trans("Height");
  608. print '</td><td><input name="sizeH" size="5" value="'.GETPOST('sizeH','int').'"></td>';
  609. print '</tr><tr><td>';
  610. print $langs->trans("Depth");
  611. print '</td><td><input name="sizeS" size="5" value="'.GETPOST('sizeS','int').'"></td>';
  612. print '</tr>';
  613. // Delivery method
  614. print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";
  615. print '<td colspan="3">';
  616. $expe->fetch_delivery_methods();
  617. print $form->selectarray("shipping_method_id",$expe->meths,GETPOST('shipping_method_id','int'),1,0,0,"",1);
  618. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  619. print "</td></tr>\n";
  620. // Tracking number
  621. print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
  622. print '<td colspan="3">';
  623. print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number','alpha').'">';
  624. print "</td></tr>\n";
  625. // Other attributes
  626. $parameters=array('colspan' => ' colspan="3"');
  627. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$expe,$action); // Note that $action and $object may have been modified by hook
  628. print "</table>";
  629. /*
  630. * Lignes de commandes
  631. */
  632. //$lines = $object->fetch_lines(1);
  633. $numAsked = count($object->lines);
  634. print '<script type="text/javascript" language="javascript">
  635. jQuery(document).ready(function() {
  636. jQuery("#autofill").click(function() {';
  637. $i=0;
  638. while($i < $numAsked)
  639. {
  640. print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
  641. $i++;
  642. }
  643. print '});
  644. jQuery("#autoreset").click(function() {';
  645. $i=0;
  646. while($i < $numAsked)
  647. {
  648. print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
  649. $i++;
  650. }
  651. print '});
  652. });
  653. </script>';
  654. print '<br>';
  655. print '<table class="noborder" width="100%">';
  656. /* Lecture des expeditions deja effectuees */
  657. $object->loadExpeditions();
  658. if ($numAsked)
  659. {
  660. print '<tr class="liste_titre">';
  661. print '<td>'.$langs->trans("Description").'</td>';
  662. print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
  663. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  664. print '<td align="center">'.$langs->trans("QtyToShip");
  665. if (empty($conf->productbatch->enabled)) {
  666. print ' <br>(<a href="#" id="autofill">'.$langs->trans("Fill").'</a>';
  667. print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';
  668. }
  669. print '</td>';
  670. if (! empty($conf->stock->enabled))
  671. {
  672. if (empty($conf->productbatch->enabled)) {
  673. print '<td align="left">'.$langs->trans("Warehouse").' / '.$langs->trans("Stock").'</td>';
  674. } else {
  675. print '<td align="left">'.$langs->trans("Warehouse").' / '.$langs->trans("Batch").' / '.$langs->trans("Stock").'</td>';
  676. }
  677. }
  678. print "</tr>\n";
  679. }
  680. $var=true;
  681. $indiceAsked = 0;
  682. while ($indiceAsked < $numAsked)
  683. {
  684. $product = new Product($db);
  685. $line = $object->lines[$indiceAsked];
  686. $var=!$var;
  687. // Show product and description
  688. $type=$line->product_type?$line->product_type:$line->fk_product_type;
  689. // Try to enhance type detection using date_start and date_end for free lines where type
  690. // was not saved.
  691. if (! empty($line->date_start)) $type=1;
  692. if (! empty($line->date_end)) $type=1;
  693. print "<tr ".$bc[$var].">\n";
  694. // Product label
  695. if ($line->fk_product > 0)
  696. {
  697. $product->fetch($line->fk_product);
  698. $product->load_stock();
  699. print '<td>';
  700. print '<a name="'.$line->rowid.'"></a>'; // ancre pour retourner sur la ligne
  701. // Show product and description
  702. $product_static->type=$line->fk_product_type;
  703. $product_static->id=$line->fk_product;
  704. $product_static->ref=$line->ref;
  705. $text=$product_static->getNomUrl(1);
  706. $text.= ' - '.(! empty($line->label)?$line->label:$line->product_label);
  707. $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->desc));
  708. print $form->textwithtooltip($text,$description,3,'','',$i);
  709. // Show range
  710. print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
  711. // Add description in form
  712. if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
  713. {
  714. print ($line->desc && $line->desc!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->desc):'';
  715. }
  716. print '</td>';
  717. }
  718. else
  719. {
  720. print "<td>";
  721. if ($type==1) $text = img_object($langs->trans('Service'),'service');
  722. else $text = img_object($langs->trans('Product'),'product');
  723. if (! empty($line->label)) {
  724. $text.= ' <strong>'.$line->label.'</strong>';
  725. print $form->textwithtooltip($text,$line->desc,3,'','',$i);
  726. } else {
  727. print $text.' '.nl2br($line->desc);
  728. }
  729. // Show range
  730. print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
  731. print "</td>\n";
  732. }
  733. // Qty
  734. print '<td align="center">'.$line->qty;
  735. print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
  736. print '</td>';
  737. $qtyProdCom=$line->qty;
  738. // Qty already sent
  739. print '<td align="center">';
  740. $quantityDelivered = $object->expeditions[$line->id];
  741. print $quantityDelivered;
  742. print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
  743. print '</td>';
  744. $quantityAsked = $line->qty;
  745. $quantityToBeDelivered = $quantityAsked - $quantityDelivered;
  746. $defaultqty=0;
  747. if (GETPOST('entrepot_id','int') > 0)
  748. {
  749. //var_dump($product);
  750. $stock = $product->stock_warehouse[GETPOST('entrepot_id','int')]->real;
  751. $stock+=0; // Convertit en numerique
  752. $defaultqty=min($quantityToBeDelivered, $stock);
  753. if (($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES)) || $defaultqty < 0) $defaultqty=0;
  754. }
  755. if (empty($conf->productbatch->enabled) || ! ($product->hasbatch() and is_array($product->stock_warehouse[GETPOST('entrepot_id','int')])))
  756. {
  757. // Quantity to send
  758. print '<td align="center">';
  759. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  760. {
  761. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  762. print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$defaultqty.'">';
  763. }
  764. else print $langs->trans("NA");
  765. print '</td>';
  766. // Stock
  767. if (! empty($conf->stock->enabled))
  768. {
  769. print '<td align="left">';
  770. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  771. {
  772. // Show warehouse combo list
  773. $ent = "entl".$indiceAsked;
  774. $idl = "idl".$indiceAsked;
  775. $tmpentrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int');
  776. print $formproduct->selectWarehouses($tmpentrepot_id,'entl'.$indiceAsked,'',1,0,$line->fk_product);
  777. if ($tmpentrepot_id > 0 && $tmpentrepot_id == GETPOST('entrepot_id','int'))
  778. {
  779. //print $stock.' '.$quantityToBeDelivered;
  780. if ($stock < $quantityToBeDelivered)
  781. {
  782. print ' '.img_warning($langs->trans("StockTooLow")); // Stock too low for entrepot_id but we may have change warehouse
  783. }
  784. }
  785. }
  786. else
  787. {
  788. print $langs->trans("Service");
  789. }
  790. print '</td>';
  791. }
  792. print "</tr>\n";
  793. // Show subproducts of product
  794. if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)
  795. {
  796. $product->get_sousproduits_arbo();
  797. $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
  798. if(count($prods_arbo) > 0)
  799. {
  800. foreach($prods_arbo as $key => $value)
  801. {
  802. //print $value[0];
  803. $img='';
  804. if ($value['stock'] < $value['stock_alert'])
  805. {
  806. $img=img_warning($langs->trans("StockTooLow"));
  807. }
  808. print "<tr ".$bc[$var]."><td>&nbsp; &nbsp; &nbsp; ->
  809. <a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$value['id']."\">".$value['fullpath']."
  810. </a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
  811. <td align=\"center\">".$value['stock']." ".$img."</td></tr>";
  812. }
  813. }
  814. }
  815. } else {
  816. print '<td></td><td></td></tr>';
  817. $subj=0;
  818. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  819. foreach ($product->stock_warehouse[GETPOST('entrepot_id','int')]->detail_batch as $dbatch) {
  820. //var_dump($dbatch);
  821. $substock=$dbatch->qty +0 ;
  822. print '<tr><td colspan="3" ></td><td align="center">';
  823. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.min($defaultqty,$substock).'">';
  824. print '</td>';
  825. print '<td align="left">';
  826. print '<input name="batchl'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$dbatch->id.'">';
  827. print $langs->trans("DetailBatchFormat", dol_print_date($dbatch->eatby,"day"), dol_print_date($dbatch->sellby,"day"), $dbatch->batch, $dbatch->qty);
  828. if ($defaultqty<=0) {
  829. $defaultqty=0;
  830. } else {
  831. $defaultqty -=min($defaultqty,$substock);
  832. }
  833. $subj++;
  834. }
  835. }
  836. $indiceAsked++;
  837. }
  838. print "</table>";
  839. print '<br><center><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';
  840. print '</form>';
  841. print '<br>';
  842. }
  843. else
  844. {
  845. dol_print_error($db);
  846. }
  847. }
  848. }
  849. else if ($id || $ref)
  850. /* *************************************************************************** */
  851. /* */
  852. /* Edit and view mode */
  853. /* */
  854. /* *************************************************************************** */
  855. {
  856. $lines = $object->lines;
  857. $num_prod = count($lines);
  858. if ($object->id > 0)
  859. {
  860. dol_htmloutput_mesg($mesg);
  861. if (!empty($object->origin))
  862. {
  863. $typeobject = $object->origin;
  864. $origin = $object->origin;
  865. $object->fetch_origin();
  866. }
  867. $soc = new Societe($db);
  868. $soc->fetch($object->socid);
  869. $head=shipping_prepare_head($object);
  870. dol_fiche_head($head, 'shipping', $langs->trans("Shipment"), 0, 'sending');
  871. dol_htmloutput_mesg($mesg);
  872. /*
  873. * Confirmation de la suppression
  874. */
  875. if ($action == 'delete')
  876. {
  877. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$object->ref),'confirm_delete','',0,1);
  878. }
  879. /*
  880. * Confirmation de la validation
  881. */
  882. if ($action == 'valid')
  883. {
  884. $objectref = substr($object->ref, 1, 4);
  885. if ($objectref == 'PROV')
  886. {
  887. $numref = $object->getNextNumRef($soc);
  888. }
  889. else
  890. {
  891. $numref = $object->ref;
  892. }
  893. $text = $langs->trans("ConfirmValidateSending",$numref);
  894. if (! empty($conf->notification->enabled))
  895. {
  896. require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
  897. $notify=new Notify($db);
  898. $text.='<br>';
  899. $text.=$notify->confirmMessage('SHIPPING_VALIDATE',$object->socid);
  900. }
  901. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$text,'confirm_valid','',0,1);
  902. }
  903. /*
  904. * Confirmation de l'annulation
  905. */
  906. if ($action == 'annuler')
  907. {
  908. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$object->ref),'confirm_cancel','',0,1);
  909. }
  910. // Calculate true totalWeight and totalVolume for all products
  911. // by adding weight and volume of each product line.
  912. $totalWeight = '';
  913. $totalVolume = '';
  914. $weightUnit=0;
  915. $volumeUnit=0;
  916. for ($i = 0 ; $i < $num_prod ; $i++)
  917. {
  918. $weightUnit=0;
  919. $volumeUnit=0;
  920. if (! empty($lines[$i]->weight_units)) $weightUnit = $lines[$i]->weight_units;
  921. if (! empty($lines[$i]->volume_units)) $volumeUnit = $lines[$i]->volume_units;
  922. // TODO Use a function addvalueunits(val1,unit1,val2,unit2)=>(val,unit)
  923. if ($lines[$i]->weight_units < 50)
  924. {
  925. $trueWeightUnit=pow(10,$weightUnit);
  926. $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped*$trueWeightUnit;
  927. }
  928. else
  929. {
  930. $trueWeightUnit=$weightUnit;
  931. $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped;
  932. }
  933. if ($lines[$i]->volume_units < 50)
  934. {
  935. //print $lines[$i]->volume."x".$lines[$i]->volume_units."x".($lines[$i]->volume_units < 50)."x".$volumeUnit;
  936. $trueVolumeUnit=pow(10,$volumeUnit);
  937. //print $lines[$i]->volume;
  938. $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped*$trueVolumeUnit;
  939. }
  940. else
  941. {
  942. $trueVolumeUnit=$volumeUnit;
  943. $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped;
  944. }
  945. }
  946. print '<table class="border" width="100%">';
  947. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/liste.php">'.$langs->trans("BackToList").'</a>';
  948. // Ref
  949. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  950. print '<td colspan="3">';
  951. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  952. print '</td></tr>';
  953. // Customer
  954. print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
  955. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  956. print "</tr>";
  957. // Linked documents
  958. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  959. {
  960. print '<tr><td>';
  961. $objectsrc=new Commande($db);
  962. $objectsrc->fetch($object->$typeobject->id);
  963. print $langs->trans("RefOrder").'</td>';
  964. print '<td colspan="3">';
  965. print $objectsrc->getNomUrl(1,'commande');
  966. print "</td>\n";
  967. print '</tr>';
  968. }
  969. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  970. {
  971. print '<tr><td>';
  972. $objectsrc=new Propal($db);
  973. $objectsrc->fetch($object->$typeobject->id);
  974. print $langs->trans("RefProposal").'</td>';
  975. print '<td colspan="3">';
  976. print $objectsrc->getNomUrl(1,'expedition');
  977. print "</td>\n";
  978. print '</tr>';
  979. }
  980. // Ref customer
  981. print '<tr><td>'.$langs->trans("RefCustomer").'</td>';
  982. print '<td colspan="3">'.$object->ref_customer."</a></td>\n";
  983. print '</tr>';
  984. // Date creation
  985. print '<tr><td>'.$langs->trans("DateCreation").'</td>';
  986. print '<td colspan="3">'.dol_print_date($object->date_creation,"day")."</td>\n";
  987. print '</tr>';
  988. // Delivery date planned
  989. print '<tr><td height="10">';
  990. print '<table class="nobordernopadding" width="100%"><tr><td>';
  991. print $langs->trans('DateDeliveryPlanned');
  992. print '</td>';
  993. 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>';
  994. print '</tr></table>';
  995. print '</td><td colspan="2">';
  996. if ($action == 'editdate_livraison')
  997. {
  998. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  999. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1000. print '<input type="hidden" name="action" value="setdate_livraison">';
  1001. $form->select_date($object->date_delivery?$object->date_delivery:-1,'liv_',1,1,'',"setdate_livraison");
  1002. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1003. print '</form>';
  1004. }
  1005. else
  1006. {
  1007. print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhourtext') : '&nbsp;';
  1008. }
  1009. print '</td>';
  1010. print '</tr>';
  1011. // Weight
  1012. print '<tr><td>'.$form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1013. if($action=='edittrueWeight') {
  1014. print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1015. print '<input name="action" value="settrueWeight" type="hidden">';
  1016. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1017. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1018. print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
  1019. print $formproduct->select_measuring_units("weight_units","weight",$object->weight_units);
  1020. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1021. print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1022. print '</form>';
  1023. }
  1024. else {
  1025. print $object->trueWeight;
  1026. print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):'';
  1027. }
  1028. if ($totalWeight > 0)
  1029. {
  1030. if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
  1031. print $totalWeight.' '.measuring_units_string(0,"weight");
  1032. if (!empty($object->trueWeight)) print ')';
  1033. }
  1034. print '</td></tr>';
  1035. // Width
  1036. print '<tr><td>'.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1037. print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer);
  1038. print ($object->trueWidth && $object->width_units!='')?' '.measuring_units_string($object->width_units,"size"):'';
  1039. print '</td></tr>';
  1040. // Height
  1041. print '<tr><td>'.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1042. if($action=='edittrueHeight') {
  1043. print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1044. print '<input name="action" value="settrueHeight" type="hidden">';
  1045. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1046. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1047. print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
  1048. print $formproduct->select_measuring_units("size_units","size",$object->size_units);
  1049. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1050. print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1051. print '</form>';
  1052. }
  1053. else {
  1054. print $object->trueHeight;
  1055. print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):'';
  1056. }
  1057. print '</td></tr>';
  1058. // Depth
  1059. print '<tr><td>'.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1060. print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer);
  1061. print ($object->trueDepth && $object->depth_units!='')?' '.measuring_units_string($object->depth_units,"size"):'';
  1062. print '</td></tr>';
  1063. // Volume
  1064. print '<tr><td>';
  1065. print $langs->trans("Volume");
  1066. print '</td>';
  1067. print '<td colspan="3">';
  1068. $calculatedVolume=0;
  1069. if ($object->trueWidth && $object->trueHeight && $object->trueDepth) $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
  1070. // If sending volume not defined we use sum of products
  1071. if ($calculatedVolume > 0)
  1072. {
  1073. print $calculatedVolume.' ';
  1074. if ($volumeUnit < 50) print measuring_units_string(0,"volume");
  1075. else print measuring_units_string($volumeUnit,"volume");
  1076. }
  1077. if ($totalVolume > 0)
  1078. {
  1079. if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
  1080. print $totalVolume.' '.measuring_units_string(0,"volume");
  1081. if ($calculatedVolume) print ')';
  1082. }
  1083. print "</td>\n";
  1084. print '</tr>';
  1085. // Status
  1086. print '<tr><td>'.$langs->trans("Status").'</td>';
  1087. print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
  1088. print '</tr>';
  1089. // Sending method
  1090. print '<tr><td height="10">';
  1091. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1092. print $langs->trans('SendingMethod');
  1093. print '</td>';
  1094. if ($action != 'editshipping_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetSendingMethod'),1).'</a></td>';
  1095. print '</tr></table>';
  1096. print '</td><td colspan="2">';
  1097. if ($action == 'editshipping_method_id')
  1098. {
  1099. print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1100. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1101. print '<input type="hidden" name="action" value="setshipping_method_id">';
  1102. $object->fetch_delivery_methods();
  1103. print $form->selectarray("shipping_method_id",$object->meths,$object->shipping_method_id,1,0,0,"",1);
  1104. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  1105. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1106. print '</form>';
  1107. }
  1108. else
  1109. {
  1110. if ($object->shipping_method_id > 0)
  1111. {
  1112. // Get code using getLabelFromKey
  1113. $code=$langs->getLabelFromKey($db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
  1114. print $langs->trans("SendingMethod".strtoupper($code));
  1115. }
  1116. }
  1117. print '</td>';
  1118. print '</tr>';
  1119. // Tracking Number
  1120. print '<tr><td>'.$form->editfieldkey("TrackingNumber",'trackingnumber',$object->tracking_number,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1121. print $form->editfieldval("TrackingNumber",'trackingnumber',$object->tracking_url,$object,$user->rights->expedition->creer,'string',$object->tracking_number);
  1122. print '</td></tr>';
  1123. // Other attributes
  1124. $parameters=array('colspan' => ' colspan="3"');
  1125. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1126. print "</table>\n";
  1127. /*
  1128. * Lignes produits
  1129. */
  1130. print '<br><table class="noborder" width="100%">';
  1131. print '<tr class="liste_titre">';
  1132. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1133. {
  1134. print '<td width="5" align="center">&nbsp;</td>';
  1135. }
  1136. print '<td>'.$langs->trans("Products").'</td>';
  1137. print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
  1138. if ($object->statut <= 1)
  1139. {
  1140. print '<td align="center">'.$langs->trans("QtyToShip").'</td>';
  1141. }
  1142. else
  1143. {
  1144. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  1145. }
  1146. print '<td align="center">'.$langs->trans("CalculatedWeight").'</td>';
  1147. print '<td align="center">'.$langs->trans("CalculatedVolume").'</td>';
  1148. //print '<td align="center">'.$langs->trans("Size").'</td>';
  1149. if (! empty($conf->stock->enabled))
  1150. {
  1151. print '<td align="left">'.$langs->trans("WarehouseSource").'</td>';
  1152. }
  1153. if (! empty($conf->productbatch->enabled))
  1154. {
  1155. print '<td align="left">'.$langs->trans("Batch").'</td>';
  1156. }
  1157. print "</tr>\n";
  1158. $var=false;
  1159. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1160. {
  1161. $object->fetch_thirdparty();
  1162. $outputlangs = $langs;
  1163. $newlang='';
  1164. if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
  1165. if (empty($newlang)) $newlang=$object->client->default_lang;
  1166. if (! empty($newlang))
  1167. {
  1168. $outputlangs = new Translate("",$conf);
  1169. $outputlangs->setDefaultLang($newlang);
  1170. }
  1171. }
  1172. for ($i = 0 ; $i < $num_prod ; $i++)
  1173. {
  1174. print "<tr ".$bc[$var].">";
  1175. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1176. {
  1177. print '<td align="center">'.($i+1).'</td>';
  1178. }
  1179. // Predefined product or service
  1180. if ($lines[$i]->fk_product > 0)
  1181. {
  1182. // Define output language
  1183. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1184. {
  1185. $prod = new Product($db);
  1186. $prod->fetch($lines[$i]->fk_product);
  1187. $label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;
  1188. }
  1189. else
  1190. $label = (! empty($lines[$i]->label)?$lines[$i]->label:$lines[$i]->product_label);
  1191. print '<td>';
  1192. // Show product and description
  1193. $product_static->type=$lines[$i]->fk_product_type;
  1194. $product_static->id=$lines[$i]->fk_product;
  1195. $product_static->ref=$lines[$i]->ref;
  1196. $text=$product_static->getNomUrl(1);
  1197. $text.= ' - '.$label;
  1198. $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($lines[$i]->description));
  1199. print $form->textwithtooltip($text,$description,3,'','',$i);
  1200. print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
  1201. if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
  1202. {
  1203. print (! empty($lines[$i]->description) && $lines[$i]->description!=$lines[$i]->product)?'<br>'.dol_htmlentitiesbr($lines[$i]->description):'';
  1204. }
  1205. }
  1206. else
  1207. {
  1208. print "<td>";
  1209. if ($lines[$i]->fk_product_type==1) $text = img_object($langs->trans('Service'),'service');
  1210. else $text = img_object($langs->trans('Product'),'product');
  1211. if (! empty($lines[$i]->label)) {
  1212. $text.= ' <strong>'.$lines[$i]->label.'</strong>';
  1213. print $form->textwithtooltip($text,$lines[$i]->description,3,'','',$i);
  1214. } else {
  1215. print $text.' '.nl2br($lines[$i]->description);
  1216. }
  1217. print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
  1218. print "</td>\n";
  1219. }
  1220. // Qte commande
  1221. print '<td align="center">'.$lines[$i]->qty_asked.'</td>';
  1222. // Qte a expedier ou expedier
  1223. print '<td align="center">'.$lines[$i]->qty_shipped.'</td>';
  1224. // Weight
  1225. print '<td align="center">';
  1226. if ($lines[$i]->fk_product_type == 0) print $lines[$i]->weight*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->weight_units,"weight");
  1227. else print '&nbsp;';
  1228. print '</td>';
  1229. // Volume
  1230. print '<td align="center">';
  1231. if ($lines[$i]->fk_product_type == 0) print $lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume");
  1232. else print '&nbsp;';
  1233. print '</td>';
  1234. // Size
  1235. //print '<td align="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume").'</td>';
  1236. // Entrepot source
  1237. if (! empty($conf->stock->enabled))
  1238. {
  1239. print '<td align="left">';
  1240. if ($lines[$i]->entrepot_id > 0)
  1241. {
  1242. $entrepot = new Entrepot($db);
  1243. $entrepot->fetch($lines[$i]->entrepot_id);
  1244. print $entrepot->getNomUrl(1);
  1245. }
  1246. print '</td>';
  1247. }
  1248. // Batch number managment
  1249. if (! empty($conf->productbatch->enabled)) {
  1250. if (isset($lines[$i]->detail_batch) ) {
  1251. print '<td align="center">';
  1252. $detail = '';
  1253. foreach ($lines[$i]->detail_batch as $dbatch) {
  1254. $detail.= $langs->trans("DetailBatchFormat",dol_print_date($dbatch->eatby,"day"),dol_print_date($dbatch->sellby,"day"),$dbatch->batch,$dbatch->dluo_qty).'<br/>';
  1255. }
  1256. print $form->textwithtooltip($langs->trans("DetailBatchNumber"),$detail);
  1257. print '</td>';
  1258. } else {
  1259. print '<td></td>';
  1260. }
  1261. }
  1262. print "</tr>";
  1263. $var=!$var;
  1264. }
  1265. }
  1266. print "</table>\n";
  1267. print "\n</div>\n";
  1268. $object->fetchObjectLinked($object->id,$object->element);
  1269. /*
  1270. * Boutons actions
  1271. */
  1272. if (($user->societe_id == 0) && ($action!='presend'))
  1273. {
  1274. print '<div class="tabsAction">';
  1275. if ($object->statut == 0 && $num_prod > 0)
  1276. {
  1277. if ($user->rights->expedition->valider)
  1278. {
  1279. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
  1280. }
  1281. else
  1282. {
  1283. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
  1284. }
  1285. }
  1286. // TODO add alternative status
  1287. /* if ($object->statut == 1 && $user->rights->expedition->valider)
  1288. {
  1289. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
  1290. }*/
  1291. // Send
  1292. if ($object->statut > 0)
  1293. {
  1294. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send)
  1295. {
  1296. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
  1297. }
  1298. else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
  1299. }
  1300. // Create bill and Close shipment
  1301. if (! empty($conf->facture->enabled) && $object->statut > 0)
  1302. {
  1303. if ($user->rights->facture->creer)
  1304. {
  1305. 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>';
  1306. }
  1307. }
  1308. // This is just to generate a delivery receipt
  1309. if ($conf->livraison_bon->enabled && ($object->statut == 1 || $object->statut == 2) && $user->rights->expedition->livraison->creer && empty($object->linkedObjectsIds['delivery'][0]))
  1310. {
  1311. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=create_delivery">'.$langs->trans("CreateDeliveryOrder").'</a>';
  1312. }
  1313. // Close
  1314. if (! empty($conf->facture->enabled) && $object->statut > 0)
  1315. {
  1316. if ($user->rights->expedition->creer && $object->statut > 0 && ! $object->billed)
  1317. {
  1318. $label="Close";
  1319. // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders
  1320. if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) $label="ClassifyBilled";
  1321. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans($label).'</a>';
  1322. }
  1323. }
  1324. if ($user->rights->expedition->supprimer)
  1325. {
  1326. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
  1327. }
  1328. print '</div>';
  1329. print "<br>\n";
  1330. }
  1331. /*
  1332. * Documents generated
  1333. */
  1334. if ($action != 'presend')
  1335. {
  1336. print '<table width="100%"><tr><td width="50%" valign="top">';
  1337. $objectref = dol_sanitizeFileName($object->ref);
  1338. $filedir = $conf->expedition->dir_output . "/sending/" .$objectref;
  1339. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1340. $genallowed=$user->rights->expedition->lire;
  1341. $delallowed=$user->rights->expedition->supprimer;
  1342. $somethingshown=$formfile->show_documents('expedition',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
  1343. /*
  1344. * Linked object block
  1345. */
  1346. $somethingshown=$object->showLinkedObjectBlock();
  1347. if ($genallowed && ! $somethingshown) $somethingshown=1;
  1348. print '</td><td valign="top" width="50%">';
  1349. // List of actions on element
  1350. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1351. $formactions=new FormActions($db);
  1352. $somethingshown=$formactions->showactions($object,'shipping',$socid);
  1353. print '</td></tr></table>';
  1354. }
  1355. /*
  1356. * Action presend
  1357. */
  1358. if ($action == 'presend')
  1359. {
  1360. $ref = dol_sanitizeFileName($object->ref);
  1361. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  1362. $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/'));
  1363. $file=$fileparams['fullname'];
  1364. // Build document if it not exists
  1365. if (! $file || ! is_readable($file))
  1366. {
  1367. // Define output language
  1368. $outputlangs = $langs;
  1369. $newlang='';
  1370. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  1371. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  1372. if (! empty($newlang))
  1373. {
  1374. $outputlangs = new Translate("",$conf);
  1375. $outputlangs->setDefaultLang($newlang);
  1376. }
  1377. $result=expedition_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1378. if ($result <= 0)
  1379. {
  1380. dol_print_error($db,$result);
  1381. exit;
  1382. }
  1383. $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/'));
  1384. $file=$fileparams['fullname'];
  1385. }
  1386. print '<br>';
  1387. print_titre($langs->trans('SendShippingByEMail'));
  1388. // Cree l'objet formulaire mail
  1389. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  1390. $formmail = new FormMail($db);
  1391. $formmail->fromtype = 'user';
  1392. $formmail->fromid = $user->id;
  1393. $formmail->fromname = $user->getFullName($langs);
  1394. $formmail->frommail = $user->email;
  1395. $formmail->withfrom=1;
  1396. $liste=array();
  1397. foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
  1398. $formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
  1399. $formmail->withtocc=$liste;
  1400. $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
  1401. $formmail->withtopic=$langs->trans('SendShippingRef','__SHIPPINGREF__');
  1402. $formmail->withfile=2;
  1403. $formmail->withbody=1;
  1404. $formmail->withdeliveryreceipt=1;
  1405. $formmail->withcancel=1;
  1406. // Tableau des substitutions
  1407. $formmail->substit['__SHIPPINGREF__']=$object->ref;
  1408. $formmail->substit['__SIGNATURE__']=$user->signature;
  1409. $formmail->substit['__PERSONALIZED__']='';
  1410. $formmail->substit['__CONTACTCIVNAME__']='';
  1411. //Find the good contact adress
  1412. //Find the good contact adress
  1413. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled)) {
  1414. $objectsrc=new Commande($db);
  1415. $objectsrc->fetch($object->$typeobject->id);
  1416. }
  1417. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled)) {
  1418. $objectsrc=new Propal($db);
  1419. $objectsrc->fetch($object->$typeobject->id);
  1420. }
  1421. $custcontact='';
  1422. $contactarr=array();
  1423. $contactarr=$objectsrc->liste_contact(-1,'external');
  1424. if (is_array($contactarr) && count($contactarr)>0) {
  1425. foreach($contactarr as $contact) {
  1426. if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
  1427. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  1428. $contactstatic=new Contact($db);
  1429. $contactstatic->fetch($contact['id']);
  1430. $custcontact=$contactstatic->getFullName($langs,1);
  1431. }
  1432. }
  1433. if (!empty($custcontact)) {
  1434. $formmail->substit['__CONTACTCIVNAME__']=$custcontact;
  1435. }
  1436. }
  1437. // Tableau des parametres complementaires
  1438. $formmail->param['action']='send';
  1439. $formmail->param['models']='shipping_send';
  1440. $formmail->param['shippingid']=$object->id;
  1441. $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  1442. // Init list of files
  1443. if (GETPOST("mode")=='init')
  1444. {
  1445. $formmail->clear_attached_files();
  1446. $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
  1447. }
  1448. // Show form
  1449. print $formmail->get_form();
  1450. print '<br>';
  1451. }
  1452. if ($action != 'presend' && ! empty($origin) && $object->$origin->id)
  1453. {
  1454. print '<br>';
  1455. //show_list_sending_receive($object->origin,$object->origin_id," AND e.rowid <> ".$object->id);
  1456. show_list_sending_receive($object->origin,$object->origin_id);
  1457. }
  1458. }
  1459. llxFooter();
  1460. $db->close();