card.php 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  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. * Copyright (C) 2014-2015 Francis Appels <francis.appels@yahoo.com>
  11. * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
  12. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/expedition/card.php
  29. * \ingroup expedition
  30. * \brief Fiche descriptive d'une expedition
  31. */
  32. require '../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  40. require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
  41. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  42. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  43. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  44. if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  45. if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
  46. $langs->load("sendings");
  47. $langs->load("companies");
  48. $langs->load("bills");
  49. $langs->load('deliveries');
  50. $langs->load('orders');
  51. $langs->load('stocks');
  52. $langs->load('other');
  53. $langs->load('propal');
  54. if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
  55. if (! empty($conf->productbatch->enabled)) $langs->load('productbatch');
  56. $origin = GETPOST('origin','alpha')?GETPOST('origin','alpha'):'expedition'; // Example: commande, propal
  57. $origin_id = GETPOST('id','int')?GETPOST('id','int'):'';
  58. $id = $origin_id;
  59. if (empty($origin_id)) $origin_id = GETPOST('origin_id','int'); // Id of order or propal
  60. if (empty($origin_id)) $origin_id = GETPOST('object_id','int'); // Id of order or propal
  61. $ref=GETPOST('ref','alpha');
  62. // Security check
  63. $socid='';
  64. if ($user->societe_id) $socid=$user->societe_id;
  65. $result=restrictedArea($user, $origin, $origin_id);
  66. $action = GETPOST('action','alpha');
  67. $confirm = GETPOST('confirm','alpha');
  68. //PDF
  69. $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  70. $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  71. $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  72. $object = new Expedition($db);
  73. $extrafields = new ExtraFields($db);
  74. $extrafieldsline = new ExtraFields($db);
  75. // fetch optionals attributes and labels
  76. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  77. // fetch optionals attributes lines and labels
  78. $extralabelslines=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  79. // Load object. Make an object->fetch
  80. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  81. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  82. $hookmanager->initHooks(array('expeditioncard','globalcard'));
  83. $permissiondellink=$user->rights->expedition->livraison->creer; // Used by the include of actions_dellink.inc.php
  84. /*
  85. * Actions
  86. */
  87. $parameters=array();
  88. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  89. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  90. if (empty($reshook))
  91. {
  92. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  93. // Set incoterm
  94. if ($action == 'reopen' && $user->rights->expedition->creer)
  95. {
  96. $object->fetch($id);
  97. $result = $object->reOpen();
  98. }
  99. // Set incoterm
  100. if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
  101. {
  102. $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
  103. }
  104. if ($action == 'update_extras')
  105. {
  106. // Fill array 'array_options' with data from update form
  107. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  108. $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
  109. if ($ret < 0) $error++;
  110. if (! $error)
  111. {
  112. // Actions on extra fields (by external module or standard code)
  113. // TODO le hook fait double emploi avec le trigger !!
  114. $hookmanager->initHooks(array('expeditiondao'));
  115. $parameters = array('id' => $object->id);
  116. $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  117. if (empty($reshook)) {
  118. $result = $object->insertExtraFields();
  119. if ($result < 0) {
  120. $error++;
  121. }
  122. } else if ($reshook < 0)
  123. $error++;
  124. }
  125. if ($error)
  126. $action = 'edit_extras';
  127. }
  128. // Create shipment
  129. if ($action == 'add' && $user->rights->expedition->creer)
  130. {
  131. $error=0;
  132. $predef='';
  133. $db->begin();
  134. $object->note = GETPOST('note','alpha');
  135. $object->origin = $origin;
  136. $object->origin_id = $origin_id;
  137. $object->weight = GETPOST('weight','int')==''?"NULL":GETPOST('weight','int');
  138. $object->sizeH = GETPOST('sizeH','int')==''?"NULL":GETPOST('sizeH','int');
  139. $object->sizeW = GETPOST('sizeW','int')==''?"NULL":GETPOST('sizeW','int');
  140. $object->sizeS = GETPOST('sizeS','int')==''?"NULL":GETPOST('sizeS','int');
  141. $object->size_units = GETPOST('size_units','int');
  142. $object->weight_units = GETPOST('weight_units','int');
  143. $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'));
  144. // On va boucler sur chaque ligne du document d'origine pour completer objet expedition
  145. // avec info diverses + qte a livrer
  146. $classname = ucfirst($object->origin);
  147. $objectsrc = new $classname($db);
  148. $objectsrc->fetch($object->origin_id);
  149. $object->socid = $objectsrc->socid;
  150. $object->ref_customer = $objectsrc->ref_client;
  151. $object->model_pdf = GETPOST('model');
  152. $object->date_delivery = $date_delivery; // Date delivery planed
  153. $object->fk_delivery_address = $objectsrc->fk_delivery_address;
  154. $object->shipping_method_id = GETPOST('shipping_method_id','int');
  155. $object->tracking_number = GETPOST('tracking_number','alpha');
  156. $object->ref_int = GETPOST('ref_int','alpha');
  157. $object->note_private = GETPOST('note_private');
  158. $object->note_public = GETPOST('note_public');
  159. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  160. $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
  161. $batch_line = array();
  162. $stockLine = array();
  163. $array_options=array();
  164. $num=count($objectsrc->lines);
  165. $totalqty=0;
  166. for ($i = 0; $i < $num; $i++)
  167. {
  168. $idl="idl".$i;
  169. $sub_qty=array();
  170. $subtotalqty=0;
  171. $j=0;
  172. $batch="batchl".$i."_0";
  173. $stockLocation="ent1".$i."_0";
  174. $qty = "qtyl".$i;
  175. if (isset($_POST[$batch]))
  176. {
  177. //shipment line with batch-enable product
  178. $qty .= '_'.$j;
  179. while (isset($_POST[$batch]))
  180. {
  181. // save line of detail into sub_qty
  182. $sub_qty[$j]['q']=GETPOST($qty,'int'); // the qty we want to move for this stock record
  183. $sub_qty[$j]['id_batch']=GETPOST($batch,'int'); // the id into llx_product_batch of stock record to move
  184. $subtotalqty+=$sub_qty[$j]['q'];
  185. //var_dump($qty);var_dump($batch);var_dump($sub_qty[$j]['q']);var_dump($sub_qty[$j]['id_batch']);
  186. $j++;
  187. $batch="batchl".$i."_".$j;
  188. $qty = "qtyl".$i.'_'.$j;
  189. }
  190. $batch_line[$i]['detail']=$sub_qty; // array of details
  191. $batch_line[$i]['qty']=$subtotalqty;
  192. $batch_line[$i]['ix_l']=GETPOST($idl,'int');
  193. $totalqty+=$subtotalqty;
  194. }
  195. else if (isset($_POST[$stockLocation]))
  196. {
  197. //shipment line from multiple stock locations
  198. $qty .= '_'.$j;
  199. while (isset($_POST[$stockLocation]))
  200. {
  201. // save sub line of warehouse
  202. $stockLine[$i][$j]['qty']=GETPOST($qty,'int');
  203. $stockLine[$i][$j]['warehouse_id']=GETPOST($stockLocation,'int');
  204. $stockLine[$i][$j]['ix_l']=GETPOST($idl,'int');
  205. $totalqty+=GETPOST($qty,'int');
  206. $j++;
  207. $stockLocation="ent1".$i."_".$j;
  208. $qty = "qtyl".$i.'_'.$j;
  209. }
  210. }
  211. else
  212. {
  213. //var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit;
  214. //shipment line for product with no batch management and no multiple stock location
  215. if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int');
  216. }
  217. // Extrafields
  218. $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  219. $array_options[$i] = $extrafieldsline->getOptionalsFromPost($extralabelsline, $i);
  220. // Unset extrafield
  221. if (is_array($extralabelsline)) {
  222. // Get extra fields
  223. foreach ($extralabelsline as $key => $value) {
  224. unset($_POST["options_" . $key]);
  225. }
  226. }
  227. }
  228. //var_dump($batch_line[2]);
  229. if ($totalqty > 0) // There is at least one thing to ship
  230. {
  231. //var_dump($_POST);exit;
  232. for ($i = 0; $i < $num; $i++)
  233. {
  234. $qty = "qtyl".$i;
  235. if (! isset($batch_line[$i]))
  236. {
  237. // not batch mode
  238. if (isset($stockLine[$i]))
  239. {
  240. //shipment from multiple stock locations
  241. $nbstockline = count($stockLine[$i]);
  242. for($j = 0; $j < $nbstockline; $j++)
  243. {
  244. if ($stockLine[$i][$j]['qty']>0)
  245. {
  246. $ret=$object->addline($stockLine[$i][$j]['warehouse_id'], $stockLine[$i][$j]['ix_l'], $stockLine[$i][$j]['qty'], $array_options[$i]);
  247. if ($ret < 0)
  248. {
  249. setEventMessages($object->error, $object->errors, 'errors');
  250. $error++;
  251. }
  252. }
  253. }
  254. }
  255. else
  256. {
  257. if (GETPOST($qty,'int') > 0 || (GETPOST($qty,'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS))
  258. {
  259. $ent = "entl".$i;
  260. $idl = "idl".$i;
  261. $entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int');
  262. if ($entrepot_id < 0) $entrepot_id='';
  263. if (! ($objectsrc->lines[$i]->fk_product > 0)) $entrepot_id = 0;
  264. $ret=$object->addline($entrepot_id, GETPOST($idl,'int'), GETPOST($qty,'int'), $array_options[$i]);
  265. if ($ret < 0)
  266. {
  267. setEventMessages($object->error, $object->errors, 'errors');
  268. $error++;
  269. }
  270. }
  271. }
  272. }
  273. else
  274. {
  275. // batch mode
  276. if ($batch_line[$i]['qty']>0)
  277. {
  278. $ret=$object->addline_batch($batch_line[$i],$array_options[$i]);
  279. if ($ret < 0)
  280. {
  281. setEventMessages($object->error, $object->errors, 'errors');
  282. $error++;
  283. }
  284. }
  285. }
  286. }
  287. // Fill array 'array_options' with data from add form
  288. $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
  289. if ($ret < 0) $error++;
  290. if (! $error)
  291. {
  292. $ret=$object->create($user); // This create shipment (like Odoo picking) and line of shipments. Stock movement will when validating shipment.
  293. if ($ret <= 0)
  294. {
  295. setEventMessages($object->error, $object->errors, 'errors');
  296. $error++;
  297. }
  298. }
  299. }
  300. else
  301. {
  302. setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("QtyToShip").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
  303. $error++;
  304. }
  305. if (! $error)
  306. {
  307. $db->commit();
  308. header("Location: card.php?id=".$object->id);
  309. exit;
  310. }
  311. else
  312. {
  313. $db->rollback();
  314. $_GET["commande_id"]=GETPOST('commande_id','int');
  315. $action='create';
  316. }
  317. }
  318. /*
  319. * Build a receiving receipt
  320. */
  321. else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
  322. {
  323. $result = $object->create_delivery($user);
  324. if ($result > 0)
  325. {
  326. header("Location: ".DOL_URL_ROOT.'/livraison/card.php?action=create_delivery&id='.$result);
  327. exit;
  328. }
  329. else
  330. {
  331. setEventMessages($object->error, $object->errors, 'errors');
  332. }
  333. }
  334. else if ($action == 'confirm_valid' && $confirm == 'yes' &&
  335. ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer))
  336. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate)))
  337. )
  338. {
  339. $object->fetch_thirdparty();
  340. $result = $object->valid($user);
  341. if ($result < 0)
  342. {
  343. $langs->load("errors");
  344. setEventMessages($langs->trans($object->error), null, 'errors');
  345. }
  346. else
  347. {
  348. // Define output language
  349. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  350. {
  351. $outputlangs = $langs;
  352. $newlang = '';
  353. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
  354. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  355. if (! empty($newlang)) {
  356. $outputlangs = new Translate("", $conf);
  357. $outputlangs->setDefaultLang($newlang);
  358. }
  359. $model=$object->modelpdf;
  360. $ret = $object->fetch($id); // Reload to get new records
  361. $result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  362. if ($result < 0) dol_print_error($db,$result);
  363. }
  364. }
  365. }
  366. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)
  367. {
  368. $result = $object->delete();
  369. if ($result > 0)
  370. {
  371. header("Location: ".DOL_URL_ROOT.'/expedition/index.php');
  372. exit;
  373. }
  374. else
  375. {
  376. setEventMessages($object->error, $object->errors, 'errors');
  377. }
  378. }
  379. // TODO add alternative status
  380. /*else if ($action == 'reopen' && (! empty($user->rights->expedition->creer) || ! empty($user->rights->expedition->shipping_advance->validate)))
  381. {
  382. $result = $object->setStatut(0);
  383. if ($result < 0)
  384. {
  385. setEventMessages($object->error, $object->errors, 'errors');
  386. }
  387. }*/
  388. else if ($action == 'setdate_livraison' && $user->rights->expedition->creer)
  389. {
  390. //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
  391. $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
  392. $object->fetch($id);
  393. $result=$object->set_date_livraison($user,$datedelivery);
  394. if ($result < 0)
  395. {
  396. setEventMessages($object->error, $object->errors, 'errors');
  397. }
  398. }
  399. // Action update description of emailing
  400. else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
  401. || $action == 'settrueWeight'
  402. || $action == 'settrueWidth'
  403. || $action == 'settrueHeight'
  404. || $action == 'settrueDepth'
  405. || $action == 'setshipping_method_id')
  406. {
  407. $error=0;
  408. if ($action == 'settrackingnumber') $object->tracking_number = trim(GETPOST('trackingnumber','alpha'));
  409. if ($action == 'settrackingurl') $object->tracking_url = trim(GETPOST('trackingurl','int'));
  410. if ($action == 'settrueWeight') {
  411. $object->trueWeight = trim(GETPOST('trueWeight','int'));
  412. $object->weight_units = GETPOST('weight_units','int');
  413. }
  414. if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth','int'));
  415. if ($action == 'settrueHeight'){
  416. $object->trueHeight = trim(GETPOST('trueHeight','int'));
  417. $object->size_units = GETPOST('size_units','int');
  418. }
  419. if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth','int'));
  420. if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
  421. if (! $error)
  422. {
  423. if ($object->update($user) >= 0)
  424. {
  425. header("Location: card.php?id=".$object->id);
  426. exit;
  427. }
  428. setEventMessages($object->error, $object->errors, 'errors');
  429. }
  430. $action="";
  431. }
  432. // Build document
  433. else if ($action == 'builddoc') // En get ou en post
  434. {
  435. // Save last template used to generate document
  436. if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
  437. // Define output language
  438. $outputlangs = $langs;
  439. $newlang='';
  440. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
  441. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$shipment->thirdparty->default_lang;
  442. if (! empty($newlang))
  443. {
  444. $outputlangs = new Translate("",$conf);
  445. $outputlangs->setDefaultLang($newlang);
  446. }
  447. $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  448. if ($result <= 0)
  449. {
  450. setEventMessages($object->error, $object->errors, 'errors');
  451. $action='';
  452. }
  453. }
  454. // Delete file in doc form
  455. elseif ($action == 'remove_file')
  456. {
  457. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  458. $upload_dir = $conf->expedition->dir_output . "/sending";
  459. $file = $upload_dir . '/' . GETPOST('file');
  460. $ret=dol_delete_file($file,0,0,0,$object);
  461. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  462. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  463. }
  464. elseif ($action == 'classifybilled')
  465. {
  466. $object->fetch($id);
  467. $object->set_billed();
  468. }
  469. elseif ($action == 'classifyclosed')
  470. {
  471. $object->fetch($id);
  472. $object->setClosed();
  473. }
  474. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  475. // Actions to send emails
  476. if (empty($id)) $id=$facid;
  477. $actiontypecode='AC_SHIP';
  478. $trigger_name='SHIPPING_SENTBYMAIL';
  479. $paramname='id';
  480. $mode='emailfromshipment';
  481. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  482. }
  483. /*
  484. * View
  485. */
  486. llxHeader('',$langs->trans('Shipment'),'Expedition');
  487. $form = new Form($db);
  488. $formfile = new FormFile($db);
  489. $formproduct = new FormProduct($db);
  490. $product_static = new Product($db);
  491. if ($action == 'create2')
  492. {
  493. print load_fiche_titre($langs->trans("CreateASending")).'<br>';
  494. print $langs->trans("ShipmentCreationIsDoneFromOrder");
  495. $action=''; $id=''; $ref='';
  496. }
  497. // Mode creation.
  498. if ($action == 'create')
  499. {
  500. $expe = new Expedition($db);
  501. print load_fiche_titre($langs->trans("CreateASending"));
  502. if (! $origin)
  503. {
  504. setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors');
  505. }
  506. if ($origin)
  507. {
  508. $classname = ucfirst($origin);
  509. $object = new $classname($db);
  510. if ($object->fetch($origin_id)) // This include the fetch_lines
  511. {
  512. //var_dump($object);
  513. $soc = new Societe($db);
  514. $soc->fetch($object->socid);
  515. $author = new User($db);
  516. $author->fetch($object->user_author_id);
  517. if (! empty($conf->stock->enabled)) $entrepot = new Entrepot($db);
  518. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  519. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  520. print '<input type="hidden" name="action" value="add">';
  521. print '<input type="hidden" name="origin" value="'.$origin.'">';
  522. print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
  523. print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';
  524. if (GETPOST('entrepot_id','int'))
  525. {
  526. print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id','int').'">';
  527. }
  528. dol_fiche_head('');
  529. print '<table class="border centpercent">';
  530. // Ref
  531. print '<tr><td class="fieldrequired">';
  532. if ($origin == 'commande' && ! empty($conf->commande->enabled))
  533. {
  534. print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"),'order').' '.$object->ref;
  535. }
  536. if ($origin == 'propal' && ! empty($conf->propal->enabled))
  537. {
  538. print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowProposal"),'propal').' '.$object->ref;
  539. }
  540. print '</a></td>';
  541. print "</tr>\n";
  542. // Ref client
  543. print '<tr><td>';
  544. if ($origin == 'commande') print $langs->trans('RefCustomerOrder');
  545. else if ($origin == 'propal') print $langs->trans('RefCustomerOrder');
  546. else print $langs->trans('RefCustomer');
  547. print '</td><td colspan="3">';
  548. print $object->ref_client;
  549. print '</td>';
  550. print '</tr>';
  551. // Tiers
  552. print '<tr><td class="fieldrequired">'.$langs->trans('Company').'</td>';
  553. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  554. print '</tr>';
  555. // Date delivery planned
  556. print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
  557. print '<td colspan="3">';
  558. //print dol_print_date($object->date_livraison,"day"); // date_livraison come from order and will be stored into date_delivery planed.
  559. $date_delivery = ($date_delivery?$date_delivery:$object->date_livraison); // $date_delivery comes from GETPOST
  560. print $form->select_date($date_delivery?$date_delivery:-1,'date_delivery',1,1,1);
  561. print "</td>\n";
  562. print '</tr>';
  563. // Note Public
  564. print '<tr><td>'.$langs->trans("NotePublic").'</td>';
  565. print '<td colspan="3">';
  566. $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  567. print $doleditor->Create(1);
  568. print "</td></tr>";
  569. // Note Private
  570. if ($object->note_private && ! $user->societe_id)
  571. {
  572. print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
  573. print '<td colspan="3">';
  574. $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  575. print $doleditor->Create(1);
  576. print "</td></tr>";
  577. }
  578. // Weight
  579. print '<tr><td>';
  580. print $langs->trans("Weight");
  581. print '</td><td width="90px"><input name="weight" size="5" value="'.GETPOST('weight','int').'"></td><td>';
  582. print $formproduct->select_measuring_units("weight_units","weight",GETPOST('weight_units','int'));
  583. print '</td></tr><tr><td>';
  584. print $langs->trans("Width");
  585. print ' </td><td><input name="sizeW" size="5" value="'.GETPOST('sizeW','int').'"></td><td rowspan="3">';
  586. print $formproduct->select_measuring_units("size_units","size");
  587. print '</td></tr><tr><td>';
  588. print $langs->trans("Height");
  589. print '</td><td><input name="sizeH" size="5" value="'.GETPOST('sizeH','int').'"></td>';
  590. print '</tr><tr><td>';
  591. print $langs->trans("Depth");
  592. print '</td><td><input name="sizeS" size="5" value="'.GETPOST('sizeS','int').'"></td>';
  593. print '</tr>';
  594. // Delivery method
  595. print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";
  596. print '<td colspan="3">';
  597. $expe->fetch_delivery_methods();
  598. print $form->selectarray("shipping_method_id",$expe->meths,GETPOST('shipping_method_id','int'),1,0,0,"",1);
  599. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  600. print "</td></tr>\n";
  601. // Tracking number
  602. print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
  603. print '<td colspan="3">';
  604. print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number','alpha').'">';
  605. print "</td></tr>\n";
  606. // Other attributes
  607. $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'socid'=>$socid);
  608. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$expe,$action); // Note that $action and $object may have been modified by hook
  609. if (empty($reshook) && ! empty($extrafields->attribute_label)) {
  610. print $expe->showOptionals($extrafields, 'edit');
  611. }
  612. // Incoterms
  613. if (!empty($conf->incoterm->enabled))
  614. {
  615. print '<tr>';
  616. print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->libelle_incoterms, 1).'</label></td>';
  617. print '<td colspan="3" class="maxwidthonsmartphone">';
  618. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
  619. print '</td></tr>';
  620. }
  621. // Document model
  622. include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php';
  623. $liste = ModelePdfExpedition::liste_modeles($db);
  624. if (count($liste) > 1)
  625. {
  626. print "<tr><td>".$langs->trans("Model")."</td>";
  627. print '<td colspan="3">';
  628. print $form->selectarray('model', $liste, $conf->global->EXPEDITION_ADDON_PDF);
  629. print "</td></tr>\n";
  630. }
  631. print "</table>";
  632. dol_fiche_end();
  633. // Shipment lines
  634. $numAsked = count($object->lines);
  635. print '<script type="text/javascript" language="javascript">
  636. jQuery(document).ready(function() {
  637. jQuery("#autofill").click(function() {';
  638. $i=0;
  639. while($i < $numAsked)
  640. {
  641. print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
  642. $i++;
  643. }
  644. print '});
  645. jQuery("#autoreset").click(function() {';
  646. $i=0;
  647. while($i < $numAsked)
  648. {
  649. print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
  650. $i++;
  651. }
  652. print '});
  653. });
  654. </script>';
  655. print '<br>';
  656. print '<table class="noborder" width="100%">';
  657. // Lecture des expeditions deja effectuees
  658. $object->loadExpeditions();
  659. if ($numAsked)
  660. {
  661. print '<tr class="liste_titre">';
  662. print '<td>'.$langs->trans("Description").'</td>';
  663. print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
  664. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  665. print '<td align="center">'.$langs->trans("QtyToShip");
  666. if (empty($conf->productbatch->enabled))
  667. {
  668. print ' <br>(<a href="#" id="autofill">'.$langs->trans("Fill").'</a>';
  669. print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';
  670. }
  671. print '</td>';
  672. if (! empty($conf->stock->enabled))
  673. {
  674. if (empty($conf->productbatch->enabled))
  675. {
  676. print '<td align="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
  677. }
  678. else
  679. {
  680. print '<td align="left">'.$langs->trans("Warehouse").' / '.$langs->trans("Batch").' ('.$langs->trans("Stock").')</td>';
  681. }
  682. }
  683. print "</tr>\n";
  684. }
  685. $var=true;
  686. $indiceAsked = 0;
  687. while ($indiceAsked < $numAsked)
  688. {
  689. $product = new Product($db);
  690. $line = $object->lines[$indiceAsked];
  691. $var=!$var;
  692. // Show product and description
  693. $type=$line->product_type?$line->product_type:$line->fk_product_type;
  694. // Try to enhance type detection using date_start and date_end for free lines where type
  695. // was not saved.
  696. if (! empty($line->date_start)) $type=1;
  697. if (! empty($line->date_end)) $type=1;
  698. print "<tr ".$bc[$var].">\n";
  699. // Product label
  700. if ($line->fk_product > 0) // If predefined product
  701. {
  702. $product->fetch($line->fk_product);
  703. $product->load_stock();
  704. print '<td>';
  705. print '<a name="'.$line->rowid.'"></a>'; // ancre pour retourner sur la ligne
  706. // Show product and description
  707. $product_static->type=$line->fk_product_type;
  708. $product_static->id=$line->fk_product;
  709. $product_static->ref=$line->ref;
  710. $text=$product_static->getNomUrl(1);
  711. $text.= ' - '.(! empty($line->label)?$line->label:$line->product_label);
  712. $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->desc));
  713. print $form->textwithtooltip($text,$description,3,'','',$i);
  714. // Show range
  715. print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
  716. // Add description in form
  717. if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
  718. {
  719. print ($line->desc && $line->desc!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->desc):'';
  720. }
  721. print '</td>';
  722. }
  723. else
  724. {
  725. print "<td>";
  726. if ($type==1) $text = img_object($langs->trans('Service'),'service');
  727. else $text = img_object($langs->trans('Product'),'product');
  728. if (! empty($line->label)) {
  729. $text.= ' <strong>'.$line->label.'</strong>';
  730. print $form->textwithtooltip($text,$line->desc,3,'','',$i);
  731. } else {
  732. print $text.' '.nl2br($line->desc);
  733. }
  734. // Show range
  735. print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
  736. print "</td>\n";
  737. }
  738. // Qty
  739. print '<td align="center">'.$line->qty;
  740. print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
  741. print '</td>';
  742. $qtyProdCom=$line->qty;
  743. // Qty already shipped
  744. print '<td align="center">';
  745. $quantityDelivered = $object->expeditions[$line->id];
  746. print $quantityDelivered;
  747. print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
  748. print '</td>';
  749. $quantityAsked = $line->qty;
  750. if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES))
  751. {
  752. $quantityToBeDelivered = 0;
  753. }
  754. else
  755. {
  756. $quantityToBeDelivered = $quantityAsked - $quantityDelivered;
  757. }
  758. $warehouse_id = GETPOST('entrepot_id','int');
  759. $warehouseObject = null;
  760. if ($warehouse_id > 0 || ! ($line->fk_product > 0) || empty($conf->stock->enabled)) // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
  761. {
  762. print '<!-- Case warehouse already known or product not a predefined product -->';
  763. //ship from preselected location
  764. $stock = + $product->stock_warehouse[$warehouse_id]->real; // Convert to number
  765. $deliverableQty=min($quantityToBeDelivered, $stock);
  766. if ($deliverableQty < 0) $deliverableQty = 0;
  767. if (empty($conf->productbatch->enabled) || ! ($product->hasbatch() && is_object($product->stock_warehouse[$warehouse_id])))
  768. {
  769. // Quantity to send
  770. print '<td align="center">';
  771. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  772. {
  773. if (GETPOST('qtyl'.$indiceAsked)) $defaultqty=GETPOST('qtyl'.$indiceAsked);
  774. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  775. print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
  776. }
  777. else print $langs->trans("NA");
  778. print '</td>';
  779. // Stock
  780. if (! empty($conf->stock->enabled))
  781. {
  782. print '<td align="left">';
  783. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) // Type of product need stock change ?
  784. {
  785. // Show warehouse combo list
  786. $ent = "entl".$indiceAsked;
  787. $idl = "idl".$indiceAsked;
  788. $tmpentrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):$warehouse_id;
  789. if ($line->fk_product > 0)
  790. {
  791. print '<!-- Show warehouse selection -->';
  792. print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1);
  793. if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id)
  794. {
  795. //print $stock.' '.$quantityToBeDelivered;
  796. if ($stock < $quantityToBeDelivered)
  797. {
  798. print ' '.img_warning($langs->trans("StockTooLow")); // Stock too low for this $warehouse_id but you can change warehouse
  799. }
  800. }
  801. }
  802. }
  803. else
  804. {
  805. print $langs->trans("Service");
  806. }
  807. print '</td>';
  808. }
  809. print "</tr>\n";
  810. // Show subproducts of product
  811. if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)
  812. {
  813. $product->get_sousproduits_arbo();
  814. $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
  815. if(count($prods_arbo) > 0)
  816. {
  817. foreach($prods_arbo as $key => $value)
  818. {
  819. //print $value[0];
  820. $img='';
  821. if ($value['stock'] < $value['stock_alert'])
  822. {
  823. $img=img_warning($langs->trans("StockTooLow"));
  824. }
  825. print "<tr ".$bc[$var]."><td>&nbsp; &nbsp; &nbsp; ->
  826. <a href=\"".DOL_URL_ROOT."/product/card.php?id=".$value['id']."\">".$value['fullpath']."
  827. </a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
  828. <td align=\"center\">".$value['stock']." ".$img."</td></tr>";
  829. }
  830. }
  831. }
  832. }
  833. else
  834. {
  835. print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial
  836. $staticwarehouse=new Entrepot($db);
  837. if ($warehouse_id > 0) $staticwarehouse->fetch($warehouse_id);
  838. $subj=0;
  839. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  840. if (count($product->stock_warehouse[$warehouse_id]->detail_batch))
  841. {
  842. foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch)
  843. {
  844. //var_dump($dbatch);
  845. $batchStock = + $dbatch->qty; // To get a numeric
  846. $deliverableQty = min($quantityToBeDelivered,$batchStock);
  847. print '<tr><td colspan="3" ></td><td align="center">';
  848. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';
  849. print '</td>';
  850. print '<td align="left">';
  851. print $staticwarehouse->getNomUrl(0).' / ';
  852. print '<!-- Show details of lot -->';
  853. print '<input name="batchl'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$dbatch->id.'">';
  854. print $langs->trans("DetailBatchFormat", $dbatch->batch, dol_print_date($dbatch->eatby,"day"), dol_print_date($dbatch->sellby,"day"), $dbatch->qty);
  855. $quantityToBeDelivered -= $deliverableQty;
  856. if ($quantityToBeDelivered < 0)
  857. {
  858. $quantityToBeDelivered = 0;
  859. }
  860. $subj++;
  861. print '</td></tr>';
  862. }
  863. }
  864. else
  865. {
  866. print '<!-- Case -->';
  867. print '<tr><td colspan="3"></td><td align="center">';
  868. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0" disabled="disabled"> ';
  869. print '</td>';
  870. print '<td align="left">';
  871. print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $staticwarehouse->libelle);
  872. print '</td></tr>';
  873. }
  874. }
  875. }
  876. else
  877. {
  878. // ship from multiple locations
  879. if (empty($conf->productbatch->enabled) || ! $product->hasbatch())
  880. {
  881. print '<td></td><td></td></tr>'; // end line and start a new one for each warehouse
  882. print '<!-- Case warehouse not already known and product does not need lot -->';
  883. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  884. $subj=0;
  885. foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse) // $stock_warehouse is product_stock
  886. {
  887. $warehouseObject=new Entrepot($db);
  888. $warehouseObject->fetch($warehouse_id);
  889. if ($stock_warehouse->real > 0)
  890. {
  891. $stock = + $stock_warehouse->real; // Convert it to number
  892. $deliverableQty = min($quantityToBeDelivered,$stock);
  893. $deliverableQty = max(0, $deliverableQty);
  894. // Quantity to send
  895. print '<tr><td colspan="3" ></td><td align="center"><!-- qty to ship (no lot management for product line indiceAsked='.$indiceAsked.') -->';
  896. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  897. {
  898. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
  899. print '<input name="ent1'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$warehouse_id.'">';
  900. }
  901. else print $langs->trans("NA");
  902. print '</td>';
  903. // Stock
  904. if (! empty($conf->stock->enabled))
  905. {
  906. print '<td align="left">';
  907. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  908. {
  909. print $warehouseObject->getNomUrl(0).' ';
  910. print '<!-- Show details of stock -->';
  911. print '('.$stock.')';
  912. }
  913. else
  914. {
  915. print $langs->trans("Service");
  916. }
  917. print '</td>';
  918. }
  919. $quantityToBeDelivered -= $deliverableQty;
  920. if ($quantityToBeDelivered < 0)
  921. {
  922. $quantityToBeDelivered = 0;
  923. }
  924. $subj++;
  925. print "</tr>\n";
  926. }
  927. }
  928. // Show subproducts of product (not recommanded)
  929. if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)
  930. {
  931. $product->get_sousproduits_arbo();
  932. $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
  933. if (count($prods_arbo) > 0)
  934. {
  935. foreach($prods_arbo as $key => $value)
  936. {
  937. //print $value[0];
  938. $img='';
  939. if ($value['stock'] < $value['stock_alert'])
  940. {
  941. $img=img_warning($langs->trans("StockTooLow"));
  942. }
  943. print "<tr ".$bc[$var]."><td>";
  944. print "&nbsp; &nbsp; &nbsp; ->
  945. <a href=\"".DOL_URL_ROOT."/product/card.php?id=".$value['id']."\">".$value['fullpath']."
  946. </a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
  947. <td align=\"center\">".$value['stock']." ".$img."</td>";
  948. print "</tr>";
  949. }
  950. }
  951. }
  952. }
  953. else
  954. {
  955. print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial
  956. $subj=0;
  957. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  958. foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)
  959. {
  960. $warehouseObject=new Entrepot($db);
  961. $warehouseObject->fetch($warehouse_id);
  962. if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) {
  963. foreach ($stock_warehouse->detail_batch as $dbatch)
  964. {
  965. //var_dump($dbatch);
  966. $batchStock = + $dbatch->qty; // To get a numeric
  967. $deliverableQty = min($quantityToBeDelivered,$batchStock);
  968. print '<tr><td colspan="3"></td><td align="center">';
  969. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';
  970. print '</td>';
  971. print '<td align="left">';
  972. print $warehouseObject->getNomUrl(0).' / ';
  973. print '<!-- Show details of lot -->';
  974. print '<input name="batchl'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$dbatch->id.'">';
  975. print $langs->trans("DetailBatchFormat", $dbatch->batch, dol_print_date($dbatch->eatby,"day"), dol_print_date($dbatch->sellby,"day"), $dbatch->qty);
  976. $quantityToBeDelivered -= $deliverableQty;
  977. if ($quantityToBeDelivered < 0)
  978. {
  979. $quantityToBeDelivered = 0;
  980. }
  981. //dol_syslog('deliverableQty = '.$deliverableQty.' batchStock = '.$batchStock);
  982. $subj++;
  983. print '</td></tr>';
  984. }
  985. }
  986. }
  987. }
  988. if ($subj == 0) // Line not shown yet, we show it
  989. {
  990. print '<!-- line not shown yet, we show it -->';
  991. print '<tr><td colspan="3" ></td><td align="center">';
  992. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  993. {
  994. //$disabled='disabled="disabled"';
  995. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0"'.($disabled?' '.$disabled:'').'> ';
  996. }
  997. else
  998. {
  999. print $langs->trans("NA");
  1000. }
  1001. print '</td>';
  1002. print '<td align="left">';
  1003. if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  1004. {
  1005. if ($warehouseObject)
  1006. {
  1007. print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $warehouseObject->libelle);
  1008. }
  1009. else
  1010. {
  1011. if ($line->fk_product) print img_warning().' '.$langs->trans("StockTooLow");
  1012. else print '';
  1013. }
  1014. }
  1015. else
  1016. {
  1017. print $langs->trans("Service");
  1018. }
  1019. print '</td>';
  1020. print '</tr>';
  1021. }
  1022. }
  1023. //Display lines extrafields
  1024. if (is_array($extralabelslines) && count($extralabelslines)>0)
  1025. {
  1026. $colspan=5;
  1027. $line = new ExpeditionLigne($db);
  1028. $line->fetch_optionals($object->id,$extralabelslines);
  1029. print '<tr '.$bc[$var].'>';
  1030. print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
  1031. print '</tr>';
  1032. }
  1033. $indiceAsked++;
  1034. }
  1035. print "</table>";
  1036. print '<br><div class="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></div>';
  1037. print '</form>';
  1038. print '<br>';
  1039. }
  1040. else
  1041. {
  1042. dol_print_error($db);
  1043. }
  1044. }
  1045. }
  1046. else if ($id || $ref)
  1047. /* *************************************************************************** */
  1048. /* */
  1049. /* Edit and view mode */
  1050. /* */
  1051. /* *************************************************************************** */
  1052. {
  1053. $lines = $object->lines;
  1054. $num_prod = count($lines);
  1055. if ($object->id > 0)
  1056. {
  1057. if (!empty($object->origin))
  1058. {
  1059. $typeobject = $object->origin;
  1060. $origin = $object->origin;
  1061. $object->fetch_origin();
  1062. }
  1063. $soc = new Societe($db);
  1064. $soc->fetch($object->socid);
  1065. $res = $object->fetch_optionals($object->id, $extralabels);
  1066. $head=shipping_prepare_head($object);
  1067. dol_fiche_head($head, 'shipping', $langs->trans("Shipment"), 0, 'sending');
  1068. /*
  1069. * Confirmation de la suppression
  1070. */
  1071. if ($action == 'delete')
  1072. {
  1073. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$object->ref),'confirm_delete','',0,1);
  1074. }
  1075. /*
  1076. * Confirmation de la validation
  1077. */
  1078. if ($action == 'valid')
  1079. {
  1080. $objectref = substr($object->ref, 1, 4);
  1081. if ($objectref == 'PROV')
  1082. {
  1083. $numref = $object->getNextNumRef($soc);
  1084. }
  1085. else
  1086. {
  1087. $numref = $object->ref;
  1088. }
  1089. $text = $langs->trans("ConfirmValidateSending",$numref);
  1090. if (! empty($conf->notification->enabled))
  1091. {
  1092. require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
  1093. $notify=new Notify($db);
  1094. $text.='<br>';
  1095. $text.=$notify->confirmMessage('SHIPPING_VALIDATE',$object->socid, $object);
  1096. }
  1097. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$text,'confirm_valid','',0,1);
  1098. }
  1099. /*
  1100. * Confirmation de l'annulation
  1101. */
  1102. if ($action == 'annuler')
  1103. {
  1104. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$object->ref),'confirm_cancel','',0,1);
  1105. }
  1106. // Calculate totalWeight and totalVolume for all products
  1107. // by adding weight and volume of each product line.
  1108. $tmparray=$object->getTotalWeightVolume();
  1109. $totalWeight=$tmparray['weight'];
  1110. $totalVolume=$tmparray['volume'];
  1111. print '<table class="border" width="100%">';
  1112. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php">'.$langs->trans("BackToList").'</a>';
  1113. // Ref
  1114. print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
  1115. print '<td colspan="3">';
  1116. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  1117. print '</td></tr>';
  1118. // Customer
  1119. print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
  1120. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  1121. print "</tr>";
  1122. // Linked documents
  1123. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  1124. {
  1125. print '<tr><td>';
  1126. $objectsrc=new Commande($db);
  1127. $objectsrc->fetch($object->$typeobject->id);
  1128. print $langs->trans("RefOrder").'</td>';
  1129. print '<td colspan="3">';
  1130. print $objectsrc->getNomUrl(1,'commande');
  1131. print "</td>\n";
  1132. print '</tr>';
  1133. }
  1134. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  1135. {
  1136. print '<tr><td>';
  1137. $objectsrc=new Propal($db);
  1138. $objectsrc->fetch($object->$typeobject->id);
  1139. print $langs->trans("RefProposal").'</td>';
  1140. print '<td colspan="3">';
  1141. print $objectsrc->getNomUrl(1,'expedition');
  1142. print "</td>\n";
  1143. print '</tr>';
  1144. }
  1145. // Ref customer
  1146. print '<tr><td>'.$langs->trans("RefCustomer").'</td>';
  1147. print '<td colspan="3">'.$object->ref_customer."</a></td>\n";
  1148. print '</tr>';
  1149. // Date creation
  1150. print '<tr><td>'.$langs->trans("DateCreation").'</td>';
  1151. print '<td colspan="3">'.dol_print_date($object->date_creation,"day")."</td>\n";
  1152. print '</tr>';
  1153. // Delivery date planned
  1154. print '<tr><td height="10">';
  1155. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1156. print $langs->trans('DateDeliveryPlanned');
  1157. print '</td>';
  1158. 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>';
  1159. print '</tr></table>';
  1160. print '</td><td colspan="2">';
  1161. if ($action == 'editdate_livraison')
  1162. {
  1163. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1164. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1165. print '<input type="hidden" name="action" value="setdate_livraison">';
  1166. print $form->select_date($object->date_delivery?$object->date_delivery:-1,'liv_',1,1,'',"setdate_livraison",1,0,1);
  1167. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1168. print '</form>';
  1169. }
  1170. else
  1171. {
  1172. print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhour') : '&nbsp;';
  1173. }
  1174. print '</td>';
  1175. print '</tr>';
  1176. // Weight
  1177. print '<tr><td>';
  1178. print $form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer);
  1179. print '</td><td colspan="3">';
  1180. if ($action=='edittrueWeight')
  1181. {
  1182. print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1183. print '<input name="action" value="settrueWeight" type="hidden">';
  1184. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1185. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1186. print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
  1187. print $formproduct->select_measuring_units("weight_units","weight",$object->weight_units);
  1188. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1189. print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1190. print '</form>';
  1191. }
  1192. else
  1193. {
  1194. print $object->trueWeight;
  1195. print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):'';
  1196. }
  1197. // Calculated
  1198. if ($totalWeight > 0)
  1199. {
  1200. if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
  1201. //print $totalWeight.' '.measuring_units_string(0,"weight");
  1202. print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no');
  1203. //if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')';
  1204. if (!empty($object->trueWeight)) print ')';
  1205. }
  1206. print '</td></tr>';
  1207. // Width
  1208. print '<tr><td>'.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1209. print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer);
  1210. print ($object->trueWidth && $object->width_units!='')?' '.measuring_units_string($object->width_units,"size"):'';
  1211. print '</td></tr>';
  1212. // Height
  1213. print '<tr><td>'.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1214. if($action=='edittrueHeight')
  1215. {
  1216. print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1217. print '<input name="action" value="settrueHeight" type="hidden">';
  1218. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1219. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1220. print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
  1221. print $formproduct->select_measuring_units("size_units","size",$object->size_units);
  1222. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1223. print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1224. print '</form>';
  1225. }
  1226. else
  1227. {
  1228. print $object->trueHeight;
  1229. print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):'';
  1230. }
  1231. print '</td></tr>';
  1232. // Depth
  1233. print '<tr><td>'.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1234. print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer);
  1235. print ($object->trueDepth && $object->depth_units!='')?' '.measuring_units_string($object->depth_units,"size"):'';
  1236. print '</td></tr>';
  1237. // Volume
  1238. print '<tr><td>';
  1239. print $langs->trans("Volume");
  1240. print '</td>';
  1241. print '<td colspan="3">';
  1242. $calculatedVolume=0;
  1243. $volumeUnit=0;
  1244. if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
  1245. {
  1246. $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
  1247. $volumeUnit=$object->size_units * 3;
  1248. }
  1249. // If sending volume not defined we use sum of products
  1250. if ($calculatedVolume > 0)
  1251. {
  1252. if ($volumeUnit < 50)
  1253. {
  1254. //print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
  1255. print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
  1256. }
  1257. else print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
  1258. }
  1259. if ($totalVolume > 0)
  1260. {
  1261. if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
  1262. //print $totalVolume.' '.measuring_units_string(0,"volume");
  1263. print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no');
  1264. //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
  1265. if ($calculatedVolume) print ')';
  1266. }
  1267. print "</td>\n";
  1268. print '</tr>';
  1269. // Status
  1270. print '<tr><td>'.$langs->trans("Status").'</td>';
  1271. print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
  1272. print '</tr>';
  1273. // Sending method
  1274. print '<tr><td height="10">';
  1275. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1276. print $langs->trans('SendingMethod');
  1277. print '</td>';
  1278. 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>';
  1279. print '</tr></table>';
  1280. print '</td><td colspan="2">';
  1281. if ($action == 'editshipping_method_id')
  1282. {
  1283. print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1284. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1285. print '<input type="hidden" name="action" value="setshipping_method_id">';
  1286. $object->fetch_delivery_methods();
  1287. print $form->selectarray("shipping_method_id",$object->meths,$object->shipping_method_id,1,0,0,"",1);
  1288. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  1289. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1290. print '</form>';
  1291. }
  1292. else
  1293. {
  1294. if ($object->shipping_method_id > 0)
  1295. {
  1296. // Get code using getLabelFromKey
  1297. $code=$langs->getLabelFromKey($db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
  1298. print $langs->trans("SendingMethod".strtoupper($code));
  1299. }
  1300. }
  1301. print '</td>';
  1302. print '</tr>';
  1303. // Tracking Number
  1304. print '<tr><td>'.$form->editfieldkey("TrackingNumber",'trackingnumber',$object->tracking_number,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1305. print $form->editfieldval("TrackingNumber",'trackingnumber',$object->tracking_url,$object,$user->rights->expedition->creer,'string',$object->tracking_number);
  1306. print '</td></tr>';
  1307. // Incoterms
  1308. if (!empty($conf->incoterm->enabled))
  1309. {
  1310. print '<tr><td>';
  1311. print '<table width="100%" class="nobordernopadding"><tr><td>';
  1312. print $langs->trans('IncotermLabel');
  1313. print '<td><td align="right">';
  1314. if ($user->rights->expedition->creer) print '<a href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
  1315. else print '&nbsp;';
  1316. print '</td></tr></table>';
  1317. print '</td>';
  1318. print '<td colspan="3">';
  1319. if ($action != 'editincoterm')
  1320. {
  1321. print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
  1322. }
  1323. else
  1324. {
  1325. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id);
  1326. }
  1327. print '</td></tr>';
  1328. }
  1329. // Other attributes
  1330. $cols = 3;
  1331. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  1332. print "</table>\n";
  1333. /*
  1334. * Lines of products
  1335. */
  1336. print '<br><table class="noborder" width="100%">';
  1337. print '<tr class="liste_titre">';
  1338. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1339. {
  1340. print '<td width="5" align="center">&nbsp;</td>';
  1341. }
  1342. print '<td>'.$langs->trans("Products").'</td>';
  1343. print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
  1344. if ($object->statut <= 1)
  1345. {
  1346. print '<td align="center">'.$langs->trans("QtyToShip").'</td>';
  1347. }
  1348. else
  1349. {
  1350. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  1351. }
  1352. print '<td align="center">'.$langs->trans("CalculatedWeight").'</td>';
  1353. print '<td align="center">'.$langs->trans("CalculatedVolume").'</td>';
  1354. //print '<td align="center">'.$langs->trans("Size").'</td>';
  1355. if (! empty($conf->stock->enabled))
  1356. {
  1357. print '<td align="left">'.$langs->trans("WarehouseSource").'</td>';
  1358. }
  1359. if (! empty($conf->productbatch->enabled))
  1360. {
  1361. print '<td align="left">'.$langs->trans("Batch").'</td>';
  1362. }
  1363. print "</tr>\n";
  1364. $var=false;
  1365. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1366. {
  1367. $object->fetch_thirdparty();
  1368. $outputlangs = $langs;
  1369. $newlang='';
  1370. if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id','alpha');
  1371. if (empty($newlang)) $newlang=$object->thirdparty->default_lang;
  1372. if (! empty($newlang))
  1373. {
  1374. $outputlangs = new Translate("",$conf);
  1375. $outputlangs->setDefaultLang($newlang);
  1376. }
  1377. }
  1378. for ($i = 0 ; $i < $num_prod ; $i++)
  1379. {
  1380. print "<tr ".$bc[$var].">";
  1381. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1382. {
  1383. print '<td align="center">'.($i+1).'</td>';
  1384. }
  1385. // Predefined product or service
  1386. if ($lines[$i]->fk_product > 0)
  1387. {
  1388. // Define output language
  1389. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1390. {
  1391. $prod = new Product($db);
  1392. $prod->fetch($lines[$i]->fk_product);
  1393. $label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;
  1394. }
  1395. else
  1396. $label = (! empty($lines[$i]->label)?$lines[$i]->label:$lines[$i]->product_label);
  1397. print '<td>';
  1398. // Show product and description
  1399. $product_static->type=$lines[$i]->fk_product_type;
  1400. $product_static->id=$lines[$i]->fk_product;
  1401. $product_static->ref=$lines[$i]->ref;
  1402. $text=$product_static->getNomUrl(1);
  1403. $text.= ' - '.$label;
  1404. $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($lines[$i]->description));
  1405. print $form->textwithtooltip($text,$description,3,'','',$i);
  1406. print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
  1407. if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
  1408. {
  1409. print (! empty($lines[$i]->description) && $lines[$i]->description!=$lines[$i]->product)?'<br>'.dol_htmlentitiesbr($lines[$i]->description):'';
  1410. }
  1411. print "</td>\n";
  1412. }
  1413. else
  1414. {
  1415. print "<td>";
  1416. if ($lines[$i]->fk_product_type==1) $text = img_object($langs->trans('Service'),'service');
  1417. else $text = img_object($langs->trans('Product'),'product');
  1418. if (! empty($lines[$i]->label)) {
  1419. $text.= ' <strong>'.$lines[$i]->label.'</strong>';
  1420. print $form->textwithtooltip($text,$lines[$i]->description,3,'','',$i);
  1421. } else {
  1422. print $text.' '.nl2br($lines[$i]->description);
  1423. }
  1424. print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
  1425. print "</td>\n";
  1426. }
  1427. // Qte commande
  1428. print '<td align="center">'.$lines[$i]->qty_asked.'</td>';
  1429. // Qte a expedier ou expedier
  1430. print '<td align="center">'.$lines[$i]->qty_shipped.'</td>';
  1431. // Weight
  1432. print '<td align="center">';
  1433. if ($lines[$i]->fk_product_type == 0) print $lines[$i]->weight*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->weight_units,"weight");
  1434. else print '&nbsp;';
  1435. print '</td>';
  1436. // Volume
  1437. print '<td align="center">';
  1438. if ($lines[$i]->fk_product_type == 0) print $lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume");
  1439. else print '&nbsp;';
  1440. print '</td>';
  1441. // Size
  1442. //print '<td align="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume").'</td>';
  1443. // Entrepot source
  1444. if (! empty($conf->stock->enabled))
  1445. {
  1446. print '<td align="left">';
  1447. if ($lines[$i]->entrepot_id > 0)
  1448. {
  1449. $entrepot = new Entrepot($db);
  1450. $entrepot->fetch($lines[$i]->entrepot_id);
  1451. print $entrepot->getNomUrl(1);
  1452. }
  1453. else if (count($lines[$i]->details_entrepot) > 1)
  1454. {
  1455. $detail = '';
  1456. foreach ($lines[$i]->details_entrepot as $detail_entrepot)
  1457. {
  1458. if ($detail_entrepot->entrepot_id > 0)
  1459. {
  1460. $entrepot = new Entrepot($db);
  1461. $entrepot->fetch($detail_entrepot->entrepot_id);
  1462. $detail.= $langs->trans("DetailWarehouseFormat",$entrepot->libelle,$detail_entrepot->qty_shipped).'<br/>';
  1463. }
  1464. }
  1465. print $form->textwithtooltip(img_picto('', 'object_stock').' '.$langs->trans("DetailWarehouseNumber"),$detail);
  1466. }
  1467. print '</td>';
  1468. }
  1469. // Batch number managment
  1470. if (! empty($conf->productbatch->enabled))
  1471. {
  1472. if (isset($lines[$i]->detail_batch))
  1473. {
  1474. print '<td>';
  1475. if ($lines[$i]->product_tobatch)
  1476. {
  1477. $detail = '';
  1478. foreach ($lines[$i]->detail_batch as $dbatch)
  1479. {
  1480. $detail.= $langs->trans("DetailBatchFormat",$dbatch->batch,dol_print_date($dbatch->eatby,"day"),dol_print_date($dbatch->sellby,"day"),$dbatch->dluo_qty).'<br/>';
  1481. }
  1482. print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
  1483. }
  1484. else
  1485. {
  1486. print $langs->trans("NA");
  1487. }
  1488. print '</td>';
  1489. } else {
  1490. print '<td></td>';
  1491. }
  1492. }
  1493. print "</tr>";
  1494. //Display lines extrafields
  1495. if (is_array($extralabelslines) && count($extralabelslines)>0) {
  1496. $colspan= empty($conf->productbatch->enabled) ? 5 : 6;
  1497. $line = new ExpeditionLigne($db);
  1498. $line->fetch_optionals($lines[$i]->id,$extralabelslines);
  1499. print '<tr '.$bc[$var].'>';
  1500. print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
  1501. print '</tr>';
  1502. }
  1503. $var=!$var;
  1504. }
  1505. }
  1506. print "</table>\n";
  1507. print "\n</div>\n";
  1508. $object->fetchObjectLinked($object->id,$object->element);
  1509. /*
  1510. * Boutons actions
  1511. */
  1512. if (($user->societe_id == 0) && ($action!='presend'))
  1513. {
  1514. print '<div class="tabsAction">';
  1515. $parameters = array();
  1516. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1517. // modified by hook
  1518. if (empty($reshook))
  1519. {
  1520. if ($object->statut == 0 && $num_prod > 0)
  1521. {
  1522. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer))
  1523. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate)))
  1524. {
  1525. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
  1526. }
  1527. else
  1528. {
  1529. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
  1530. }
  1531. }
  1532. // TODO add alternative status
  1533. // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
  1534. if ($object->statut == 2 && $object->billed && $user->rights->expedition->creer)
  1535. {
  1536. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
  1537. }
  1538. // Send
  1539. if ($object->statut > 0)
  1540. {
  1541. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send)
  1542. {
  1543. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
  1544. }
  1545. else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
  1546. }
  1547. // Create bill and Close shipment
  1548. if (! empty($conf->facture->enabled) && $object->statut > 0)
  1549. {
  1550. if ($user->rights->facture->creer)
  1551. {
  1552. 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>';
  1553. }
  1554. }
  1555. // This is just to generate a delivery receipt
  1556. //var_dump($object->linkedObjectsIds['delivery']);
  1557. if ($conf->livraison_bon->enabled && ($object->statut == 1 || $object->statut == 2) && $user->rights->expedition->livraison->creer && count($object->linkedObjectsIds['delivery']) == 0)
  1558. {
  1559. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=create_delivery">'.$langs->trans("CreateDeliveryOrder").'</a>';
  1560. }
  1561. // Close
  1562. if (! empty($conf->facture->enabled) && $object->statut > 0)
  1563. {
  1564. if ($user->rights->expedition->creer && $object->statut > 0 && ! $object->billed)
  1565. {
  1566. $label="Close"; $paramaction='classifyclosed'; // = Transferred/Received
  1567. // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders
  1568. if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) // TODO Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close.
  1569. {
  1570. $label="ClassifyBilled";
  1571. $paramaction='classifybilled';
  1572. }
  1573. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$paramaction.'">'.$langs->trans($label).'</a>';
  1574. }
  1575. }
  1576. if ($user->rights->expedition->supprimer)
  1577. {
  1578. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
  1579. }
  1580. }
  1581. print '</div>';
  1582. }
  1583. /*
  1584. * Documents generated
  1585. */
  1586. if ($action != 'presend')
  1587. {
  1588. print '<div class="fichecenter"><div class="fichehalfleft">';
  1589. $objectref = dol_sanitizeFileName($object->ref);
  1590. $filedir = $conf->expedition->dir_output . "/sending/" .$objectref;
  1591. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1592. $genallowed=$user->rights->expedition->lire;
  1593. $delallowed=$user->rights->expedition->supprimer;
  1594. $somethingshown=$formfile->show_documents('expedition',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
  1595. // Linked object block
  1596. $somethingshown = $form->showLinkedObjectBlock($object);
  1597. // Show links to link elements
  1598. //$linktoelem = $form->showLinkToObjectBlock($object);
  1599. //if ($linktoelem) print '<br>'.$linktoelem;
  1600. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  1601. // List of actions on element
  1602. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1603. $formactions=new FormActions($db);
  1604. $somethingshown=$formactions->showactions($object,'shipping',$socid);
  1605. print '</div></div></div>';
  1606. }
  1607. /*
  1608. * Action presend
  1609. */
  1610. //Select mail models is same action as presend
  1611. if (GETPOST('modelselected')) {
  1612. $action = 'presend';
  1613. }
  1614. if ($action == 'presend')
  1615. {
  1616. $ref = dol_sanitizeFileName($object->ref);
  1617. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  1618. $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/').'[^\-]+');
  1619. $file=$fileparams['fullname'];
  1620. // Define output language
  1621. $outputlangs = $langs;
  1622. $newlang = '';
  1623. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
  1624. $newlang = $_REQUEST['lang_id'];
  1625. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  1626. $newlang = $object->thirdparty->default_lang;
  1627. if (!empty($newlang))
  1628. {
  1629. $outputlangs = new Translate('', $conf);
  1630. $outputlangs->setDefaultLang($newlang);
  1631. $outputlangs->load('sendings');
  1632. }
  1633. // Build document if it not exists
  1634. if (! $file || ! is_readable($file))
  1635. {
  1636. $result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1637. if ($result <= 0)
  1638. {
  1639. dol_print_error($db,$object->error,$object->errors);
  1640. exit;
  1641. }
  1642. $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/').'[^\-]+');
  1643. $file=$fileparams['fullname'];
  1644. }
  1645. print '<div class="clearboth"></div>';
  1646. print '<br>';
  1647. print load_fiche_titre($langs->trans('SendShippingByEMail'));
  1648. dol_fiche_head('');
  1649. // Cree l'objet formulaire mail
  1650. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  1651. $formmail = new FormMail($db);
  1652. $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
  1653. $formmail->fromtype = 'user';
  1654. $formmail->fromid = $user->id;
  1655. $formmail->fromname = $user->getFullName($langs);
  1656. $formmail->frommail = $user->email;
  1657. $formmail->trackid='shi'.$object->id;
  1658. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
  1659. {
  1660. include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1661. $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'shi'.$object->id);
  1662. }
  1663. $formmail->withfrom=1;
  1664. $liste=array();
  1665. foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
  1666. $formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
  1667. $formmail->withtocc=$liste;
  1668. $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
  1669. $formmail->withtopic=$outputlangs->trans('SendShippingRef','__SHIPPINGREF__');
  1670. $formmail->withfile=2;
  1671. $formmail->withbody=1;
  1672. $formmail->withdeliveryreceipt=1;
  1673. $formmail->withcancel=1;
  1674. // Tableau des substitutions
  1675. $formmail->setSubstitFromObject($object);
  1676. $formmail->substit['__SHIPPINGREF__']=$object->ref;
  1677. $formmail->substit['__SHIPPINGTRACKNUM__']=$object->tracking_number;
  1678. $formmail->substit['__SHIPPINGTRACKNUMURL__']=$object->tracking_url;
  1679. //Find the good contact adress
  1680. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled)) {
  1681. $objectsrc=new Commande($db);
  1682. $objectsrc->fetch($object->$typeobject->id);
  1683. }
  1684. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled)) {
  1685. $objectsrc=new Propal($db);
  1686. $objectsrc->fetch($object->$typeobject->id);
  1687. }
  1688. $custcontact='';
  1689. $contactarr=array();
  1690. if (is_object($objectsrc)) // For the case the shipment was created without orders
  1691. {
  1692. $contactarr=$objectsrc->liste_contact(-1,'external');
  1693. }
  1694. if (is_array($contactarr) && count($contactarr)>0) {
  1695. foreach($contactarr as $contact) {
  1696. if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) {
  1697. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  1698. $contactstatic=new Contact($db);
  1699. $contactstatic->fetch($contact['id']);
  1700. $custcontact=$contactstatic->getFullName($langs,1);
  1701. }
  1702. }
  1703. if (!empty($custcontact)) {
  1704. $formmail->substit['__CONTACTCIVNAME__']=$custcontact;
  1705. }
  1706. }
  1707. // Tableau des parametres complementaires
  1708. $formmail->param['action']='send';
  1709. $formmail->param['models']='shipping_send';
  1710. $formmail->param['models_id']=GETPOST('modelmailselected','int');
  1711. $formmail->param['shippingid']=$object->id;
  1712. $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  1713. // Init list of files
  1714. if (GETPOST("mode")=='init')
  1715. {
  1716. $formmail->clear_attached_files();
  1717. $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
  1718. }
  1719. // Show form
  1720. print $formmail->get_form();
  1721. dol_fiche_end();
  1722. }
  1723. if ($action != 'presend' && ! empty($origin) && $object->$origin->id)
  1724. {
  1725. print '<br>';
  1726. //show_list_sending_receive($object->origin,$object->origin_id," AND e.rowid <> ".$object->id);
  1727. show_list_sending_receive($object->origin,$object->origin_id);
  1728. }
  1729. }
  1730. llxFooter();
  1731. $db->close();