card.php 115 KB

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