card.php 104 KB

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