card.php 107 KB

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