card.php 98 KB

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