card.php 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592
  1. <?php
  2. /* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2016 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@inodbox.com>
  6. * Copyright (C) 2011-2017 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-2017 Francis Appels <francis.appels@yahoo.com>
  11. * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
  12. * Copyright (C) 2016-2018 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2016 Yasser Carreón <yacasia@gmail.com>
  14. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/expedition/card.php
  31. * \ingroup expedition
  32. * \brief Card of a shipment
  33. */
  34. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  45. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  46. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  47. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  48. if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
  49. if (! empty($conf->projet->enabled)) {
  50. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  51. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  52. }
  53. // Load translation files required by the page
  54. $langs->loadLangs(array("sendings","companies","bills",'deliveries','orders','stocks','other','propal'));
  55. if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
  56. if (! empty($conf->productbatch->enabled)) $langs->load('productbatch');
  57. $origin = GETPOST('origin','alpha')?GETPOST('origin','alpha'):'expedition'; // Example: commande, propal
  58. $origin_id = GETPOST('id','int')?GETPOST('id','int'):'';
  59. $id = $origin_id;
  60. if (empty($origin_id)) $origin_id = GETPOST('origin_id','int'); // Id of order or propal
  61. if (empty($origin_id)) $origin_id = GETPOST('object_id','int'); // Id of order or propal
  62. $ref=GETPOST('ref','alpha');
  63. $line_id = GETPOST('lineid','int')?GETPOST('lineid','int'):'';
  64. // Security check
  65. $socid='';
  66. if ($user->societe_id) $socid=$user->societe_id;
  67. if ($origin == 'expedition') $result=restrictedArea($user, $origin, $id);
  68. else {
  69. $result=restrictedArea($user, 'expedition');
  70. if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) accessforbidden();
  71. }
  72. $action = GETPOST('action','alpha');
  73. $confirm = GETPOST('confirm','alpha');
  74. $cancel = GETPOST('cancel','alpha');
  75. //PDF
  76. $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  77. $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  78. $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  79. $object = new Expedition($db);
  80. $extrafields = new ExtraFields($db);
  81. $extrafieldsline = new ExtraFields($db);
  82. // fetch optionals attributes and labels
  83. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  84. // fetch optionals attributes lines and labels
  85. $extralabelslines=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  86. // Load object. Make an object->fetch
  87. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  88. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  89. $hookmanager->initHooks(array('expeditioncard','globalcard'));
  90. $permissiondellink=$user->rights->expedition->livraison->creer; // Used by the include of actions_dellink.inc.php
  91. //var_dump($object->lines[0]->detail_batch);
  92. /*
  93. * Actions
  94. */
  95. $parameters=array();
  96. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  97. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  98. if (empty($reshook))
  99. {
  100. if ($cancel)
  101. {
  102. $action = '';
  103. $object->fetch($id); // show shipment also after canceling modification
  104. }
  105. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  106. // Actions to build doc
  107. $upload_dir = $conf->expedition->dir_output.'/sending';
  108. $permissioncreate = $user->rights->expedition->creer;
  109. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  110. // Reopen
  111. if ($action == 'reopen' && $user->rights->expedition->creer)
  112. {
  113. $object->fetch($id);
  114. $result = $object->reOpen();
  115. }
  116. // Set incoterm
  117. if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
  118. {
  119. $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
  120. }
  121. if ($action == 'setref_customer')
  122. {
  123. $result = $object->fetch($id);
  124. if ($result < 0) {
  125. setEventMessages($object->error, $object->errors, 'errors');
  126. }
  127. $result = $object->setValueFrom('ref_customer', GETPOST('ref_customer','alpha'), '', null, 'text', '', $user, 'SHIPMENT_MODIFY');
  128. if ($result < 0) {
  129. setEventMessages($object->error, $object->errors, 'errors');
  130. $action = 'editref_customer';
  131. } else {
  132. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  133. exit;
  134. }
  135. }
  136. if ($action == 'update_extras')
  137. {
  138. $object->oldcopy = dol_clone($object);
  139. // Fill array 'array_options' with data from update form
  140. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  141. $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
  142. if ($ret < 0) $error++;
  143. if (! $error)
  144. {
  145. // Actions on extra fields
  146. $result = $object->insertExtraFields('SHIPMENT_MODIFY');
  147. if ($result < 0)
  148. {
  149. setEventMessages($object->error, $object->errors, 'errors');
  150. $error++;
  151. }
  152. }
  153. if ($error)
  154. $action = 'edit_extras';
  155. }
  156. // Create shipment
  157. if ($action == 'add' && $user->rights->expedition->creer)
  158. {
  159. $error=0;
  160. $predef='';
  161. $db->begin();
  162. $object->note = GETPOST('note','alpha');
  163. $object->origin = $origin;
  164. $object->origin_id = $origin_id;
  165. $object->fk_project = GETPOST('projectid','int');
  166. $object->weight = GETPOST('weight','int')==''?"NULL":GETPOST('weight','int');
  167. $object->sizeH = GETPOST('sizeH','int')==''?"NULL":GETPOST('sizeH','int');
  168. $object->sizeW = GETPOST('sizeW','int')==''?"NULL":GETPOST('sizeW','int');
  169. $object->sizeS = GETPOST('sizeS','int')==''?"NULL":GETPOST('sizeS','int');
  170. $object->size_units = GETPOST('size_units','int');
  171. $object->weight_units = GETPOST('weight_units','int');
  172. $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'));
  173. // On va boucler sur chaque ligne du document d'origine pour completer objet expedition
  174. // avec info diverses + qte a livrer
  175. $classname = ucfirst($object->origin);
  176. $objectsrc = new $classname($db);
  177. $objectsrc->fetch($object->origin_id);
  178. $object->socid = $objectsrc->socid;
  179. $object->ref_customer = GETPOST('ref_customer','alpha');
  180. $object->model_pdf = GETPOST('model');
  181. $object->date_delivery = $date_delivery; // Date delivery planed
  182. $object->fk_delivery_address = $objectsrc->fk_delivery_address;
  183. $object->shipping_method_id = GETPOST('shipping_method_id','int');
  184. $object->tracking_number = GETPOST('tracking_number','alpha');
  185. $object->ref_int = GETPOST('ref_int','alpha');
  186. $object->note_private = GETPOST('note_private','none');
  187. $object->note_public = GETPOST('note_public','none');
  188. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  189. $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
  190. $batch_line = array();
  191. $stockLine = array();
  192. $array_options=array();
  193. $num=count($objectsrc->lines);
  194. $totalqty=0;
  195. for ($i = 0; $i < $num; $i++)
  196. {
  197. $idl="idl".$i;
  198. $sub_qty=array();
  199. $subtotalqty=0;
  200. $j=0;
  201. $batch="batchl".$i."_0";
  202. $stockLocation="ent1".$i."_0";
  203. $qty = "qtyl".$i;
  204. if ($objectsrc->lines[$i]->product_tobatch) // If product need a batch number
  205. {
  206. if (isset($_POST[$batch]))
  207. {
  208. //shipment line with batch-enable product
  209. $qty .= '_'.$j;
  210. while (isset($_POST[$batch]))
  211. {
  212. // save line of detail into sub_qty
  213. $sub_qty[$j]['q']=GETPOST($qty,'int'); // the qty we want to move for this stock record
  214. $sub_qty[$j]['id_batch']=GETPOST($batch,'int'); // the id into llx_product_batch of stock record to move
  215. $subtotalqty+=$sub_qty[$j]['q'];
  216. //var_dump($qty);var_dump($batch);var_dump($sub_qty[$j]['q']);var_dump($sub_qty[$j]['id_batch']);
  217. $j++;
  218. $batch="batchl".$i."_".$j;
  219. $qty = "qtyl".$i.'_'.$j;
  220. }
  221. $batch_line[$i]['detail']=$sub_qty; // array of details
  222. $batch_line[$i]['qty']=$subtotalqty;
  223. $batch_line[$i]['ix_l']=GETPOST($idl,'int');
  224. $totalqty+=$subtotalqty;
  225. }
  226. else
  227. {
  228. // No detail were provided for lots
  229. if (! empty($_POST[$qty]))
  230. {
  231. // We try to set an amount
  232. // Case we dont use the list of available qty for each warehouse/lot
  233. // GUI does not allow this yet
  234. setEventMessages($langs->trans("StockIsRequiredToChooseWhichLotToUse"), null, 'errors');
  235. }
  236. }
  237. }
  238. else if (isset($_POST[$stockLocation]))
  239. {
  240. //shipment line from multiple stock locations
  241. $qty .= '_'.$j;
  242. while (isset($_POST[$stockLocation]))
  243. {
  244. // save sub line of warehouse
  245. $stockLine[$i][$j]['qty']=GETPOST($qty,'int');
  246. $stockLine[$i][$j]['warehouse_id']=GETPOST($stockLocation,'int');
  247. $stockLine[$i][$j]['ix_l']=GETPOST($idl,'int');
  248. $totalqty+=GETPOST($qty,'int');
  249. $j++;
  250. $stockLocation="ent1".$i."_".$j;
  251. $qty = "qtyl".$i.'_'.$j;
  252. }
  253. }
  254. else
  255. {
  256. //var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit;
  257. //shipment line for product with no batch management and no multiple stock location
  258. if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int');
  259. }
  260. // Extrafields
  261. $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  262. $array_options[$i] = $extrafieldsline->getOptionalsFromPost($extralabelsline, $i);
  263. // Unset extrafield
  264. if (is_array($extralabelsline)) {
  265. // Get extra fields
  266. foreach ($extralabelsline as $key => $value) {
  267. unset($_POST["options_" . $key]);
  268. }
  269. }
  270. }
  271. //var_dump($batch_line[2]);
  272. if ($totalqty > 0) // There is at least one thing to ship
  273. {
  274. //var_dump($_POST);exit;
  275. for ($i = 0; $i < $num; $i++)
  276. {
  277. $qty = "qtyl".$i;
  278. if (! isset($batch_line[$i]))
  279. {
  280. // not batch mode
  281. if (isset($stockLine[$i]))
  282. {
  283. //shipment from multiple stock locations
  284. $nbstockline = count($stockLine[$i]);
  285. for($j = 0; $j < $nbstockline; $j++)
  286. {
  287. if ($stockLine[$i][$j]['qty']>0)
  288. {
  289. $ret=$object->addline($stockLine[$i][$j]['warehouse_id'], $stockLine[$i][$j]['ix_l'], $stockLine[$i][$j]['qty'], $array_options[$i]);
  290. if ($ret < 0)
  291. {
  292. setEventMessages($object->error, $object->errors, 'errors');
  293. $error++;
  294. }
  295. }
  296. }
  297. }
  298. else
  299. {
  300. if (GETPOST($qty,'int') > 0 || (GETPOST($qty,'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS))
  301. {
  302. $ent = "entl".$i;
  303. $idl = "idl".$i;
  304. $entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int');
  305. if ($entrepot_id < 0) $entrepot_id='';
  306. if (! ($objectsrc->lines[$i]->fk_product > 0)) $entrepot_id = 0;
  307. $ret=$object->addline($entrepot_id, GETPOST($idl,'int'), GETPOST($qty,'int'), $array_options[$i]);
  308. if ($ret < 0)
  309. {
  310. setEventMessages($object->error, $object->errors, 'errors');
  311. $error++;
  312. }
  313. }
  314. }
  315. }
  316. else
  317. {
  318. // batch mode
  319. if ($batch_line[$i]['qty']>0)
  320. {
  321. $ret=$object->addline_batch($batch_line[$i],$array_options[$i]);
  322. if ($ret < 0)
  323. {
  324. setEventMessages($object->error, $object->errors, 'errors');
  325. $error++;
  326. }
  327. }
  328. }
  329. }
  330. // Fill array 'array_options' with data from add form
  331. $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
  332. if ($ret < 0) $error++;
  333. if (! $error)
  334. {
  335. $ret=$object->create($user); // This create shipment (like Odoo picking) and line of shipments. Stock movement will when validating shipment.
  336. if ($ret <= 0)
  337. {
  338. setEventMessages($object->error, $object->errors, 'errors');
  339. $error++;
  340. }
  341. }
  342. }
  343. else
  344. {
  345. setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("QtyToShip").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
  346. $error++;
  347. }
  348. if (! $error)
  349. {
  350. $db->commit();
  351. header("Location: card.php?id=".$object->id);
  352. exit;
  353. }
  354. else
  355. {
  356. $db->rollback();
  357. $_GET["commande_id"]=GETPOST('commande_id','int');
  358. $action='create';
  359. }
  360. }
  361. /*
  362. * Build a receiving receipt
  363. */
  364. else if ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)
  365. {
  366. $result = $object->create_delivery($user);
  367. if ($result > 0)
  368. {
  369. header("Location: ".DOL_URL_ROOT.'/livraison/card.php?action=create_delivery&id='.$result);
  370. exit;
  371. }
  372. else
  373. {
  374. setEventMessages($object->error, $object->errors, 'errors');
  375. }
  376. }
  377. else if ($action == 'confirm_valid' && $confirm == 'yes' &&
  378. ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer))
  379. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate)))
  380. )
  381. {
  382. $object->fetch_thirdparty();
  383. $result = $object->valid($user);
  384. if ($result < 0)
  385. {
  386. $langs->load("errors");
  387. setEventMessages($langs->trans($object->error), null, 'errors');
  388. }
  389. else
  390. {
  391. // Define output language
  392. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  393. {
  394. $outputlangs = $langs;
  395. $newlang = '';
  396. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
  397. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  398. if (! empty($newlang)) {
  399. $outputlangs = new Translate("", $conf);
  400. $outputlangs->setDefaultLang($newlang);
  401. }
  402. $model=$object->modelpdf;
  403. $ret = $object->fetch($id); // Reload to get new records
  404. $result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  405. if ($result < 0) dol_print_error($db,$result);
  406. }
  407. }
  408. }
  409. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)
  410. {
  411. $result = $object->delete();
  412. if ($result > 0)
  413. {
  414. header("Location: ".DOL_URL_ROOT.'/expedition/index.php');
  415. exit;
  416. }
  417. else
  418. {
  419. setEventMessages($object->error, $object->errors, 'errors');
  420. }
  421. }
  422. // TODO add alternative status
  423. /*else if ($action == 'reopen' && (! empty($user->rights->expedition->creer) || ! empty($user->rights->expedition->shipping_advance->validate)))
  424. {
  425. $result = $object->setStatut(0);
  426. if ($result < 0)
  427. {
  428. setEventMessages($object->error, $object->errors, 'errors');
  429. }
  430. }*/
  431. else if ($action == 'setdate_livraison' && $user->rights->expedition->creer)
  432. {
  433. //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
  434. $datedelivery=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'), GETPOST('liv_year','int'));
  435. $object->fetch($id);
  436. $result=$object->set_date_livraison($user,$datedelivery);
  437. if ($result < 0)
  438. {
  439. setEventMessages($object->error, $object->errors, 'errors');
  440. }
  441. }
  442. // Action update
  443. else if (
  444. ($action == 'settracking_number'
  445. || $action == 'settracking_url'
  446. || $action == 'settrueWeight'
  447. || $action == 'settrueWidth'
  448. || $action == 'settrueHeight'
  449. || $action == 'settrueDepth'
  450. || $action == 'setshipping_method_id')
  451. && $user->rights->expedition->creer
  452. )
  453. {
  454. $error=0;
  455. if ($action == 'settracking_number') $object->tracking_number = trim(GETPOST('tracking_number','alpha'));
  456. if ($action == 'settracking_url') $object->tracking_url = trim(GETPOST('tracking_url','int'));
  457. if ($action == 'settrueWeight') {
  458. $object->trueWeight = trim(GETPOST('trueWeight','int'));
  459. $object->weight_units = GETPOST('weight_units','int');
  460. }
  461. if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth','int'));
  462. if ($action == 'settrueHeight'){
  463. $object->trueHeight = trim(GETPOST('trueHeight','int'));
  464. $object->size_units = GETPOST('size_units','int');
  465. }
  466. if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth','int'));
  467. if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
  468. if (! $error)
  469. {
  470. if ($object->update($user) >= 0)
  471. {
  472. header("Location: card.php?id=".$object->id);
  473. exit;
  474. }
  475. setEventMessages($object->error, $object->errors, 'errors');
  476. }
  477. $action="";
  478. }
  479. elseif ($action == 'classifybilled')
  480. {
  481. $object->fetch($id);
  482. $result = $object->set_billed();
  483. if($result >= 0) {
  484. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  485. exit();
  486. }
  487. }
  488. elseif ($action == 'classifyclosed')
  489. {
  490. $object->fetch($id);
  491. $result = $object->setClosed();
  492. if($result >= 0) {
  493. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  494. exit();
  495. }
  496. }
  497. /*
  498. * delete a line
  499. */
  500. elseif ($action == 'deleteline' && ! empty($line_id))
  501. {
  502. $object->fetch($id);
  503. $lines = $object->lines;
  504. $line = new ExpeditionLigne($db);
  505. $num_prod = count($lines);
  506. for ($i = 0 ; $i < $num_prod ; $i++)
  507. {
  508. if ($lines[$i]->id == $line_id)
  509. {
  510. if (count($lines[$i]->details_entrepot) > 1)
  511. {
  512. // delete multi warehouse lines
  513. foreach ($lines[$i]->details_entrepot as $details_entrepot) {
  514. $line->id = $details_entrepot->line_id;
  515. if (! $error && $line->delete($user) < 0)
  516. {
  517. $error++;
  518. }
  519. }
  520. }
  521. else
  522. {
  523. // delete single warehouse line
  524. $line->id = $line_id;
  525. if (! $error && $line->delete($user) < 0)
  526. {
  527. $error++;
  528. }
  529. }
  530. }
  531. unset($_POST["lineid"]);
  532. }
  533. if(! $error) {
  534. header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
  535. exit();
  536. }
  537. else
  538. {
  539. setEventMessages($line->error, $line->errors, 'errors');
  540. }
  541. }
  542. /*
  543. * Update a line
  544. */
  545. else if ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('save'))
  546. {
  547. // Clean parameters
  548. $qty=0;
  549. $entrepot_id = 0;
  550. $batch_id = 0;
  551. $lines = $object->lines;
  552. $num_prod = count($lines);
  553. for ($i = 0 ; $i < $num_prod ; $i++)
  554. {
  555. if ($lines[$i]->id == $line_id) // we have found line to update
  556. {
  557. $line = new ExpeditionLigne($db);
  558. // Extrafields Lines
  559. $extrafieldsline = new ExtraFields($db);
  560. $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  561. $line->array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
  562. // Unset extrafield POST Data
  563. if (is_array($extralabelsline)) {
  564. foreach ($extralabelsline as $key => $value) {
  565. unset($_POST["options_" . $key]);
  566. }
  567. }
  568. $line->fk_product = $lines[$i]->fk_product;
  569. if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0)
  570. {
  571. // line with lot
  572. foreach ($lines[$i]->detail_batch as $detail_batch)
  573. {
  574. $lotStock = new Productbatch($db);
  575. $batch="batchl".$detail_batch->fk_expeditiondet."_".$detail_batch->fk_origin_stock;
  576. $qty = "qtyl".$detail_batch->fk_expeditiondet.'_'.$detail_batch->id;
  577. $batch_id = GETPOST($batch,'int');
  578. $batch_qty = GETPOST($qty, 'int');
  579. if (! empty($batch_id) && ($batch_id != $detail_batch->fk_origin_stock || $batch_qty != $detail_batch->qty))
  580. {
  581. if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0) // $line is ExpeditionLine
  582. {
  583. if ($lines[$i]->entrepot_id != 0)
  584. {
  585. // allow update line entrepot_id if not multi warehouse shipping
  586. $line->entrepot_id = $lotStock->warehouseid;
  587. }
  588. // detail_batch can be an object with keys, or an array of ExpeditionLineBatch
  589. if (empty($line->detail_batch)) $line->detail_batch=new stdClass();
  590. $line->detail_batch->fk_origin_stock = $batch_id;
  591. $line->detail_batch->batch = $lotStock->batch;
  592. $line->detail_batch->id = $detail_batch->id;
  593. $line->detail_batch->entrepot_id = $lotStock->warehouseid;
  594. $line->detail_batch->qty = $batch_qty;
  595. if ($line->update($user) < 0) {
  596. setEventMessages($line->error, $line->errors, 'errors');
  597. $error++;
  598. }
  599. }
  600. else
  601. {
  602. setEventMessages($lotStock->error, $lotStock->errors, 'errors');
  603. $error++;
  604. }
  605. }
  606. unset($_POST[$batch]);
  607. unset($_POST[$qty]);
  608. }
  609. // add new batch
  610. $lotStock = new Productbatch($db);
  611. $batch="batchl".$line_id."_0";
  612. $qty = "qtyl".$line_id."_0";
  613. $batch_id = GETPOST($batch,'int');
  614. $batch_qty = GETPOST($qty, 'int');
  615. $lineIdToAddLot = 0;
  616. if ($batch_qty > 0 && ! empty($batch_id))
  617. {
  618. if ($lotStock->fetch($batch_id) > 0)
  619. {
  620. // check if lotStock warehouse id is same as line warehouse id
  621. if ($lines[$i]->entrepot_id > 0)
  622. {
  623. // single warehouse shipment line
  624. if ($lines[i]->entrepot_id == $lotStock->warehouseid)
  625. {
  626. $lineIdToAddLot = $line_id;
  627. }
  628. }
  629. else if (count($lines[$i]->details_entrepot) > 1)
  630. {
  631. // multi warehouse shipment lines
  632. foreach ($lines[$i]->details_entrepot as $detail_entrepot)
  633. {
  634. if ($detail_entrepot->entrepot_id == $lotStock->warehouseid)
  635. {
  636. $lineIdToAddLot = $detail_entrepot->line_id;
  637. }
  638. }
  639. }
  640. if ($lineIdToAddLot)
  641. {
  642. // add lot to existing line
  643. if ($line->fetch($lineIdToAddLot) > 0)
  644. {
  645. $line->detail_batch->fk_origin_stock = $batch_id;
  646. $line->detail_batch->batch = $lotStock->batch;
  647. $line->detail_batch->entrepot_id = $lotStock->warehouseid;
  648. $line->detail_batch->qty = $batch_qty;
  649. if ($line->update($user) < 0) {
  650. setEventMessages($line->error, $line->errors, 'errors');
  651. $error++;
  652. }
  653. }
  654. else
  655. {
  656. setEventMessages($line->error, $line->errors, 'errors');
  657. $error++;
  658. }
  659. }
  660. else
  661. {
  662. // create new line with new lot
  663. $line->origin_line_id = $lines[$i]->origin_line_id;
  664. $line->entrepot_id = $lotStock->warehouseid;
  665. $line->detail_batch[0] = new ExpeditionLineBatch($db);
  666. $line->detail_batch[0]->fk_origin_stock = $batch_id;
  667. $line->detail_batch[0]->batch = $lotStock->batch;
  668. $line->detail_batch[0]->entrepot_id = $lotStock->warehouseid;
  669. $line->detail_batch[0]->qty = $batch_qty;
  670. if ($object->create_line_batch($line, $line->array_options) < 0)
  671. {
  672. setEventMessages($object->error, $object->errors, 'errors');
  673. $error++;
  674. }
  675. }
  676. }
  677. else
  678. {
  679. setEventMessages($lotStock->error, $lotStock->errors, 'errors');
  680. $error++;
  681. }
  682. }
  683. }
  684. else
  685. {
  686. if ($lines[$i]->fk_product > 0)
  687. {
  688. // line without lot
  689. if ($lines[$i]->entrepot_id > 0)
  690. {
  691. // single warehouse shipment line
  692. $stockLocation="entl".$line_id;
  693. $qty = "qtyl".$line_id;
  694. $line->id = $line_id;
  695. $line->entrepot_id = GETPOST($stockLocation,'int');
  696. $line->qty = GETPOST($qty, 'int');
  697. if ($line->update($user) < 0) {
  698. setEventMessages($line->error, $line->errors, 'errors');
  699. $error++;
  700. }
  701. unset($_POST[$stockLocation]);
  702. unset($_POST[$qty]);
  703. }
  704. else if (count($lines[$i]->details_entrepot) > 1)
  705. {
  706. // multi warehouse shipment lines
  707. foreach ($lines[$i]->details_entrepot as $detail_entrepot)
  708. {
  709. if (! $error) {
  710. $stockLocation="entl".$detail_entrepot->line_id;
  711. $qty = "qtyl".$detail_entrepot->line_id;
  712. $warehouse = GETPOST($stockLocation,'int');
  713. if (!empty ($warehouse))
  714. {
  715. $line->id = $detail_entrepot->line_id;
  716. $line->entrepot_id = $warehouse;
  717. $line->qty = GETPOST($qty, 'int');
  718. if ($line->update($user) < 0) {
  719. setEventMessages($line->error, $line->errors, 'errors');
  720. $error++;
  721. }
  722. }
  723. unset($_POST[$stockLocation]);
  724. unset($_POST[$qty]);
  725. }
  726. }
  727. }
  728. }
  729. else // Product no predefined
  730. {
  731. $qty = "qtyl".$line_id;
  732. $line->id = $line_id;
  733. $line->qty = GETPOST($qty, 'int');
  734. $line->entrepot_id = 0;
  735. if ($line->update($user) < 0) {
  736. setEventMessages($line->error, $line->errors, 'errors');
  737. $error++;
  738. }
  739. unset($_POST[$qty]);
  740. }
  741. }
  742. }
  743. }
  744. unset($_POST["lineid"]);
  745. if (! $error) {
  746. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  747. // Define output language
  748. $outputlangs = $langs;
  749. $newlang = '';
  750. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09'))
  751. $newlang = GETPOST('lang_id','aZ09');
  752. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  753. $newlang = $object->thirdparty->default_lang;
  754. if (! empty($newlang)) {
  755. $outputlangs = new Translate("", $conf);
  756. $outputlangs->setDefaultLang($newlang);
  757. }
  758. $ret = $object->fetch($object->id); // Reload to get new records
  759. $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  760. }
  761. }
  762. else
  763. {
  764. header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
  765. exit();
  766. }
  767. }
  768. else if ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('cancel','alpha') == $langs->trans('Cancel')) {
  769. header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition
  770. exit();
  771. }
  772. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  773. // Actions to send emails
  774. if (empty($id)) $id=$facid;
  775. $trigger_name='SHIPPING_SENTBYMAIL';
  776. $paramname='id';
  777. $mode='emailfromshipment';
  778. $trackid='shi'.$object->id;
  779. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  780. }
  781. /*
  782. * View
  783. */
  784. llxHeader('',$langs->trans('Shipment'),'Expedition');
  785. $form = new Form($db);
  786. $formfile = new FormFile($db);
  787. $formproduct = new FormProduct($db);
  788. if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
  789. $product_static = new Product($db);
  790. $shipment_static = new Expedition($db);
  791. $warehousestatic = new Entrepot($db);
  792. if ($action == 'create2')
  793. {
  794. print load_fiche_titre($langs->trans("CreateShipment")).'<br>';
  795. print $langs->trans("ShipmentCreationIsDoneFromOrder");
  796. $action=''; $id=''; $ref='';
  797. }
  798. // Mode creation.
  799. if ($action == 'create')
  800. {
  801. $expe = new Expedition($db);
  802. print load_fiche_titre($langs->trans("CreateShipment"));
  803. if (! $origin)
  804. {
  805. setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors');
  806. }
  807. if ($origin)
  808. {
  809. $classname = ucfirst($origin);
  810. $object = new $classname($db);
  811. if ($object->fetch($origin_id)) // This include the fetch_lines
  812. {
  813. $soc = new Societe($db);
  814. $soc->fetch($object->socid);
  815. $author = new User($db);
  816. $author->fetch($object->user_author_id);
  817. if (! empty($conf->stock->enabled)) $entrepot = new Entrepot($db);
  818. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  819. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  820. print '<input type="hidden" name="action" value="add">';
  821. print '<input type="hidden" name="origin" value="'.$origin.'">';
  822. print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
  823. print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';
  824. if (GETPOST('entrepot_id','int'))
  825. {
  826. print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id','int').'">';
  827. }
  828. dol_fiche_head('');
  829. print '<table class="border centpercent">';
  830. // Ref
  831. print '<tr><td class="titlefieldcreate fieldrequired">';
  832. if ($origin == 'commande' && ! empty($conf->commande->enabled))
  833. {
  834. 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;
  835. }
  836. if ($origin == 'propal' && ! empty($conf->propal->enabled))
  837. {
  838. 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;
  839. }
  840. print '</a></td>';
  841. print "</tr>\n";
  842. // Ref client
  843. print '<tr><td>';
  844. if ($origin == 'commande') print $langs->trans('RefCustomerOrder');
  845. else if ($origin == 'propal') print $langs->trans('RefCustomerOrder');
  846. else print $langs->trans('RefCustomer');
  847. print '</td><td colspan="3">';
  848. print '<input type="text" name="ref_customer" value="'.$object->ref_client.'" />';
  849. print '</td>';
  850. print '</tr>';
  851. // Tiers
  852. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Company').'</td>';
  853. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  854. print '</tr>';
  855. // Project
  856. if (! empty($conf->projet->enabled))
  857. {
  858. $projectid = GETPOST('projectid','int')?GETPOST('projectid','int'):0;
  859. if(empty($projectid) && ! empty($object->fk_project)) $projectid = $object->fk_project;
  860. if ($origin == 'project') $projectid = ($originid ? $originid : 0);
  861. $langs->load("projects");
  862. print '<tr>';
  863. print '<td>' . $langs->trans("Project") . '</td><td colspan="2">';
  864. $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0);
  865. print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid=' . $soc->id . '&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'">' . $langs->trans("AddProject") . '</a>';
  866. print '</td>';
  867. print '</tr>';
  868. }
  869. // Date delivery planned
  870. print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
  871. print '<td colspan="3">';
  872. //print dol_print_date($object->date_livraison,"day"); // date_livraison come from order and will be stored into date_delivery planed.
  873. $date_delivery = ($date_delivery?$date_delivery:$object->date_livraison); // $date_delivery comes from GETPOST
  874. print $form->selectDate($date_delivery?$date_delivery:-1, 'date_delivery', 1, 1, 1);
  875. print "</td>\n";
  876. print '</tr>';
  877. // Note Public
  878. print '<tr><td>'.$langs->trans("NotePublic").'</td>';
  879. print '<td colspan="3">';
  880. $doleditor = new DolEditor('note_public', $object->note_public, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  881. print $doleditor->Create(1);
  882. print "</td></tr>";
  883. // Note Private
  884. if ($object->note_private && ! $user->societe_id)
  885. {
  886. print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
  887. print '<td colspan="3">';
  888. $doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  889. print $doleditor->Create(1);
  890. print "</td></tr>";
  891. }
  892. // Weight
  893. print '<tr><td>';
  894. print $langs->trans("Weight");
  895. print '</td><td colspan="3"><input name="weight" size="4" value="'.GETPOST('weight','int').'"> ';
  896. $text=$formproduct->select_measuring_units("weight_units","weight",GETPOST('weight_units','int'));
  897. $htmltext=$langs->trans("KeepEmptyForAutoCalculation");
  898. print $form->textwithpicto($text, $htmltext);
  899. print '</td></tr>';
  900. // Dim
  901. print '<tr><td>';
  902. print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");
  903. print ' </td><td colspan="3"><input name="sizeW" size="4" value="'.GETPOST('sizeW','int').'">';
  904. print ' x <input name="sizeH" size="4" value="'.GETPOST('sizeH','int').'">';
  905. print ' x <input name="sizeS" size="4" value="'.GETPOST('sizeS','int').'">';
  906. print ' ';
  907. $text=$formproduct->select_measuring_units("size_units","size");
  908. $htmltext=$langs->trans("KeepEmptyForAutoCalculation");
  909. print $form->textwithpicto($text, $htmltext);
  910. print '</td></tr>';
  911. // Delivery method
  912. print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";
  913. print '<td colspan="3">';
  914. $expe->fetch_delivery_methods();
  915. print $form->selectarray("shipping_method_id", $expe->meths, GETPOST('shipping_method_id','int'),1,0,0,"",1);
  916. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  917. print "</td></tr>\n";
  918. // Tracking number
  919. print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
  920. print '<td colspan="3">';
  921. print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number','alpha').'">';
  922. print "</td></tr>\n";
  923. // Other attributes
  924. $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'socid'=>$socid);
  925. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$expe,$action); // Note that $action and $object may have been modified by hook
  926. print $hookmanager->resPrint;
  927. if (empty($reshook)) {
  928. // copy from order
  929. $orderExtrafields = new Extrafields($db);
  930. $orderExtrafieldLabels = $orderExtrafields->fetch_name_optionals_label($object->table_element);
  931. if ($object->fetch_optionals() > 0) {
  932. $expe->array_options = array_merge($expe->array_options, $object->array_options);
  933. }
  934. print $expe->showOptionals($extrafields, 'edit');
  935. }
  936. // Incoterms
  937. if (!empty($conf->incoterm->enabled))
  938. {
  939. print '<tr>';
  940. print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->libelle_incoterms, 1).'</label></td>';
  941. print '<td colspan="3" class="maxwidthonsmartphone">';
  942. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''));
  943. print '</td></tr>';
  944. }
  945. // Document model
  946. include_once DOL_DOCUMENT_ROOT . '/core/modules/expedition/modules_expedition.php';
  947. $liste = ModelePdfExpedition::liste_modeles($db);
  948. if (count($liste) > 1)
  949. {
  950. print "<tr><td>".$langs->trans("DefaultModel")."</td>";
  951. print '<td colspan="3">';
  952. print $form->selectarray('model', $liste, $conf->global->EXPEDITION_ADDON_PDF);
  953. print "</td></tr>\n";
  954. }
  955. print "</table>";
  956. dol_fiche_end();
  957. // Shipment lines
  958. $numAsked = count($object->lines);
  959. print '<script type="text/javascript" language="javascript">
  960. jQuery(document).ready(function() {
  961. jQuery("#autofill").click(function() {';
  962. $i=0;
  963. while($i < $numAsked)
  964. {
  965. print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
  966. $i++;
  967. }
  968. print '});
  969. jQuery("#autoreset").click(function() {';
  970. $i=0;
  971. while($i < $numAsked)
  972. {
  973. print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
  974. $i++;
  975. }
  976. print '});
  977. });
  978. </script>';
  979. print '<br>';
  980. print '<table class="noborder" width="100%">';
  981. // Load shipments already done for same order
  982. $object->loadExpeditions();
  983. if ($numAsked)
  984. {
  985. print '<tr class="liste_titre">';
  986. print '<td>'.$langs->trans("Description").'</td>';
  987. print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
  988. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  989. print '<td align="center">'.$langs->trans("QtyToShip");
  990. if (empty($conf->productbatch->enabled))
  991. {
  992. print ' <br>(<a href="#" id="autofill">'.$langs->trans("Fill").'</a>';
  993. print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';
  994. }
  995. print '</td>';
  996. if (! empty($conf->stock->enabled))
  997. {
  998. if (empty($conf->productbatch->enabled))
  999. {
  1000. print '<td align="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
  1001. }
  1002. else
  1003. {
  1004. print '<td align="left">'.$langs->trans("Warehouse").' / '.$langs->trans("Batch").' ('.$langs->trans("Stock").')</td>';
  1005. }
  1006. }
  1007. print "</tr>\n";
  1008. }
  1009. $indiceAsked = 0;
  1010. while ($indiceAsked < $numAsked)
  1011. {
  1012. $product = new Product($db);
  1013. $line = $object->lines[$indiceAsked];
  1014. // Show product and description
  1015. $type=$line->product_type?$line->product_type:$line->fk_product_type;
  1016. // Try to enhance type detection using date_start and date_end for free lines where type
  1017. // was not saved.
  1018. if (! empty($line->date_start)) $type=1;
  1019. if (! empty($line->date_end)) $type=1;
  1020. print '<!-- line '.$line->rowid.' for product -->'."\n";
  1021. print '<tr class="oddeven">'."\n";
  1022. // Product label
  1023. if ($line->fk_product > 0) // If predefined product
  1024. {
  1025. $product->fetch($line->fk_product);
  1026. $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
  1027. //var_dump($product->stock_warehouse[1]);
  1028. print '<td>';
  1029. print '<a name="'.$line->rowid.'"></a>'; // ancre pour retourner sur la ligne
  1030. // Show product and description
  1031. $product_static->type=$line->fk_product_type;
  1032. $product_static->id=$line->fk_product;
  1033. $product_static->ref=$line->ref;
  1034. $product_static->status_batch=$line->product_tobatch;
  1035. $text=$product_static->getNomUrl(1);
  1036. $text.= ' - '.(! empty($line->label)?$line->label:$line->product_label);
  1037. $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->desc));
  1038. print $form->textwithtooltip($text,$description,3,'','',$i);
  1039. // Show range
  1040. print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
  1041. // Add description in form
  1042. if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
  1043. {
  1044. print ($line->desc && $line->desc!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->desc):'';
  1045. }
  1046. print '</td>';
  1047. }
  1048. else
  1049. {
  1050. print "<td>";
  1051. if ($type==1) $text = img_object($langs->trans('Service'),'service');
  1052. else $text = img_object($langs->trans('Product'),'product');
  1053. if (! empty($line->label)) {
  1054. $text.= ' <strong>'.$line->label.'</strong>';
  1055. print $form->textwithtooltip($text,$line->desc,3,'','',$i);
  1056. } else {
  1057. print $text.' '.nl2br($line->desc);
  1058. }
  1059. // Show range
  1060. print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
  1061. print "</td>\n";
  1062. }
  1063. // Qty
  1064. print '<td align="center">'.$line->qty;
  1065. print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
  1066. print '</td>';
  1067. $qtyProdCom=$line->qty;
  1068. // Qty already shipped
  1069. print '<td align="center">';
  1070. $quantityDelivered = $object->expeditions[$line->id];
  1071. print $quantityDelivered;
  1072. print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
  1073. print '</td>';
  1074. // Qty to ship
  1075. $quantityAsked = $line->qty;
  1076. if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES))
  1077. {
  1078. $quantityToBeDelivered = 0;
  1079. }
  1080. else
  1081. {
  1082. $quantityToBeDelivered = $quantityAsked - $quantityDelivered;
  1083. }
  1084. $warehouse_id = GETPOST('entrepot_id','int');
  1085. $warehouseObject = null;
  1086. 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
  1087. {
  1088. print '<!-- Case warehouse already known or product not a predefined product -->';
  1089. //ship from preselected location
  1090. $stock = + $product->stock_warehouse[$warehouse_id]->real; // Convert to number
  1091. $deliverableQty=min($quantityToBeDelivered, $stock);
  1092. if ($deliverableQty < 0) $deliverableQty = 0;
  1093. if (empty($conf->productbatch->enabled) || ! $product->hasbatch())
  1094. {
  1095. // Quantity to send
  1096. print '<td align="center">';
  1097. if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  1098. {
  1099. if (GETPOST('qtyl'.$indiceAsked, 'int')) $deliverableQty=GETPOST('qtyl'.$indiceAsked, 'int');
  1100. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1101. print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
  1102. }
  1103. else print $langs->trans("NA");
  1104. print '</td>';
  1105. // Stock
  1106. if (! empty($conf->stock->enabled))
  1107. {
  1108. print '<td align="left">';
  1109. if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) // Type of product need stock change ?
  1110. {
  1111. // Show warehouse combo list
  1112. $ent = "entl".$indiceAsked;
  1113. $idl = "idl".$indiceAsked;
  1114. $tmpentrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):$warehouse_id;
  1115. if ($line->fk_product > 0)
  1116. {
  1117. print '<!-- Show warehouse selection -->';
  1118. print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1);
  1119. if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id)
  1120. {
  1121. //print $stock.' '.$quantityToBeDelivered;
  1122. if ($stock < $quantityToBeDelivered)
  1123. {
  1124. print ' '.img_warning($langs->trans("StockTooLow")); // Stock too low for this $warehouse_id but you can change warehouse
  1125. }
  1126. }
  1127. }
  1128. }
  1129. else
  1130. {
  1131. print $langs->trans("Service");
  1132. }
  1133. print '</td>';
  1134. }
  1135. print "</tr>\n";
  1136. // Show subproducts of product
  1137. if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)
  1138. {
  1139. $product->get_sousproduits_arbo();
  1140. $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
  1141. if(count($prods_arbo) > 0)
  1142. {
  1143. foreach($prods_arbo as $key => $value)
  1144. {
  1145. //print $value[0];
  1146. $img='';
  1147. if ($value['stock'] < $value['stock_alert'])
  1148. {
  1149. $img=img_warning($langs->trans("StockTooLow"));
  1150. }
  1151. print "<tr class=\"oddeven\"><td>&nbsp; &nbsp; &nbsp; ->
  1152. <a href=\"".DOL_URL_ROOT."/product/card.php?id=".$value['id']."\">".$value['fullpath']."
  1153. </a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
  1154. <td align=\"center\">".$value['stock']." ".$img."</td></tr>";
  1155. }
  1156. }
  1157. }
  1158. }
  1159. else
  1160. {
  1161. // Product need lot
  1162. print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial
  1163. print '<!-- Case product need lot -->';
  1164. $staticwarehouse=new Entrepot($db);
  1165. if ($warehouse_id > 0) $staticwarehouse->fetch($warehouse_id);
  1166. $subj=0;
  1167. // Define nb of lines suggested for this order line
  1168. $nbofsuggested=0;
  1169. if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch))
  1170. {
  1171. foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch)
  1172. {
  1173. $nbofsuggested++;
  1174. }
  1175. }
  1176. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1177. if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch))
  1178. {
  1179. foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) // $dbatch is instance of Productbatch
  1180. {
  1181. //var_dump($dbatch);
  1182. $batchStock = + $dbatch->qty; // To get a numeric
  1183. $deliverableQty = min($quantityToBeDelivered,$batchStock);
  1184. print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested)?$bc[$var]:'').'>';
  1185. print '<td colspan="3" ></td><td align="center">';
  1186. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';
  1187. print '</td>';
  1188. print '<!-- Show details of lot -->';
  1189. print '<td align="left">';
  1190. print $staticwarehouse->getNomUrl(0).' / ';
  1191. print '<input name="batchl'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$dbatch->id.'">';
  1192. $detail='';
  1193. $detail.= $langs->trans("Batch").': '.$dbatch->batch;
  1194. $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
  1195. $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
  1196. $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
  1197. $detail.= '<br>';
  1198. print $detail;
  1199. $quantityToBeDelivered -= $deliverableQty;
  1200. if ($quantityToBeDelivered < 0)
  1201. {
  1202. $quantityToBeDelivered = 0;
  1203. }
  1204. $subj++;
  1205. print '</td></tr>';
  1206. }
  1207. }
  1208. else
  1209. {
  1210. print '<!-- Case there is no details of lot at all -->';
  1211. print '<tr class="oddeven"><td colspan="3"></td><td align="center">';
  1212. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0" disabled="disabled"> ';
  1213. print '</td>';
  1214. print '<td align="left">';
  1215. print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $staticwarehouse->libelle);
  1216. print '</td></tr>';
  1217. }
  1218. }
  1219. }
  1220. else
  1221. {
  1222. // ship from multiple locations
  1223. if (empty($conf->productbatch->enabled) || ! $product->hasbatch())
  1224. {
  1225. print '<!-- Case warehouse not already known and product does not need lot -->';
  1226. print '<td></td><td></td></tr>'."\n"; // end line and start a new one for each warehouse
  1227. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1228. $subj=0;
  1229. // Define nb of lines suggested for this order line
  1230. $nbofsuggested=0;
  1231. foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)
  1232. {
  1233. if ($stock_warehouse->real > 0)
  1234. {
  1235. $nbofsuggested++;
  1236. }
  1237. }
  1238. $tmpwarehouseObject=new Entrepot($db);
  1239. foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse) // $stock_warehouse is product_stock
  1240. {
  1241. $tmpwarehouseObject->fetch($warehouse_id);
  1242. if ($stock_warehouse->real > 0)
  1243. {
  1244. $stock = + $stock_warehouse->real; // Convert it to number
  1245. $deliverableQty = min($quantityToBeDelivered,$stock);
  1246. $deliverableQty = max(0, $deliverableQty);
  1247. // Quantity to send
  1248. print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested)?$bc[$var]:'').'>';
  1249. print '<td colspan="3" ></td><td align="center"><!-- qty to ship (no lot management for product line indiceAsked='.$indiceAsked.') -->';
  1250. if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  1251. {
  1252. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
  1253. print '<input name="ent1'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$warehouse_id.'">';
  1254. }
  1255. else print $langs->trans("NA");
  1256. print '</td>';
  1257. // Stock
  1258. if (! empty($conf->stock->enabled))
  1259. {
  1260. print '<td align="left">';
  1261. if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  1262. {
  1263. print $tmpwarehouseObject->getNomUrl(0).' ';
  1264. print '<!-- Show details of stock -->';
  1265. print '('.$stock.')';
  1266. }
  1267. else
  1268. {
  1269. print $langs->trans("Service");
  1270. }
  1271. print '</td>';
  1272. }
  1273. $quantityToBeDelivered -= $deliverableQty;
  1274. if ($quantityToBeDelivered < 0)
  1275. {
  1276. $quantityToBeDelivered = 0;
  1277. }
  1278. $subj++;
  1279. print "</tr>\n";
  1280. }
  1281. }
  1282. // Show subproducts of product (not recommanded)
  1283. if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)
  1284. {
  1285. $product->get_sousproduits_arbo();
  1286. $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
  1287. if (count($prods_arbo) > 0)
  1288. {
  1289. foreach($prods_arbo as $key => $value)
  1290. {
  1291. //print $value[0];
  1292. $img='';
  1293. if ($value['stock'] < $value['stock_alert'])
  1294. {
  1295. $img=img_warning($langs->trans("StockTooLow"));
  1296. }
  1297. print '<tr class"oddeven"><td>';
  1298. print "&nbsp; &nbsp; &nbsp; ->
  1299. <a href=\"".DOL_URL_ROOT."/product/card.php?id=".$value['id']."\">".$value['fullpath']."
  1300. </a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
  1301. <td align=\"center\">".$value['stock']." ".$img."</td>";
  1302. print "</tr>";
  1303. }
  1304. }
  1305. }
  1306. }
  1307. else
  1308. {
  1309. print '<!-- Case warehouse not already known and product need lot -->';
  1310. print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial
  1311. $subj=0;
  1312. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1313. $tmpwarehouseObject=new Entrepot($db);
  1314. $productlotObject=new Productlot($db);
  1315. // Define nb of lines suggested for this order line
  1316. $nbofsuggested=0;
  1317. foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)
  1318. {
  1319. if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) {
  1320. foreach ($stock_warehouse->detail_batch as $dbatch)
  1321. {
  1322. $nbofsuggested++;
  1323. }
  1324. }
  1325. }
  1326. foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)
  1327. {
  1328. $tmpwarehouseObject->fetch($warehouse_id);
  1329. if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) {
  1330. foreach ($stock_warehouse->detail_batch as $dbatch)
  1331. {
  1332. //var_dump($dbatch);
  1333. $batchStock = + $dbatch->qty; // To get a numeric
  1334. $deliverableQty = min($quantityToBeDelivered,$batchStock);
  1335. if ($deliverableQty < 0) $deliverableQty = 0;
  1336. print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested)?$bc[$var]:'').'><td colspan="3"></td><td align="center">';
  1337. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';
  1338. print '</td>';
  1339. print '<td align="left">';
  1340. print $tmpwarehouseObject->getNomUrl(0).' / ';
  1341. print '<!-- Show details of lot -->';
  1342. print '<input name="batchl'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$dbatch->id.'">';
  1343. //print '|'.$line->fk_product.'|'.$dbatch->batch.'|<br>';
  1344. print $langs->trans("Batch").': ';
  1345. $result = $productlotObject->fetch(0, $line->fk_product, $dbatch->batch);
  1346. if ($result > 0) print $productlotObject->getNomUrl(1);
  1347. else print 'TableLotIncompleteRunRepairWithParamStandardEqualConfirmed';
  1348. print ' ('.$dbatch->qty.')';
  1349. $quantityToBeDelivered -= $deliverableQty;
  1350. if ($quantityToBeDelivered < 0)
  1351. {
  1352. $quantityToBeDelivered = 0;
  1353. }
  1354. //dol_syslog('deliverableQty = '.$deliverableQty.' batchStock = '.$batchStock);
  1355. $subj++;
  1356. print '</td></tr>';
  1357. }
  1358. }
  1359. }
  1360. }
  1361. if ($subj == 0) // Line not shown yet, we show it
  1362. {
  1363. print '<!-- line not shown yet, we show it -->';
  1364. print '<tr class="oddeven"><td colspan="3" ></td><td align="center">';
  1365. if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  1366. {
  1367. $disabled='';
  1368. if (! empty($conf->productbatch->enabled) && $product->hasbatch())
  1369. {
  1370. $disabled='disabled="disabled"';
  1371. }
  1372. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0"'.($disabled?' '.$disabled:'').'> ';
  1373. }
  1374. else
  1375. {
  1376. print $langs->trans("NA");
  1377. }
  1378. print '</td>';
  1379. print '<td align="left">';
  1380. if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
  1381. {
  1382. $warehouse_selected_id = GETPOST('entrepot_id','int');
  1383. if ($warehouse_selected_id > 0)
  1384. {
  1385. $warehouseObject=new Entrepot($db);
  1386. $warehouseObject->fetch($warehouse_selected_id);
  1387. print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $warehouseObject->libelle);
  1388. }
  1389. else
  1390. {
  1391. if ($line->fk_product) print img_warning().' '.$langs->trans("StockTooLow");
  1392. else print '';
  1393. }
  1394. }
  1395. else
  1396. {
  1397. print $langs->trans("Service");
  1398. }
  1399. print '</td>';
  1400. print '</tr>';
  1401. }
  1402. }
  1403. //Display lines extrafields
  1404. if (is_array($extralabelslines) && count($extralabelslines)>0)
  1405. {
  1406. $colspan=5;
  1407. $orderLineExtrafields = new Extrafields($db);
  1408. $orderLineExtrafieldLabels = $orderLineExtrafields->fetch_name_optionals_label($object->table_element_line);
  1409. $srcLine = new OrderLine($db);
  1410. $srcLine->fetch_optionals($line->id); // fetch extrafields also available in orderline
  1411. $line = new ExpeditionLigne($db);
  1412. //$line->fetch_optionals($line->id);
  1413. $line->array_options = array_merge($line->array_options, $srcLine->array_options);
  1414. print '<tr class="oddeven">';
  1415. print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
  1416. print '</tr>';
  1417. }
  1418. $indiceAsked++;
  1419. }
  1420. print "</table>";
  1421. print '<br>';
  1422. print '<div class="center">';
  1423. print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
  1424. print '&nbsp; ';
  1425. print '<input type="'.($backtopage?"submit":"button").'" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"'.($backtopage?'':' onclick="javascript:history.go(-1)"').'>'; // Cancel for create does not post form if we don't know the backtopage
  1426. print '</div>';
  1427. print '</form>';
  1428. print '<br>';
  1429. }
  1430. else
  1431. {
  1432. dol_print_error($db);
  1433. }
  1434. }
  1435. }
  1436. else if ($id || $ref)
  1437. /* *************************************************************************** */
  1438. /* */
  1439. /* Edit and view mode */
  1440. /* */
  1441. /* *************************************************************************** */
  1442. {
  1443. $lines = $object->lines;
  1444. $num_prod = count($lines);
  1445. if ($object->id > 0)
  1446. {
  1447. if (!empty($object->origin) && $object->origin_id > 0)
  1448. {
  1449. $typeobject = $object->origin;
  1450. $origin = $object->origin;
  1451. $origin_id = $object->origin_id;
  1452. $object->fetch_origin(); // Load property $object->commande, $object->propal, ...
  1453. }
  1454. $soc = new Societe($db);
  1455. $soc->fetch($object->socid);
  1456. $res = $object->fetch_optionals();
  1457. $head=shipping_prepare_head($object);
  1458. dol_fiche_head($head, 'shipping', $langs->trans("Shipment"), -1, 'sending');
  1459. $formconfirm='';
  1460. // Confirm deleteion
  1461. if ($action == 'delete')
  1462. {
  1463. $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$object->ref),'confirm_delete','',0,1);
  1464. }
  1465. // Confirmation validation
  1466. if ($action == 'valid')
  1467. {
  1468. $objectref = substr($object->ref, 1, 4);
  1469. if ($objectref == 'PROV')
  1470. {
  1471. $numref = $object->getNextNumRef($soc);
  1472. }
  1473. else
  1474. {
  1475. $numref = $object->ref;
  1476. }
  1477. $text = $langs->trans("ConfirmValidateSending",$numref);
  1478. if (! empty($conf->notification->enabled))
  1479. {
  1480. require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
  1481. $notify=new Notify($db);
  1482. $text.='<br>';
  1483. $text.=$notify->confirmMessage('SHIPPING_VALIDATE',$object->socid, $object);
  1484. }
  1485. $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$text,'confirm_valid','',0,1);
  1486. }
  1487. // Confirm cancelation
  1488. if ($action == 'annuler')
  1489. {
  1490. $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$object->ref),'confirm_cancel','',0,1);
  1491. }
  1492. // Call Hook formConfirm
  1493. $parameters = array();
  1494. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1495. if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
  1496. elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
  1497. // Print form confirm
  1498. print $formconfirm;
  1499. // Calculate totalWeight and totalVolume for all products
  1500. // by adding weight and volume of each product line.
  1501. $tmparray=$object->getTotalWeightVolume();
  1502. $totalWeight=$tmparray['weight'];
  1503. $totalVolume=$tmparray['volume'];
  1504. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  1505. {
  1506. $objectsrc=new Commande($db);
  1507. $objectsrc->fetch($object->$typeobject->id);
  1508. }
  1509. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  1510. {
  1511. $objectsrc=new Propal($db);
  1512. $objectsrc->fetch($object->$typeobject->id);
  1513. }
  1514. // Shipment card
  1515. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
  1516. $morehtmlref='<div class="refidno">';
  1517. // Ref customer shipment
  1518. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
  1519. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
  1520. // Thirdparty
  1521. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  1522. // Project
  1523. if (! empty($conf->projet->enabled)) {
  1524. $langs->load("projects");
  1525. $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
  1526. if (0) { // Do not change on shipment
  1527. if ($action != 'classify') {
  1528. $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  1529. }
  1530. if ($action == 'classify') {
  1531. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  1532. $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
  1533. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  1534. $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  1535. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  1536. $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
  1537. $morehtmlref .= '</form>';
  1538. } else {
  1539. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  1540. }
  1541. } else {
  1542. // We don't have project on shipment, so we will use the project or source object instead
  1543. // TODO Add project on shipment
  1544. $morehtmlref .= ' : ';
  1545. if (! empty($objectsrc->fk_project)) {
  1546. $proj = new Project($db);
  1547. $proj->fetch($objectsrc->fk_project);
  1548. $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
  1549. $morehtmlref .= $proj->ref;
  1550. $morehtmlref .= '</a>';
  1551. } else {
  1552. $morehtmlref .= '';
  1553. }
  1554. }
  1555. }
  1556. $morehtmlref.='</div>';
  1557. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  1558. print '<div class="fichecenter">';
  1559. print '<div class="fichehalfleft">';
  1560. print '<div class="underbanner clearboth"></div>';
  1561. print '<table class="border tableforfield" width="100%">';
  1562. // Linked documents
  1563. if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
  1564. {
  1565. print '<tr><td>';
  1566. print $langs->trans("RefOrder").'</td>';
  1567. print '<td colspan="3">';
  1568. print $objectsrc->getNomUrl(1,'commande');
  1569. print "</td>\n";
  1570. print '</tr>';
  1571. }
  1572. if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
  1573. {
  1574. print '<tr><td>';
  1575. print $langs->trans("RefProposal").'</td>';
  1576. print '<td colspan="3">';
  1577. print $objectsrc->getNomUrl(1,'expedition');
  1578. print "</td>\n";
  1579. print '</tr>';
  1580. }
  1581. // Date creation
  1582. print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
  1583. print '<td colspan="3">'.dol_print_date($object->date_creation,"dayhour")."</td>\n";
  1584. print '</tr>';
  1585. // Delivery date planned
  1586. print '<tr><td height="10">';
  1587. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1588. print $langs->trans('DateDeliveryPlanned');
  1589. print '</td>';
  1590. 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>';
  1591. print '</tr></table>';
  1592. print '</td><td colspan="2">';
  1593. if ($action == 'editdate_livraison')
  1594. {
  1595. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1596. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1597. print '<input type="hidden" name="action" value="setdate_livraison">';
  1598. print $form->selectDate($object->date_delivery?$object->date_delivery:-1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);
  1599. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1600. print '</form>';
  1601. }
  1602. else
  1603. {
  1604. print $object->date_delivery ? dol_print_date($object->date_delivery,'dayhour') : '&nbsp;';
  1605. }
  1606. print '</td>';
  1607. print '</tr>';
  1608. // Weight
  1609. print '<tr><td>';
  1610. print $form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer);
  1611. print '</td><td colspan="3">';
  1612. if ($action=='edittrueWeight')
  1613. {
  1614. print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1615. print '<input name="action" value="settrueWeight" type="hidden">';
  1616. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1617. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1618. print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
  1619. print $formproduct->select_measuring_units("weight_units","weight",$object->weight_units);
  1620. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1621. print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1622. print '</form>';
  1623. }
  1624. else
  1625. {
  1626. print $object->trueWeight;
  1627. print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):'';
  1628. }
  1629. // Calculated
  1630. if ($totalWeight > 0)
  1631. {
  1632. if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';
  1633. //print $totalWeight.' '.measuring_units_string(0,"weight");
  1634. 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');
  1635. //if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')';
  1636. if (!empty($object->trueWeight)) print ')';
  1637. }
  1638. print '</td></tr>';
  1639. // Width
  1640. print '<tr><td>'.$form->editfieldkey("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1641. print $form->editfieldval("Width",'trueWidth',$object->trueWidth,$object,$user->rights->expedition->creer);
  1642. print ($object->trueWidth && $object->width_units!='')?' '.measuring_units_string($object->width_units,"size"):'';
  1643. print '</td></tr>';
  1644. // Height
  1645. print '<tr><td>'.$form->editfieldkey("Height",'trueHeight',$object->trueHeight,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1646. if($action=='edittrueHeight')
  1647. {
  1648. print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1649. print '<input name="action" value="settrueHeight" type="hidden">';
  1650. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1651. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1652. print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
  1653. print $formproduct->select_measuring_units("size_units","size",$object->size_units);
  1654. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1655. print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1656. print '</form>';
  1657. }
  1658. else
  1659. {
  1660. print $object->trueHeight;
  1661. print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):'';
  1662. }
  1663. print '</td></tr>';
  1664. // Depth
  1665. print '<tr><td>'.$form->editfieldkey("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1666. print $form->editfieldval("Depth",'trueDepth',$object->trueDepth,$object,$user->rights->expedition->creer);
  1667. print ($object->trueDepth && $object->depth_units!='')?' '.measuring_units_string($object->depth_units,"size"):'';
  1668. print '</td></tr>';
  1669. // Volume
  1670. print '<tr><td>';
  1671. print $langs->trans("Volume");
  1672. print '</td>';
  1673. print '<td colspan="3">';
  1674. $calculatedVolume=0;
  1675. $volumeUnit=0;
  1676. if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
  1677. {
  1678. $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
  1679. $volumeUnit=$object->size_units * 3;
  1680. }
  1681. // If sending volume not defined we use sum of products
  1682. if ($calculatedVolume > 0)
  1683. {
  1684. if ($volumeUnit < 50)
  1685. {
  1686. //print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
  1687. 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');
  1688. }
  1689. else print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume");
  1690. }
  1691. if ($totalVolume > 0)
  1692. {
  1693. if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';
  1694. //print $totalVolume.' '.measuring_units_string(0,"volume");
  1695. 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');
  1696. //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
  1697. if ($calculatedVolume) print ')';
  1698. }
  1699. print "</td>\n";
  1700. print '</tr>';
  1701. // Other attributes
  1702. $cols = 2;
  1703. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  1704. print '</table>';
  1705. print '</div>';
  1706. print '<div class="fichehalfright">';
  1707. print '<div class="ficheaddleft">';
  1708. print '<div class="underbanner clearboth"></div>';
  1709. print '<table class="border centpercent">';
  1710. // Sending method
  1711. print '<tr><td height="10">';
  1712. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1713. print $langs->trans('SendingMethod');
  1714. print '</td>';
  1715. 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>';
  1716. print '</tr></table>';
  1717. print '</td><td colspan="2">';
  1718. if ($action == 'editshipping_method_id')
  1719. {
  1720. print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1721. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1722. print '<input type="hidden" name="action" value="setshipping_method_id">';
  1723. $object->fetch_delivery_methods();
  1724. print $form->selectarray("shipping_method_id",$object->meths,$object->shipping_method_id,1,0,0,"",1);
  1725. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  1726. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1727. print '</form>';
  1728. }
  1729. else
  1730. {
  1731. if ($object->shipping_method_id > 0)
  1732. {
  1733. // Get code using getLabelFromKey
  1734. $code=$langs->getLabelFromKey($db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
  1735. print $langs->trans("SendingMethod".strtoupper($code));
  1736. }
  1737. }
  1738. print '</td>';
  1739. print '</tr>';
  1740. // Tracking Number
  1741. print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber",'tracking_number',$object->tracking_number,$object,$user->rights->expedition->creer).'</td><td colspan="3">';
  1742. print $form->editfieldval("TrackingNumber",'tracking_number',$object->tracking_url,$object,$user->rights->expedition->creer,'string',$object->tracking_number);
  1743. print '</td></tr>';
  1744. // Incoterms
  1745. if (!empty($conf->incoterm->enabled))
  1746. {
  1747. print '<tr><td>';
  1748. print '<table width="100%" class="nobordernopadding"><tr><td>';
  1749. print $langs->trans('IncotermLabel');
  1750. print '<td><td align="right">';
  1751. if ($user->rights->expedition->creer) print '<a href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
  1752. else print '&nbsp;';
  1753. print '</td></tr></table>';
  1754. print '</td>';
  1755. print '<td colspan="3">';
  1756. if ($action != 'editincoterm')
  1757. {
  1758. print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1);
  1759. }
  1760. else
  1761. {
  1762. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id);
  1763. }
  1764. print '</td></tr>';
  1765. }
  1766. print "</table>";
  1767. print '</div>';
  1768. print '</div>';
  1769. print '</div>';
  1770. print '<div class="clearboth"></div>';
  1771. // Lines of products
  1772. if ($action == 'editline')
  1773. {
  1774. print ' <form name="updateline" id="updateline" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;lineid=' . $line_id . '" method="POST">
  1775. <input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
  1776. <input type="hidden" name="action" value="updateline">
  1777. <input type="hidden" name="mode" value="">
  1778. <input type="hidden" name="id" value="' . $object->id . '">
  1779. ';
  1780. }
  1781. print '<br>';
  1782. print '<div class="div-table-responsive-no-min">';
  1783. print '<table class="noborder" width="100%">';
  1784. print '<tr class="liste_titre">';
  1785. // Adds a line numbering column
  1786. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1787. {
  1788. print '<td width="5" align="center">&nbsp;</td>';
  1789. }
  1790. // Product/Service
  1791. print '<td>'.$langs->trans("Products").'</td>';
  1792. // Qty
  1793. print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
  1794. if ($origin && $origin_id > 0)
  1795. {
  1796. print '<td align="center">'.$langs->trans("QtyInOtherShipments").'</td>';
  1797. }
  1798. if ($action == 'editline')
  1799. {
  1800. $editColspan = 3;
  1801. if (empty($conf->stock->enabled)) $editColspan--;
  1802. if (empty($conf->productbatch->enabled)) $editColspan--;
  1803. print '<td align="center" colspan="'. $editColspan . '">';
  1804. if ($object->statut <= 1)
  1805. {
  1806. print $langs->trans("QtyToShip").' - ';
  1807. }
  1808. else
  1809. {
  1810. print $langs->trans("QtyShipped").' - ';
  1811. }
  1812. if (! empty($conf->stock->enabled))
  1813. {
  1814. print $langs->trans("WarehouseSource").' - ';
  1815. }
  1816. if (! empty($conf->productbatch->enabled))
  1817. {
  1818. print $langs->trans("Batch");
  1819. }
  1820. print '</td>';
  1821. }
  1822. else
  1823. {
  1824. if ($object->statut <= 1)
  1825. {
  1826. print '<td align="center">'.$langs->trans("QtyToShip").'</td>';
  1827. }
  1828. else
  1829. {
  1830. print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
  1831. }
  1832. if (! empty($conf->stock->enabled))
  1833. {
  1834. print '<td align="left">'.$langs->trans("WarehouseSource").'</td>';
  1835. }
  1836. if (! empty($conf->productbatch->enabled))
  1837. {
  1838. print '<td align="left">'.$langs->trans("Batch").'</td>';
  1839. }
  1840. }
  1841. print '<td align="center">'.$langs->trans("CalculatedWeight").'</td>';
  1842. print '<td align="center">'.$langs->trans("CalculatedVolume").'</td>';
  1843. //print '<td align="center">'.$langs->trans("Size").'</td>';
  1844. if ($object->statut == 0)
  1845. {
  1846. print '<td class="linecoledit"></td>';
  1847. print '<td class="linecoldelete" width="10"></td>';
  1848. }
  1849. print "</tr>\n";
  1850. $var=false;
  1851. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1852. {
  1853. $object->fetch_thirdparty();
  1854. $outputlangs = $langs;
  1855. $newlang='';
  1856. if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
  1857. if (empty($newlang)) $newlang=$object->thirdparty->default_lang;
  1858. if (! empty($newlang))
  1859. {
  1860. $outputlangs = new Translate("",$conf);
  1861. $outputlangs->setDefaultLang($newlang);
  1862. }
  1863. }
  1864. // Get list of products already sent for same source object into $alreadysent
  1865. $alreadysent = array();
  1866. if ($origin && $origin_id > 0)
  1867. {
  1868. $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end";
  1869. $sql.= ", ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot";
  1870. $sql.= ", e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition";
  1871. //if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
  1872. $sql.= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';
  1873. $sql.= ', p.description as product_desc';
  1874. $sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
  1875. $sql.= ", ".MAIN_DB_PREFIX."expedition as e";
  1876. $sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj";
  1877. //if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line";
  1878. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
  1879. $sql.= " WHERE e.entity IN (".getEntity('expedition').")";
  1880. $sql.= " AND obj.fk_".$origin." = ".$origin_id;
  1881. $sql.= " AND obj.rowid = ed.fk_origin_line";
  1882. $sql.= " AND ed.fk_expedition = e.rowid";
  1883. //if ($filter) $sql.= $filter;
  1884. $sql.= " ORDER BY obj.fk_product";
  1885. dol_syslog("get list of shipment lines", LOG_DEBUG);
  1886. $resql = $db->query($sql);
  1887. if ($resql)
  1888. {
  1889. $num = $db->num_rows($resql);
  1890. $i = 0;
  1891. while($i < $num)
  1892. {
  1893. $obj = $db->fetch_object($resql);
  1894. if ($obj)
  1895. {
  1896. // $obj->rowid is rowid in $origin."det" table
  1897. $alreadysent[$obj->rowid][$obj->shipmentline_id]=array('shipment_ref'=>$obj->shipment_ref, 'shipment_id'=>$obj->shipment_id, 'warehouse'=>$obj->fk_entrepot, 'qty_shipped'=>$obj->qty_shipped, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery);
  1898. }
  1899. $i++;
  1900. }
  1901. }
  1902. //var_dump($alreadysent);
  1903. }
  1904. // Loop on each product to send/sent
  1905. for ($i = 0 ; $i < $num_prod ; $i++)
  1906. {
  1907. print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line
  1908. print '<tr class="oddeven">';
  1909. // Adds a line numbering column
  1910. if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
  1911. {
  1912. print '<td align="center">'.($i+1).'</td>';
  1913. }
  1914. // Predefined product or service
  1915. if ($lines[$i]->fk_product > 0)
  1916. {
  1917. // Define output language
  1918. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  1919. {
  1920. $prod = new Product($db);
  1921. $prod->fetch($lines[$i]->fk_product);
  1922. $label = ( ! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;
  1923. }
  1924. else
  1925. $label = (! empty($lines[$i]->label)?$lines[$i]->label:$lines[$i]->product_label);
  1926. print '<td>';
  1927. // Show product and description
  1928. $product_static->type=$lines[$i]->fk_product_type;
  1929. $product_static->id=$lines[$i]->fk_product;
  1930. $product_static->ref=$lines[$i]->ref;
  1931. $product_static->status_batch=$lines[$i]->product_tobatch;
  1932. $text=$product_static->getNomUrl(1);
  1933. $text.= ' - '.$label;
  1934. $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($lines[$i]->description));
  1935. print $form->textwithtooltip($text,$description,3,'','',$i);
  1936. print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
  1937. if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
  1938. {
  1939. print (! empty($lines[$i]->description) && $lines[$i]->description!=$lines[$i]->product)?'<br>'.dol_htmlentitiesbr($lines[$i]->description):'';
  1940. }
  1941. print "</td>\n";
  1942. }
  1943. else
  1944. {
  1945. print "<td>";
  1946. if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'),'service');
  1947. else $text = img_object($langs->trans('Product'),'product');
  1948. if (! empty($lines[$i]->label)) {
  1949. $text.= ' <strong>'.$lines[$i]->label.'</strong>';
  1950. print $form->textwithtooltip($text,$lines[$i]->description,3,'','',$i);
  1951. } else {
  1952. print $text.' '.nl2br($lines[$i]->description);
  1953. }
  1954. print_date_range($lines[$i]->date_start,$lines[$i]->date_end);
  1955. print "</td>\n";
  1956. }
  1957. // Qty ordered
  1958. print '<td align="center">'.$lines[$i]->qty_asked.'</td>';
  1959. // Qty in other shipments (with shipment and warehouse used)
  1960. if ($origin && $origin_id > 0)
  1961. {
  1962. print '<td align="center" class="nowrap">';
  1963. foreach ($alreadysent as $key => $val)
  1964. {
  1965. if ($lines[$i]->fk_origin_line == $key)
  1966. {
  1967. $j = 0;
  1968. foreach($val as $shipmentline_id=> $shipmentline_var)
  1969. {
  1970. if ($shipmentline_var['shipment_id'] == $lines[$i]->fk_expedition) continue; // We want to show only "other shipments"
  1971. $j++;
  1972. if ($j > 1) print '<br>';
  1973. $shipment_static->fetch($shipmentline_var['shipment_id']);
  1974. print $shipment_static->getNomUrl(1);
  1975. print ' - '.$shipmentline_var['qty_shipped'];
  1976. $htmltext=$langs->trans("DateValidation").' : '.(empty($shipmentline_var['date_valid'])?$langs->trans("Draft"):dol_print_date($shipmentline_var['date_valid'], 'dayhour'));
  1977. if (! empty($conf->stock->enabled) && $shipmentline_var['warehouse'] > 0)
  1978. {
  1979. $warehousestatic->fetch($shipmentline_var['warehouse']);
  1980. $htmltext .= '<br>'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1);
  1981. }
  1982. print ' '.$form->textwithpicto('', $htmltext, 1);
  1983. }
  1984. }
  1985. }
  1986. }
  1987. print '</td>';
  1988. if ($action == 'editline' && $lines[$i]->id == $line_id)
  1989. {
  1990. // edit mode
  1991. print '<td colspan="'.$editColspan.'" align="center"><table class="nobordernopadding">';
  1992. if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0)
  1993. {
  1994. print '<!-- case edit 1 -->';
  1995. $line = new ExpeditionLigne($db);
  1996. foreach ($lines[$i]->detail_batch as $detail_batch)
  1997. {
  1998. print '<tr>';
  1999. // Qty to ship or shipped
  2000. print '<td>' . '<input name="qtyl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->id.'" id="qtyl'.$line_id.'_'.$detail_batch->id.'" type="text" size="4" value="'.$detail_batch->qty.'">' . '</td>';
  2001. // Batch number managment
  2002. if ($lines[$i]->entrepot_id == 0)
  2003. {
  2004. // only show lot numbers from src warehouse when shipping from multiple warehouses
  2005. $line->fetch($detail_batch->fk_expeditiondet);
  2006. }
  2007. print '<td>' . $formproduct->selectLotStock($detail_batch->fk_origin_stock, 'batchl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->fk_origin_stock, '', 1, 0, $lines[$i]->fk_product, $line->entrepot_id). '</td>';
  2008. print '</tr>';
  2009. }
  2010. // add a 0 qty lot row to be able to add a lot
  2011. print '<tr>';
  2012. // Qty to ship or shipped
  2013. print '<td>' . '<input name="qtyl'.$line_id.'_0" id="qtyl'.$line_id.'_0" type="text" size="4" value="0">' . '</td>';
  2014. // Batch number managment
  2015. print '<td>' . $formproduct->selectLotStock('', 'batchl'.$line_id.'_0', '', 1, 0, $lines[$i]->fk_product). '</td>';
  2016. print '</tr>';
  2017. }
  2018. else if (! empty($conf->stock->enabled))
  2019. {
  2020. if ($lines[$i]->fk_product > 0)
  2021. {
  2022. if ($lines[$i]->entrepot_id > 0)
  2023. {
  2024. print '<!-- case edit 2 -->';
  2025. print '<tr>';
  2026. // Qty to ship or shipped
  2027. print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'">' . '</td>';
  2028. // Warehouse source
  2029. print '<td>' . $formproduct->selectWarehouses($lines[$i]->entrepot_id, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1). '</td>';
  2030. // Batch number managment
  2031. print '<td> - ' . $langs->trans("NA") . '</td>';
  2032. print '</tr>';
  2033. }
  2034. else if (count($lines[$i]->details_entrepot) > 1)
  2035. {
  2036. print '<!-- case edit 3 -->';
  2037. foreach ($lines[$i]->details_entrepot as $detail_entrepot)
  2038. {
  2039. print '<tr>';
  2040. // Qty to ship or shipped
  2041. print '<td>' . '<input name="qtyl'.$detail_entrepot->line_id.'" id="qtyl'.$detail_entrepot->line_id.'" type="text" size="4" value="'.$detail_entrepot->qty_shipped.'">' . '</td>';
  2042. // Warehouse source
  2043. print '<td>' . $formproduct->selectWarehouses($detail_entrepot->entrepot_id, 'entl'.$detail_entrepot->line_id, '', 1, 0, $lines[$i]->fk_product, '', 1) . '</td>';
  2044. // Batch number managment
  2045. print '<td> - ' . $langs->trans("NA") . '</td>';
  2046. print '</tr>';
  2047. }
  2048. }
  2049. else
  2050. {
  2051. print '<!-- case edit 4 -->';
  2052. print '<tr><td colspan="3">'.$langs->trans("NotEnoughStock").'</td></tr>';
  2053. }
  2054. }
  2055. else
  2056. {
  2057. print '<!-- case edit 5 -->';
  2058. print '<tr>';
  2059. // Qty to ship or shipped
  2060. print '<td>' . '<input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'">' . '</td>';
  2061. // Warehouse source
  2062. print '<td>' . '</td>';
  2063. // Batch number managment
  2064. print '<td>' . '</td>';
  2065. print '</tr>';
  2066. }
  2067. }
  2068. print '</table></td>';
  2069. }
  2070. else
  2071. {
  2072. // Qty to ship or shipped
  2073. print '<td align="center">'.$lines[$i]->qty_shipped.'</td>';
  2074. // Warehouse source
  2075. if (! empty($conf->stock->enabled))
  2076. {
  2077. print '<td align="left">';
  2078. if ($lines[$i]->entrepot_id > 0)
  2079. {
  2080. $entrepot = new Entrepot($db);
  2081. $entrepot->fetch($lines[$i]->entrepot_id);
  2082. print $entrepot->getNomUrl(1);
  2083. }
  2084. else if (count($lines[$i]->details_entrepot) > 1)
  2085. {
  2086. $detail = '';
  2087. foreach ($lines[$i]->details_entrepot as $detail_entrepot)
  2088. {
  2089. if ($detail_entrepot->entrepot_id > 0)
  2090. {
  2091. $entrepot = new Entrepot($db);
  2092. $entrepot->fetch($detail_entrepot->entrepot_id);
  2093. $detail.= $langs->trans("DetailWarehouseFormat",$entrepot->libelle,$detail_entrepot->qty_shipped).'<br/>';
  2094. }
  2095. }
  2096. print $form->textwithtooltip(img_picto('', 'object_stock').' '.$langs->trans("DetailWarehouseNumber"),$detail);
  2097. }
  2098. print '</td>';
  2099. }
  2100. // Batch number managment
  2101. if (! empty($conf->productbatch->enabled))
  2102. {
  2103. if (isset($lines[$i]->detail_batch))
  2104. {
  2105. print '<!-- Detail of lot -->';
  2106. print '<td>';
  2107. if ($lines[$i]->product_tobatch)
  2108. {
  2109. $detail = '';
  2110. foreach ($lines[$i]->detail_batch as $dbatch) // $dbatch is instance of ExpeditionLineBatch
  2111. {
  2112. $detail.= $langs->trans("Batch").': '.$dbatch->batch;
  2113. $detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
  2114. $detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
  2115. $detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
  2116. $detail.= '<br>';
  2117. }
  2118. print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
  2119. }
  2120. else
  2121. {
  2122. print $langs->trans("NA");
  2123. }
  2124. print '</td>';
  2125. } else {
  2126. print '<td></td>';
  2127. }
  2128. }
  2129. }
  2130. // Weight
  2131. print '<td align="center">';
  2132. if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->weight*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->weight_units,"weight");
  2133. else print '&nbsp;';
  2134. print '</td>';
  2135. // Volume
  2136. print '<td align="center">';
  2137. if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume");
  2138. else print '&nbsp;';
  2139. print '</td>';
  2140. // Size
  2141. //print '<td align="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume").'</td>';
  2142. if ($action == 'editline' && $lines[$i]->id == $line_id)
  2143. {
  2144. print '<td align="center" colspan="2" valign="middle">';
  2145. print '<input type="submit" class="button" id="savelinebutton" name="save" value="' . $langs->trans("Save") . '"><br>';
  2146. print '<input type="submit" class="button" id="cancellinebutton" name="cancel" value="' . $langs->trans("Cancel") . '"><br>';
  2147. }
  2148. else if ($object->statut == 0)
  2149. {
  2150. // edit-delete buttons
  2151. print '<td class="linecoledit" align="center">';
  2152. print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=editline&amp;lineid=' . $lines[$i]->id . '">' . img_edit() . '</a>';
  2153. print '</td>';
  2154. print '<td class="linecoldelete" width="10">';
  2155. print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=deleteline&amp;lineid=' . $lines[$i]->id . '">' . img_delete() . '</a>';
  2156. print '</td>';
  2157. // Display lines extrafields
  2158. if (! empty($rowExtrafieldsStart))
  2159. {
  2160. print $rowExtrafieldsStart;
  2161. print $rowExtrafieldsView;
  2162. print $rowEnd;
  2163. }
  2164. }
  2165. print "</tr>";
  2166. // Display lines extrafields
  2167. if (is_array($extralabelslines) && count($extralabelslines)>0) {
  2168. $colspan= empty($conf->productbatch->enabled) ? 5 : 6;
  2169. $line = new ExpeditionLigne($db);
  2170. $line->fetch_optionals($lines[$i]->id);
  2171. print '<tr class="oddeven">';
  2172. if ($action == 'editline' && $lines[$i]->id == $line_id)
  2173. {
  2174. print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
  2175. }
  2176. else
  2177. {
  2178. print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked);
  2179. }
  2180. print '</tr>';
  2181. }
  2182. }
  2183. // TODO Show also lines ordered but not delivered
  2184. print "</table>\n";
  2185. print '</div>';
  2186. }
  2187. dol_fiche_end();
  2188. $object->fetchObjectLinked($object->id,$object->element);
  2189. /*
  2190. * Boutons actions
  2191. */
  2192. if (($user->societe_id == 0) && ($action!='presend'))
  2193. {
  2194. print '<div class="tabsAction">';
  2195. $parameters = array();
  2196. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  2197. // modified by hook
  2198. if (empty($reshook))
  2199. {
  2200. if ($object->statut == Expedition::STATUS_DRAFT && $num_prod > 0)
  2201. {
  2202. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer))
  2203. || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate)))
  2204. {
  2205. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
  2206. }
  2207. else
  2208. {
  2209. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
  2210. }
  2211. }
  2212. // TODO add alternative status
  2213. // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
  2214. if ($object->statut == Expedition::STATUS_CLOSED && $user->rights->expedition->creer)
  2215. {
  2216. if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
  2217. {
  2218. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ClassifyUnbilled").'</a>';
  2219. }
  2220. else
  2221. {
  2222. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
  2223. }
  2224. }
  2225. // Send
  2226. if ($object->statut > 0)
  2227. {
  2228. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send)
  2229. {
  2230. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>';
  2231. }
  2232. else print '<a class="butActionRefused" href="#">'.$langs->trans('SendMail').'</a>';
  2233. }
  2234. // Create bill
  2235. if (! empty($conf->facture->enabled) && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED))
  2236. {
  2237. if ($user->rights->facture->creer)
  2238. {
  2239. // TODO show button only if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))
  2240. // If we do that, we must also make this option official.
  2241. print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
  2242. }
  2243. }
  2244. // This is just to generate a delivery receipt
  2245. //var_dump($object->linkedObjectsIds['delivery']);
  2246. if ($conf->livraison_bon->enabled && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED) && $user->rights->expedition->livraison->creer && count($object->linkedObjectsIds['delivery']) == 0)
  2247. {
  2248. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=create_delivery">'.$langs->trans("CreateDeliveryOrder").'</a>';
  2249. }
  2250. // Close
  2251. if ($object->statut == Expedition::STATUS_VALIDATED)
  2252. {
  2253. if ($user->rights->expedition->creer && $object->statut > 0 && ! $object->billed)
  2254. {
  2255. $label="Close"; $paramaction='classifyclosed'; // = Transferred/Received
  2256. // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders
  2257. if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?
  2258. {
  2259. $label="ClassifyBilled";
  2260. $paramaction='classifybilled';
  2261. }
  2262. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$paramaction.'">'.$langs->trans($label).'</a>';
  2263. }
  2264. }
  2265. if ($user->rights->expedition->supprimer)
  2266. {
  2267. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
  2268. }
  2269. }
  2270. print '</div>';
  2271. }
  2272. /*
  2273. * Documents generated
  2274. */
  2275. if ($action != 'presend' && $action != 'editline')
  2276. {
  2277. print '<div class="fichecenter"><div class="fichehalfleft">';
  2278. $objectref = dol_sanitizeFileName($object->ref);
  2279. $filedir = $conf->expedition->dir_output . "/sending/" .$objectref;
  2280. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  2281. $genallowed=$user->rights->expedition->lire;
  2282. $delallowed=$user->rights->expedition->creer;
  2283. print $formfile->showdocuments('expedition',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
  2284. // Show links to link elements
  2285. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
  2286. $somethingshown = $form->showLinkedObjectBlock($object, '');
  2287. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  2288. // List of actions on element
  2289. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  2290. $formactions=new FormActions($db);
  2291. $somethingshown = $formactions->showactions($object,'shipping',$socid,1);
  2292. print '</div></div></div>';
  2293. }
  2294. /*
  2295. * Action presend
  2296. */
  2297. //Select mail models is same action as presend
  2298. if (GETPOST('modelselected')) {
  2299. $action = 'presend';
  2300. }
  2301. // Presend form
  2302. $modelmail='shipping_send';
  2303. $defaulttopic='SendShippingRef';
  2304. $diroutput = $conf->expedition->dir_output. '/sending';
  2305. $trackid = 'shi'.$object->id;
  2306. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  2307. }
  2308. // End of page
  2309. llxFooter();
  2310. $db->close();