card.php 104 KB

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