card.php 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621
  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. $line->fk_expedition = $object->id;
  495. $num_prod = count($lines);
  496. for ($i = 0; $i < $num_prod; $i++) {
  497. if ($lines[$i]->id == $line_id) {
  498. if (count($lines[$i]->details_entrepot) > 1) {
  499. // delete multi warehouse lines
  500. foreach ($lines[$i]->details_entrepot as $details_entrepot) {
  501. $line->id = $details_entrepot->line_id;
  502. if (!$error && $line->delete($user) < 0) {
  503. $error++;
  504. }
  505. }
  506. } else {
  507. // delete single warehouse line
  508. $line->id = $line_id;
  509. if (!$error && $line->delete($user) < 0) {
  510. $error++;
  511. }
  512. }
  513. }
  514. unset($_POST["lineid"]);
  515. }
  516. if (!$error) {
  517. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  518. exit();
  519. } else {
  520. setEventMessages($line->error, $line->errors, 'errors');
  521. }
  522. } elseif ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('save')) {
  523. // Update a line
  524. // Clean parameters
  525. $qty = 0;
  526. $entrepot_id = 0;
  527. $batch_id = 0;
  528. $lines = $object->lines;
  529. $num_prod = count($lines);
  530. for ($i = 0; $i < $num_prod; $i++) {
  531. if ($lines[$i]->id == $line_id) { // we have found line to update
  532. $line = new ExpeditionLigne($db);
  533. $line->fk_expedition = $object->id;
  534. // Extrafields Lines
  535. $line->array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
  536. // Unset extrafield POST Data
  537. if (is_array($extrafields->attributes[$object->table_element_line]['label'])) {
  538. foreach ($extrafields->attributes[$object->table_element_line]['label'] as $key => $value) {
  539. unset($_POST["options_".$key]);
  540. }
  541. }
  542. $line->fk_product = $lines[$i]->fk_product;
  543. if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) {
  544. // line with lot
  545. foreach ($lines[$i]->detail_batch as $detail_batch) {
  546. $lotStock = new Productbatch($db);
  547. $batch = "batchl".$detail_batch->fk_expeditiondet."_".$detail_batch->fk_origin_stock;
  548. $qty = "qtyl".$detail_batch->fk_expeditiondet.'_'.$detail_batch->id;
  549. $batch_id = GETPOST($batch, 'int');
  550. $batch_qty = GETPOST($qty, 'int');
  551. if (!empty($batch_id) && ($batch_id != $detail_batch->fk_origin_stock || $batch_qty != $detail_batch->qty)) {
  552. if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0) { // $line is ExpeditionLine
  553. if ($lines[$i]->entrepot_id != 0) {
  554. // allow update line entrepot_id if not multi warehouse shipping
  555. $line->entrepot_id = $lotStock->warehouseid;
  556. }
  557. // detail_batch can be an object with keys, or an array of ExpeditionLineBatch
  558. if (empty($line->detail_batch)) {
  559. $line->detail_batch = new stdClass();
  560. }
  561. $line->detail_batch->fk_origin_stock = $batch_id;
  562. $line->detail_batch->batch = $lotStock->batch;
  563. $line->detail_batch->id = $detail_batch->id;
  564. $line->detail_batch->entrepot_id = $lotStock->warehouseid;
  565. $line->detail_batch->qty = $batch_qty;
  566. if ($line->update($user) < 0) {
  567. setEventMessages($line->error, $line->errors, 'errors');
  568. $error++;
  569. }
  570. } else {
  571. setEventMessages($lotStock->error, $lotStock->errors, 'errors');
  572. $error++;
  573. }
  574. }
  575. unset($_POST[$batch]);
  576. unset($_POST[$qty]);
  577. }
  578. // add new batch
  579. $lotStock = new Productbatch($db);
  580. $batch = "batchl".$line_id."_0";
  581. $qty = "qtyl".$line_id."_0";
  582. $batch_id = GETPOST($batch, 'int');
  583. $batch_qty = GETPOST($qty, 'int');
  584. $lineIdToAddLot = 0;
  585. if ($batch_qty > 0 && !empty($batch_id)) {
  586. if ($lotStock->fetch($batch_id) > 0) {
  587. // check if lotStock warehouse id is same as line warehouse id
  588. if ($lines[$i]->entrepot_id > 0) {
  589. // single warehouse shipment line
  590. if ($lines[$i]->entrepot_id == $lotStock->warehouseid) {
  591. $lineIdToAddLot = $line_id;
  592. }
  593. } elseif (count($lines[$i]->details_entrepot) > 1) {
  594. // multi warehouse shipment lines
  595. foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
  596. if ($detail_entrepot->entrepot_id == $lotStock->warehouseid) {
  597. $lineIdToAddLot = $detail_entrepot->line_id;
  598. }
  599. }
  600. }
  601. if ($lineIdToAddLot) {
  602. // add lot to existing line
  603. if ($line->fetch($lineIdToAddLot) > 0) {
  604. $line->detail_batch->fk_origin_stock = $batch_id;
  605. $line->detail_batch->batch = $lotStock->batch;
  606. $line->detail_batch->entrepot_id = $lotStock->warehouseid;
  607. $line->detail_batch->qty = $batch_qty;
  608. if ($line->update($user) < 0) {
  609. setEventMessages($line->error, $line->errors, 'errors');
  610. $error++;
  611. }
  612. } else {
  613. setEventMessages($line->error, $line->errors, 'errors');
  614. $error++;
  615. }
  616. } else {
  617. // create new line with new lot
  618. $line->origin_line_id = $lines[$i]->origin_line_id;
  619. $line->entrepot_id = $lotStock->warehouseid;
  620. $line->detail_batch[0] = new ExpeditionLineBatch($db);
  621. $line->detail_batch[0]->fk_origin_stock = $batch_id;
  622. $line->detail_batch[0]->batch = $lotStock->batch;
  623. $line->detail_batch[0]->entrepot_id = $lotStock->warehouseid;
  624. $line->detail_batch[0]->qty = $batch_qty;
  625. if ($object->create_line_batch($line, $line->array_options) < 0) {
  626. setEventMessages($object->error, $object->errors, 'errors');
  627. $error++;
  628. }
  629. }
  630. } else {
  631. setEventMessages($lotStock->error, $lotStock->errors, 'errors');
  632. $error++;
  633. }
  634. }
  635. } else {
  636. if ($lines[$i]->fk_product > 0) {
  637. // line without lot
  638. if ($lines[$i]->entrepot_id > 0) {
  639. // single warehouse shipment line
  640. $stockLocation = "entl".$line_id;
  641. $qty = "qtyl".$line_id;
  642. $line->id = $line_id;
  643. $line->entrepot_id = GETPOST($stockLocation, 'int');
  644. $line->qty = GETPOST($qty, 'int');
  645. if ($line->update($user) < 0) {
  646. setEventMessages($line->error, $line->errors, 'errors');
  647. $error++;
  648. }
  649. unset($_POST[$stockLocation]);
  650. unset($_POST[$qty]);
  651. } elseif (count($lines[$i]->details_entrepot) > 1) {
  652. // multi warehouse shipment lines
  653. foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
  654. if (!$error) {
  655. $stockLocation = "entl".$detail_entrepot->line_id;
  656. $qty = "qtyl".$detail_entrepot->line_id;
  657. $warehouse = GETPOST($stockLocation, 'int');
  658. if (!empty($warehouse)) {
  659. $line->id = $detail_entrepot->line_id;
  660. $line->entrepot_id = $warehouse;
  661. $line->qty = GETPOST($qty, 'int');
  662. if ($line->update($user) < 0) {
  663. setEventMessages($line->error, $line->errors, 'errors');
  664. $error++;
  665. }
  666. }
  667. unset($_POST[$stockLocation]);
  668. unset($_POST[$qty]);
  669. }
  670. }
  671. } elseif (empty($conf->stock->enabled) && empty($conf->productbatch->enabled)) { // both product batch and stock are not activated.
  672. $qty = "qtyl".$line_id;
  673. $line->id = $line_id;
  674. $line->qty = GETPOST($qty, 'int');
  675. $line->entrepot_id = 0;
  676. if ($line->update($user) < 0) {
  677. setEventMessages($line->error, $line->errors, 'errors');
  678. $error++;
  679. }
  680. unset($_POST[$qty]);
  681. }
  682. } else {
  683. // Product no predefined
  684. $qty = "qtyl".$line_id;
  685. $line->id = $line_id;
  686. $line->qty = GETPOST($qty, 'int');
  687. $line->entrepot_id = 0;
  688. if ($line->update($user) < 0) {
  689. setEventMessages($line->error, $line->errors, 'errors');
  690. $error++;
  691. }
  692. unset($_POST[$qty]);
  693. }
  694. }
  695. }
  696. }
  697. unset($_POST["lineid"]);
  698. if (!$error) {
  699. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  700. // Define output language
  701. $outputlangs = $langs;
  702. $newlang = '';
  703. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  704. $newlang = GETPOST('lang_id', 'aZ09');
  705. }
  706. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  707. $newlang = $object->thirdparty->default_lang;
  708. }
  709. if (!empty($newlang)) {
  710. $outputlangs = new Translate("", $conf);
  711. $outputlangs->setDefaultLang($newlang);
  712. }
  713. $ret = $object->fetch($object->id); // Reload to get new records
  714. $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  715. }
  716. } else {
  717. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To redisplay the form being edited
  718. exit();
  719. }
  720. } elseif ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
  721. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To redisplay the form being edited
  722. exit();
  723. }
  724. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  725. // Actions to send emails
  726. if (empty($id)) {
  727. $id = $facid;
  728. }
  729. $triggersendname = 'SHIPPING_SENTBYMAIL';
  730. $paramname = 'id';
  731. $mode = 'emailfromshipment';
  732. $trackid = 'shi'.$object->id;
  733. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  734. }
  735. /*
  736. * View
  737. */
  738. $help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:M&oacute;dulo_Expediciones|DE:Modul_Lieferungen';
  739. llxHeader('', $langs->trans('Shipment'), 'Expedition', $help_url);
  740. if (empty($action)) {
  741. $action = 'view';
  742. }
  743. $form = new Form($db);
  744. $formfile = new FormFile($db);
  745. $formproduct = new FormProduct($db);
  746. if (!empty($conf->project->enabled)) {
  747. $formproject = new FormProjets($db);
  748. }
  749. $product_static = new Product($db);
  750. $shipment_static = new Expedition($db);
  751. $warehousestatic = new Entrepot($db);
  752. if ($action == 'create2') {
  753. print load_fiche_titre($langs->trans("CreateShipment"), '', 'dolly');
  754. print '<br>'.$langs->trans("ShipmentCreationIsDoneFromOrder");
  755. $action = ''; $id = ''; $ref = '';
  756. }
  757. // Mode creation.
  758. if ($action == 'create') {
  759. $expe = new Expedition($db);
  760. print load_fiche_titre($langs->trans("CreateShipment"), '', 'dolly');
  761. if (!$origin) {
  762. setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors');
  763. }
  764. if ($origin) {
  765. $classname = ucfirst($origin);
  766. $object = new $classname($db);
  767. if ($object->fetch($origin_id)) { // This include the fetch_lines
  768. $soc = new Societe($db);
  769. $soc->fetch($object->socid);
  770. $author = new User($db);
  771. $author->fetch($object->user_author_id);
  772. if (!empty($conf->stock->enabled)) {
  773. $entrepot = new Entrepot($db);
  774. }
  775. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  776. print '<input type="hidden" name="token" value="'.newToken().'">';
  777. print '<input type="hidden" name="action" value="add">';
  778. print '<input type="hidden" name="origin" value="'.$origin.'">';
  779. print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
  780. print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';
  781. if (GETPOST('entrepot_id', 'int')) {
  782. print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id', 'int').'">';
  783. }
  784. print dol_get_fiche_head('');
  785. print '<table class="border centpercent">';
  786. // Ref
  787. print '<tr><td class="titlefieldcreate fieldrequired">';
  788. if ($origin == 'commande' && !empty($conf->commande->enabled)) {
  789. print $langs->trans("RefOrder");
  790. }
  791. if ($origin == 'propal' && !empty($conf->propal->enabled)) {
  792. print $langs->trans("RefProposal");
  793. }
  794. print '</td><td colspan="3">';
  795. print $object->getNomUrl(1);
  796. print '</td>';
  797. print "</tr>\n";
  798. // Ref client
  799. print '<tr><td>';
  800. if ($origin == 'commande') {
  801. print $langs->trans('RefCustomerOrder');
  802. } elseif ($origin == 'propal') {
  803. print $langs->trans('RefCustomerOrder');
  804. } else {
  805. print $langs->trans('RefCustomer');
  806. }
  807. print '</td><td colspan="3">';
  808. print '<input type="text" name="ref_customer" value="'.$object->ref_client.'" />';
  809. print '</td>';
  810. print '</tr>';
  811. // Tiers
  812. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Company').'</td>';
  813. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  814. print '</tr>';
  815. // Project
  816. if (!empty($conf->project->enabled)) {
  817. $projectid = GETPOST('projectid', 'int') ?GETPOST('projectid', 'int') : 0;
  818. if (empty($projectid) && !empty($object->fk_project)) {
  819. $projectid = $object->fk_project;
  820. }
  821. if ($origin == 'project') {
  822. $projectid = ($originid ? $originid : 0);
  823. }
  824. $langs->load("projects");
  825. print '<tr>';
  826. print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
  827. print img_picto('', 'project');
  828. $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0);
  829. 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>';
  830. print '</td>';
  831. print '</tr>';
  832. }
  833. // Date delivery planned
  834. print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
  835. print '<td colspan="3">';
  836. $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date); // $date_delivery comes from GETPOST
  837. print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
  838. print "</td>\n";
  839. print '</tr>';
  840. // Note Public
  841. print '<tr><td>'.$langs->trans("NotePublic").'</td>';
  842. print '<td colspan="3">';
  843. $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%');
  844. print $doleditor->Create(1);
  845. print "</td></tr>";
  846. // Note Private
  847. if ($object->note_private && !$user->socid) {
  848. print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
  849. print '<td colspan="3">';
  850. $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%');
  851. print $doleditor->Create(1);
  852. print "</td></tr>";
  853. }
  854. // Weight
  855. print '<tr><td>';
  856. print $langs->trans("Weight");
  857. print '</td><td colspan="3"><input name="weight" size="4" value="'.GETPOST('weight', 'int').'"> ';
  858. $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units', 'int'), 0, 2);
  859. $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
  860. print $form->textwithpicto($text, $htmltext);
  861. print '</td></tr>';
  862. // Dim
  863. print '<tr><td>';
  864. print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");
  865. print ' </td><td colspan="3"><input name="sizeW" size="4" value="'.GETPOST('sizeW', 'int').'">';
  866. print ' x <input name="sizeH" size="4" value="'.GETPOST('sizeH', 'int').'">';
  867. print ' x <input name="sizeS" size="4" value="'.GETPOST('sizeS', 'int').'">';
  868. print ' ';
  869. $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units', 'int'), 0, 2);
  870. $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
  871. print $form->textwithpicto($text, $htmltext);
  872. print '</td></tr>';
  873. // Delivery method
  874. print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";
  875. print '<td colspan="3">';
  876. $expe->fetch_delivery_methods();
  877. print $form->selectarray("shipping_method_id", $expe->meths, GETPOST('shipping_method_id', 'int'), 1, 0, 0, "", 1);
  878. if ($user->admin) {
  879. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  880. }
  881. print "</td></tr>\n";
  882. // Tracking number
  883. print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
  884. print '<td colspan="3">';
  885. print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';
  886. print "</td></tr>\n";
  887. // Other attributes
  888. $parameters = array('objectsrc' => isset($objectsrc) ? $objectsrc : '', 'colspan' => ' colspan="3"', 'cols' => '3', 'socid' => $socid);
  889. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $expe, $action); // Note that $action and $object may have been modified by hook
  890. print $hookmanager->resPrint;
  891. if (empty($reshook)) {
  892. // copy from order
  893. if ($object->fetch_optionals() > 0) {
  894. $expe->array_options = array_merge($expe->array_options, $object->array_options);
  895. }
  896. print $expe->showOptionals($extrafields, 'edit', $parameters);
  897. }
  898. // Incoterms
  899. if (!empty($conf->incoterm->enabled)) {
  900. print '<tr>';
  901. print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->label_incoterms, 1).'</label></td>';
  902. print '<td colspan="3" class="maxwidthonsmartphone">';
  903. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
  904. print '</td></tr>';
  905. }
  906. // Document model
  907. include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  908. $list = ModelePdfExpedition::liste_modeles($db);
  909. if (count($list) > 1) {
  910. print "<tr><td>".$langs->trans("DefaultModel")."</td>";
  911. print '<td colspan="3">';
  912. print $form->selectarray('model', $list, $conf->global->EXPEDITION_ADDON_PDF);
  913. print "</td></tr>\n";
  914. }
  915. print "</table>";
  916. print dol_get_fiche_end();
  917. // Shipment lines
  918. $numAsked = count($object->lines);
  919. print '<script type="text/javascript">'."\n";
  920. print 'jQuery(document).ready(function() {'."\n";
  921. print 'jQuery("#autofill").click(function() {';
  922. $i = 0;
  923. while ($i < $numAsked) {
  924. print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
  925. if (!empty($conf->productbatch->enabled)) {
  926. print 'jQuery("#qtyl'.$i.'_'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
  927. }
  928. $i++;
  929. }
  930. print 'return false; });'."\n";
  931. print 'jQuery("#autoreset").click(function() { console.log("Reset values to 0"); jQuery(".qtyl").val(0);'."\n";
  932. print 'return false; });'."\n";
  933. print '});'."\n";
  934. print '</script>'."\n";
  935. print '<br>';
  936. print '<table class="noborder centpercent">';
  937. // Load shipments already done for same order
  938. $object->loadExpeditions();
  939. $alreadyQtyBatchSetted = $alreadyQtySetted = array();
  940. if ($numAsked) {
  941. print '<tr class="liste_titre">';
  942. print '<td>'.$langs->trans("Description").'</td>';
  943. print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
  944. print '<td class="center">'.$langs->trans("QtyShipped").'</td>';
  945. print '<td class="center">'.$langs->trans("QtyToShip");
  946. if (empty($conf->productbatch->enabled)) {
  947. print '<br><a href="#" id="autofill" class="opacitymedium link cursor cursorpointer">'.img_picto($langs->trans("Autofill"), 'autofill', 'class="paddingrightonly"').'</a>';
  948. print ' / ';
  949. } else {
  950. print '<br>';
  951. }
  952. print '<span id="autoreset" class="opacitymedium link cursor cursorpointer">'.img_picto($langs->trans("Reset"), 'eraser').'</span>';
  953. print '</td>';
  954. if (!empty($conf->stock->enabled)) {
  955. if (empty($conf->productbatch->enabled)) {
  956. print '<td class="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
  957. } else {
  958. print '<td class="left">'.$langs->trans("Warehouse").' / '.$langs->trans("Batch").' ('.$langs->trans("Stock").')</td>';
  959. }
  960. }
  961. print "</tr>\n";
  962. }
  963. $warehouse_id = GETPOST('entrepot_id', 'int');
  964. $warehousePicking = array();
  965. // get all warehouse children for picking
  966. if ($warehouse_id > 0) {
  967. $warehousePicking[] = $warehouse_id;
  968. $warehouseObj = new Entrepot($db);
  969. $warehouseObj->get_children_warehouses($warehouse_id, $warehousePicking);
  970. }
  971. $indiceAsked = 0;
  972. while ($indiceAsked < $numAsked) {
  973. $product = new Product($db);
  974. $line = $object->lines[$indiceAsked];
  975. $parameters = array('i' => $indiceAsked, 'line' => $line, 'num' => $numAsked);
  976. $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);
  977. if ($reshook < 0) {
  978. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  979. }
  980. if (empty($reshook)) {
  981. // Show product and description
  982. $type = $line->product_type ? $line->product_type : $line->fk_product_type;
  983. // Try to enhance type detection using date_start and date_end for free lines where type
  984. // was not saved.
  985. if (!empty($line->date_start)) {
  986. $type = 1;
  987. }
  988. if (!empty($line->date_end)) {
  989. $type = 1;
  990. }
  991. print '<!-- line '.$line->id.' for product -->'."\n";
  992. print '<tr class="oddeven">'."\n";
  993. // Product label
  994. if ($line->fk_product > 0) { // If predefined product
  995. $product->fetch($line->fk_product);
  996. $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
  997. //var_dump($product->stock_warehouse[1]);
  998. print '<td>';
  999. print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
  1000. // Show product and description
  1001. $product_static->type = $line->fk_product_type;
  1002. $product_static->id = $line->fk_product;
  1003. $product_static->ref = $line->ref;
  1004. $product_static->status = $line->product_tosell;
  1005. $product_static->status_buy = $line->product_tobuy;
  1006. $product_static->status_batch = $line->product_tobatch;
  1007. $showdescinproductdesc = (getDolGlobalString('PRODUIT_DESC_IN_FORM') == 2 ? 1 : 0);
  1008. $text = $product_static->getNomUrl(1);
  1009. $text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label);
  1010. $description = ($showdescinproductdesc ? '' : dol_htmlentitiesbr($line->desc));
  1011. print $form->textwithtooltip($text, $description, 3, '', '', $i);
  1012. // Show range
  1013. print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
  1014. // Add description in form
  1015. if ($showdescinproductdesc) {
  1016. print ($line->desc && $line->desc != $line->product_label) ? '<br>'.dol_htmlentitiesbr($line->desc) : '';
  1017. }
  1018. print '</td>';
  1019. } else {
  1020. print "<td>";
  1021. if ($type == 1) {
  1022. $text = img_object($langs->trans('Service'), 'service');
  1023. } else {
  1024. $text = img_object($langs->trans('Product'), 'product');
  1025. }
  1026. if (!empty($line->label)) {
  1027. $text .= ' <strong>'.$line->label.'</strong>';
  1028. print $form->textwithtooltip($text, $line->desc, 3, '', '', $i);
  1029. } else {
  1030. print $text.' '.nl2br($line->desc);
  1031. }
  1032. // Show range
  1033. print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
  1034. print "</td>\n";
  1035. }
  1036. // unit of order
  1037. $unit_order = '';
  1038. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  1039. $unit_order = measuringUnitString($line->fk_unit);
  1040. }
  1041. // Qty
  1042. print '<td class="center">'.$line->qty;
  1043. print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
  1044. print ''.$unit_order.'</td>';
  1045. $qtyProdCom = $line->qty;
  1046. // Qty already shipped
  1047. print '<td class="center">';
  1048. $quantityDelivered = isset($object->expeditions[$line->id]) ? $object->expeditions[$line->id] : '';
  1049. print $quantityDelivered;
  1050. print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
  1051. print ''.$unit_order.'</td>';
  1052. // Qty to ship
  1053. $quantityAsked = $line->qty;
  1054. if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  1055. $quantityToBeDelivered = 0;
  1056. } else {
  1057. if (is_numeric($quantityDelivered)) {
  1058. $quantityToBeDelivered = $quantityAsked - $quantityDelivered;
  1059. } else {
  1060. $quantityToBeDelivered = $quantityAsked;
  1061. }
  1062. }
  1063. $warehouseObject = null;
  1064. 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
  1065. print '<!-- Case warehouse already known or product not a predefined product -->';
  1066. //ship from preselected location
  1067. $stock = + (isset($product->stock_warehouse[$warehouse_id]->real) ? $product->stock_warehouse[$warehouse_id]->real : 0); // Convert to number
  1068. $deliverableQty = min($quantityToBeDelivered, $stock);
  1069. if ($deliverableQty < 0) {
  1070. $deliverableQty = 0;
  1071. }
  1072. if (empty($conf->productbatch->enabled) || !$product->hasbatch()) {
  1073. // Quantity to send
  1074. print '<td class="center">';
  1075. if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  1076. if (GETPOST('qtyl'.$indiceAsked, 'int')) {
  1077. $deliverableQty = GETPOST('qtyl'.$indiceAsked, 'int');
  1078. }
  1079. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1080. print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" class="qtyl center" type="text" size="4" value="'.$deliverableQty.'">';
  1081. } else {
  1082. if (! empty($conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS)) {
  1083. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1084. print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="hidden" value="0">';
  1085. }
  1086. print $langs->trans("NA");
  1087. }
  1088. print '</td>';
  1089. // Stock
  1090. if (!empty($conf->stock->enabled)) {
  1091. print '<td class="left">';
  1092. if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { // Type of product need stock change ?
  1093. // Show warehouse combo list
  1094. $ent = "entl".$indiceAsked;
  1095. $idl = "idl".$indiceAsked;
  1096. $tmpentrepot_id = is_numeric(GETPOST($ent, 'int')) ?GETPOST($ent, 'int') : $warehouse_id;
  1097. if ($line->fk_product > 0) {
  1098. print '<!-- Show warehouse selection -->';
  1099. $stockMin = false;
  1100. if (empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) {
  1101. $stockMin = 0;
  1102. }
  1103. print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1, 0, array(), 'minwidth200', '', 1, $stockMin, 'stock DESC, e.ref');
  1104. if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id) {
  1105. //print $stock.' '.$quantityToBeDelivered;
  1106. if ($stock < $quantityToBeDelivered) {
  1107. print ' '.img_warning($langs->trans("StockTooLow")); // Stock too low for this $warehouse_id but you can change warehouse
  1108. }
  1109. }
  1110. }
  1111. } else {
  1112. print $langs->trans("Service");
  1113. }
  1114. print '</td>';
  1115. }
  1116. print "</tr>\n";
  1117. // Show subproducts of product
  1118. if (!empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0) {
  1119. $product->get_sousproduits_arbo();
  1120. $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
  1121. if (count($prods_arbo) > 0) {
  1122. foreach ($prods_arbo as $key => $value) {
  1123. //print $value[0];
  1124. $img = '';
  1125. if ($value['stock'] < $value['stock_alert']) {
  1126. $img = img_warning($langs->trans("StockTooLow"));
  1127. }
  1128. print "<tr class=\"oddeven\"><td>&nbsp; &nbsp; &nbsp; ->
  1129. <a href=\"".DOL_URL_ROOT."/product/card.php?id=".$value['id']."\">".$value['fullpath']."
  1130. </a> (".$value['nb'].")</td><td class=\"center\"> ".$value['nb_total']."</td><td>&nbsp;</td><td>&nbsp;</td>
  1131. <td class=\"center\">".$value['stock']." ".$img."</td></tr>";
  1132. }
  1133. }
  1134. }
  1135. } else {
  1136. // Product need lot
  1137. print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial
  1138. print '<!-- Case product need lot -->';
  1139. $staticwarehouse = new Entrepot($db);
  1140. if ($warehouse_id > 0) {
  1141. $staticwarehouse->fetch($warehouse_id);
  1142. }
  1143. $subj = 0;
  1144. // Define nb of lines suggested for this order line
  1145. $nbofsuggested = 0;
  1146. if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch)) {
  1147. foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) {
  1148. $nbofsuggested++;
  1149. }
  1150. }
  1151. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1152. if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch)) {
  1153. foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) { // $dbatch is instance of Productbatch
  1154. //var_dump($dbatch);
  1155. $batchStock = + $dbatch->qty; // To get a numeric
  1156. $deliverableQty = min($quantityToBeDelivered, $batchStock);
  1157. print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested) ? $bc[$var] : '').'>';
  1158. print '<td colspan="3" ></td><td class="center">';
  1159. print '<input class="qtyl" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';
  1160. print '</td>';
  1161. print '<!-- Show details of lot -->';
  1162. print '<td class="left">';
  1163. print $staticwarehouse->getNomUrl(0).' / ';
  1164. print '<input name="batchl'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$dbatch->id.'">';
  1165. $detail = '';
  1166. $detail .= $langs->trans("Batch").': '.$dbatch->batch;
  1167. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  1168. $detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day");
  1169. }
  1170. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  1171. $detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby, "day");
  1172. }
  1173. $detail .= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
  1174. $detail .= '<br>';
  1175. print $detail;
  1176. $quantityToBeDelivered -= $deliverableQty;
  1177. if ($quantityToBeDelivered < 0) {
  1178. $quantityToBeDelivered = 0;
  1179. }
  1180. $subj++;
  1181. print '</td></tr>';
  1182. }
  1183. } else {
  1184. print '<!-- Case there is no details of lot at all -->';
  1185. print '<tr class="oddeven"><td colspan="3"></td><td class="center">';
  1186. print '<input class="qtyl" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0" disabled="disabled"> ';
  1187. print '</td>';
  1188. print '<td class="left">';
  1189. print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $staticwarehouse->label);
  1190. print '</td></tr>';
  1191. }
  1192. }
  1193. } else {
  1194. // ship from multiple locations
  1195. if (empty($conf->productbatch->enabled) || !$product->hasbatch()) {
  1196. print '<!-- Case warehouse not already known and product does not need lot -->';
  1197. print '<td></td><td></td></tr>'."\n"; // end line and start a new one for each warehouse
  1198. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1199. $subj = 0;
  1200. // Define nb of lines suggested for this order line
  1201. $nbofsuggested = 0;
  1202. foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {
  1203. if ($stock_warehouse->real > 0) {
  1204. $nbofsuggested++;
  1205. }
  1206. }
  1207. $tmpwarehouseObject = new Entrepot($db);
  1208. foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) { // $stock_warehouse is product_stock
  1209. if (!empty($warehousePicking) && !in_array($warehouse_id, $warehousePicking)) {
  1210. // if a warehouse was selected by user, picking is limited to this warehouse and his children
  1211. continue;
  1212. }
  1213. $tmpwarehouseObject->fetch($warehouse_id);
  1214. if ($stock_warehouse->real > 0) {
  1215. $stock = + $stock_warehouse->real; // Convert it to number
  1216. $deliverableQty = min($quantityToBeDelivered, $stock);
  1217. $deliverableQty = max(0, $deliverableQty);
  1218. // Quantity to send
  1219. print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested) ? $bc[$var] : '').'>';
  1220. print '<td colspan="3" ></td><td class="center"><!-- qty to ship (no lot management for product line indiceAsked='.$indiceAsked.') -->';
  1221. if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  1222. if (isset($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) {
  1223. $deliverableQty = min($quantityToBeDelivered, $stock - $alreadyQtySetted[$line->fk_product][intval($warehouse_id)]);
  1224. } else {
  1225. if (!isset($alreadyQtySetted[$line->fk_product])) {
  1226. $alreadyQtySetted[$line->fk_product] = array();
  1227. }
  1228. $deliverableQty = min($quantityToBeDelivered, $stock);
  1229. }
  1230. if ($deliverableQty < 0) $deliverableQty = 0;
  1231. $tooltip = '';
  1232. if (!empty($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) {
  1233. $tooltip = ' class="classfortooltip" title="'.$langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines').' : '.$alreadyQtySetted[$line->fk_product][intval($warehouse_id)].'" ';
  1234. }
  1235. $alreadyQtySetted[$line->fk_product][intval($warehouse_id)] = $deliverableQty + $alreadyQtySetted[$line->fk_product][intval($warehouse_id)];
  1236. $inputName = 'qtyl'.$indiceAsked.'_'.$subj;
  1237. if (GETPOSTISSET($inputName)) {
  1238. $deliverableQty = GETPOST($inputName, 'int');
  1239. }
  1240. print '<input '.$tooltip.' name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
  1241. print '<input name="ent1'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$warehouse_id.'">';
  1242. } else {
  1243. if (! empty($conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS)) {
  1244. print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'" type="hidden" value="0">';
  1245. }
  1246. print $langs->trans("NA");
  1247. }
  1248. print '</td>';
  1249. // Stock
  1250. if (!empty($conf->stock->enabled)) {
  1251. print '<td class="left">';
  1252. if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  1253. print $tmpwarehouseObject->getNomUrl(0).' ';
  1254. print '<!-- Show details of stock -->';
  1255. print '('.$stock.')';
  1256. } else {
  1257. print $langs->trans("Service");
  1258. }
  1259. print '</td>';
  1260. }
  1261. $quantityToBeDelivered -= $deliverableQty;
  1262. if ($quantityToBeDelivered < 0) {
  1263. $quantityToBeDelivered = 0;
  1264. }
  1265. $subj++;
  1266. print "</tr>\n";
  1267. }
  1268. }
  1269. // Show subproducts of product (not recommanded)
  1270. if (!empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0) {
  1271. $product->get_sousproduits_arbo();
  1272. $prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
  1273. if (count($prods_arbo) > 0) {
  1274. foreach ($prods_arbo as $key => $value) {
  1275. //print $value[0];
  1276. $img = '';
  1277. if ($value['stock'] < $value['stock_alert']) {
  1278. $img = img_warning($langs->trans("StockTooLow"));
  1279. }
  1280. print '<tr class"oddeven"><td>';
  1281. print "&nbsp; &nbsp; &nbsp; ->
  1282. <a href=\"".DOL_URL_ROOT."/product/card.php?id=".$value['id']."\">".$value['fullpath']."
  1283. </a> (".$value['nb'].")</td><td class=\"center\"> ".$value['nb_total']."</td><td>&nbsp;</td><td>&nbsp;</td>
  1284. <td class=\"center\">".$value['stock']." ".$img."</td>";
  1285. print "</tr>";
  1286. }
  1287. }
  1288. }
  1289. } else {
  1290. print '<!-- Case warehouse not already known and product need lot -->';
  1291. print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial
  1292. $subj = 0;
  1293. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1294. $tmpwarehouseObject = new Entrepot($db);
  1295. $productlotObject = new Productlot($db);
  1296. // Define nb of lines suggested for this order line
  1297. $nbofsuggested = 0;
  1298. foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {
  1299. if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) {
  1300. $nbofsuggested+=count($stock_warehouse->detail_batch);
  1301. }
  1302. }
  1303. foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {
  1304. if (!empty($warehousePicking) && !in_array($warehouse_id, $warehousePicking)) {
  1305. // if a warehouse was selected by user, picking is limited to this warehouse and his children
  1306. continue;
  1307. }
  1308. $tmpwarehouseObject->fetch($warehouse_id);
  1309. if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) {
  1310. foreach ($stock_warehouse->detail_batch as $dbatch) {
  1311. $batchStock = + $dbatch->qty; // To get a numeric
  1312. if (isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {
  1313. $deliverableQty = min($quantityToBeDelivered, $batchStock - $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)]);
  1314. } else {
  1315. if (!isset($alreadyQtyBatchSetted[$line->fk_product])) {
  1316. $alreadyQtyBatchSetted[$line->fk_product] = array();
  1317. }
  1318. if (!isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch])) {
  1319. $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch] = array();
  1320. }
  1321. $deliverableQty = min($quantityToBeDelivered, $batchStock);
  1322. }
  1323. if ($deliverableQty < 0) $deliverableQty = 0;
  1324. $inputName = 'qtyl'.$indiceAsked.'_'.$subj;
  1325. if (GETPOSTISSET($inputName)) {
  1326. $deliverableQty = GETPOST($inputName, 'int');
  1327. }
  1328. $tooltipClass = $tooltipTitle = '';
  1329. if (!empty($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {
  1330. $tooltipClass = ' classfortooltip';
  1331. $tooltipTitle = $langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines').' : '.$alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];
  1332. }
  1333. $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)] = $deliverableQty + $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];
  1334. print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested) ? $bc[$var] : '').'><td colspan="3"></td><td class="center">';
  1335. print '<input class="qtyl '.$tooltipClass.'" title="'.$tooltipTitle.'" name="'.$inputName.'" id="'.$inputName.'" type="text" size="4" value="'.$deliverableQty.'">';
  1336. print '</td>';
  1337. print '<td class="left">';
  1338. print $tmpwarehouseObject->getNomUrl(0).' / ';
  1339. print '<!-- Show details of lot -->';
  1340. print '<input name="batchl'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$dbatch->id.'">';
  1341. //print '|'.$line->fk_product.'|'.$dbatch->batch.'|<br>';
  1342. print $langs->trans("Batch").': ';
  1343. $result = $productlotObject->fetch(0, $line->fk_product, $dbatch->batch);
  1344. if ($result > 0) {
  1345. print $productlotObject->getNomUrl(1);
  1346. } else {
  1347. print 'TableLotIncompleteRunRepairWithParamStandardEqualConfirmed';
  1348. }
  1349. print ' ('.$dbatch->qty.')';
  1350. $quantityToBeDelivered -= $deliverableQty;
  1351. if ($quantityToBeDelivered < 0) {
  1352. $quantityToBeDelivered = 0;
  1353. }
  1354. //dol_syslog('deliverableQty = '.$deliverableQty.' batchStock = '.$batchStock);
  1355. $subj++;
  1356. print '</td></tr>';
  1357. }
  1358. }
  1359. }
  1360. }
  1361. if ($subj == 0) { // Line not shown yet, we show it
  1362. $warehouse_selected_id = GETPOST('entrepot_id', 'int');
  1363. print '<!-- line not shown yet, we show it -->';
  1364. print '<tr class="oddeven"><td colspan="3"></td><td class="center">';
  1365. if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  1366. $disabled = '';
  1367. if (!empty($conf->productbatch->enabled) && $product->hasbatch()) {
  1368. $disabled = 'disabled="disabled"';
  1369. }
  1370. if ($warehouse_selected_id <= 0) { // We did not force a given warehouse, so we won't have no warehouse to change qty.
  1371. $disabled = 'disabled="disabled"';
  1372. }
  1373. print '<input class="qtyl" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0"'.($disabled ? ' '.$disabled : '').'> ';
  1374. } else {
  1375. print $langs->trans("NA");
  1376. }
  1377. print '</td>';
  1378. print '<td class="left">';
  1379. if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  1380. if ($warehouse_selected_id > 0) {
  1381. $warehouseObject = new Entrepot($db);
  1382. $warehouseObject->fetch($warehouse_selected_id);
  1383. print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $warehouseObject->label);
  1384. } else {
  1385. if ($line->fk_product) {
  1386. print img_warning().' '.$langs->trans("StockTooLow");
  1387. } else {
  1388. print '';
  1389. }
  1390. }
  1391. } else {
  1392. print $langs->trans("Service");
  1393. }
  1394. print '</td>';
  1395. print '</tr>';
  1396. }
  1397. }
  1398. // Display lines for extrafields of the Shipment line
  1399. // $line is a 'Order line'
  1400. if (!empty($extrafields)) {
  1401. //var_dump($line);
  1402. $colspan = 5;
  1403. $expLine = new ExpeditionLigne($db);
  1404. $srcLine = new OrderLine($db);
  1405. $srcLine->id = $line->id;
  1406. $srcLine->fetch_optionals(); // fetch extrafields also available in orderline
  1407. $expLine->array_options = array_merge($expLine->array_options, $srcLine->array_options);
  1408. print $expLine->showOptionals($extrafields, 'edit', array('style'=>'class="drag drop oddeven"', 'colspan'=>$colspan), $indiceAsked, '', 1);
  1409. }
  1410. }
  1411. $indiceAsked++;
  1412. }
  1413. print "</table>";
  1414. print '<br>';
  1415. print $form->buttonsSaveCancel("Create");
  1416. print '</form>';
  1417. print '<br>';
  1418. } else {
  1419. dol_print_error($db);
  1420. }
  1421. }
  1422. } elseif ($id || $ref) {
  1423. /* *************************************************************************** */
  1424. /* */
  1425. /* Edit and view mode */
  1426. /* */
  1427. /* *************************************************************************** */
  1428. $lines = $object->lines;
  1429. $num_prod = count($lines);
  1430. if ($object->id > 0) {
  1431. if (!empty($object->origin) && $object->origin_id > 0) {
  1432. $typeobject = $object->origin;
  1433. $origin = $object->origin;
  1434. $origin_id = $object->origin_id;
  1435. $object->fetch_origin(); // Load property $object->commande, $object->propal, ...
  1436. }
  1437. $soc = new Societe($db);
  1438. $soc->fetch($object->socid);
  1439. $res = $object->fetch_optionals();
  1440. $head = shipping_prepare_head($object);
  1441. print dol_get_fiche_head($head, 'shipping', $langs->trans("Shipment"), -1, $object->picto);
  1442. $formconfirm = '';
  1443. // Confirm deleteion
  1444. if ($action == 'delete') {
  1445. $formquestion = array();
  1446. if ($object->statut == Expedition::STATUS_CLOSED && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
  1447. $formquestion = array(
  1448. array(
  1449. 'label' => $langs->trans('ShipmentIncrementStockOnDelete'),
  1450. 'name' => 'alsoUpdateStock',
  1451. 'type' => 'checkbox',
  1452. 'value' => 0
  1453. ),
  1454. );
  1455. }
  1456. $formconfirm = $form->formconfirm(
  1457. $_SERVER['PHP_SELF'].'?id='.$object->id,
  1458. $langs->trans('DeleteSending'),
  1459. $langs->trans("ConfirmDeleteSending", $object->ref),
  1460. 'confirm_delete',
  1461. $formquestion,
  1462. 0,
  1463. 1
  1464. );
  1465. }
  1466. // Confirmation validation
  1467. if ($action == 'valid') {
  1468. $objectref = substr($object->ref, 1, 4);
  1469. if ($objectref == 'PROV') {
  1470. $numref = $object->getNextNumRef($soc);
  1471. } else {
  1472. $numref = $object->ref;
  1473. }
  1474. $text = $langs->trans("ConfirmValidateSending", $numref);
  1475. if (!empty($conf->notification->enabled)) {
  1476. require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  1477. $notify = new Notify($db);
  1478. $text .= '<br>';
  1479. $text .= $notify->confirmMessage('SHIPPING_VALIDATE', $object->socid, $object);
  1480. }
  1481. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateSending'), $text, 'confirm_valid', '', 0, 1);
  1482. }
  1483. // Confirm cancelation
  1484. if ($action == 'cancel') {
  1485. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelSending'), $langs->trans("ConfirmCancelSending", $object->ref), 'confirm_cancel', '', 0, 1);
  1486. }
  1487. // Call Hook formConfirm
  1488. $parameters = array('formConfirm' => $formconfirm);
  1489. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1490. if (empty($reshook)) {
  1491. $formconfirm .= $hookmanager->resPrint;
  1492. } elseif ($reshook > 0) {
  1493. $formconfirm = $hookmanager->resPrint;
  1494. }
  1495. // Print form confirm
  1496. print $formconfirm;
  1497. // Calculate totalWeight and totalVolume for all products
  1498. // by adding weight and volume of each product line.
  1499. $tmparray = $object->getTotalWeightVolume();
  1500. $totalWeight = $tmparray['weight'];
  1501. $totalVolume = $tmparray['volume'];
  1502. if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) {
  1503. $objectsrc = new Commande($db);
  1504. $objectsrc->fetch($object->$typeobject->id);
  1505. }
  1506. if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) {
  1507. $objectsrc = new Propal($db);
  1508. $objectsrc->fetch($object->$typeobject->id);
  1509. }
  1510. // Shipment card
  1511. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  1512. $morehtmlref = '<div class="refidno">';
  1513. // Ref customer shipment
  1514. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
  1515. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
  1516. // Thirdparty
  1517. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  1518. // Project
  1519. if (!empty($conf->project->enabled)) {
  1520. $langs->load("projects");
  1521. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  1522. if (0) { // Do not change on shipment
  1523. if ($action != 'classify') {
  1524. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  1525. }
  1526. if ($action == 'classify') {
  1527. // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  1528. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  1529. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  1530. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  1531. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  1532. $morehtmlref .= '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
  1533. $morehtmlref .= '</form>';
  1534. } else {
  1535. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  1536. }
  1537. } else {
  1538. // We don't have project on shipment, so we will use the project or source object instead
  1539. // TODO Add project on shipment
  1540. $morehtmlref .= ' : ';
  1541. if (!empty($objectsrc->fk_project)) {
  1542. $proj = new Project($db);
  1543. $proj->fetch($objectsrc->fk_project);
  1544. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  1545. if ($proj->title) {
  1546. $morehtmlref .= ' - '.$proj->title;
  1547. }
  1548. } else {
  1549. $morehtmlref .= '';
  1550. }
  1551. }
  1552. }
  1553. $morehtmlref .= '</div>';
  1554. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  1555. print '<div class="fichecenter">';
  1556. print '<div class="fichehalfleft">';
  1557. print '<div class="underbanner clearboth"></div>';
  1558. print '<table class="border tableforfield" width="100%">';
  1559. // Linked documents
  1560. if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) {
  1561. print '<tr><td>';
  1562. print $langs->trans("RefOrder").'</td>';
  1563. print '<td colspan="3">';
  1564. print $objectsrc->getNomUrl(1, 'commande');
  1565. print "</td>\n";
  1566. print '</tr>';
  1567. }
  1568. if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) {
  1569. print '<tr><td>';
  1570. print $langs->trans("RefProposal").'</td>';
  1571. print '<td colspan="3">';
  1572. print $objectsrc->getNomUrl(1, 'expedition');
  1573. print "</td>\n";
  1574. print '</tr>';
  1575. }
  1576. // Date creation
  1577. print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
  1578. print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour")."</td>\n";
  1579. print '</tr>';
  1580. // Delivery date planned
  1581. print '<tr><td height="10">';
  1582. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1583. print $langs->trans('DateDeliveryPlanned');
  1584. print '</td>';
  1585. if ($action != 'editdate_livraison') {
  1586. 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>';
  1587. }
  1588. print '</tr></table>';
  1589. print '</td><td colspan="2">';
  1590. if ($action == 'editdate_livraison') {
  1591. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1592. print '<input type="hidden" name="token" value="'.newToken().'">';
  1593. print '<input type="hidden" name="action" value="setdate_livraison">';
  1594. print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);
  1595. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  1596. print '</form>';
  1597. } else {
  1598. print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
  1599. }
  1600. print '</td>';
  1601. print '</tr>';
  1602. // Weight
  1603. print '<tr><td>';
  1604. print $form->editfieldkey("Weight", 'trueWeight', $object->trueWeight, $object, $user->rights->expedition->creer);
  1605. print '</td><td colspan="3">';
  1606. if ($action == 'edittrueWeight') {
  1607. print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1608. print '<input name="action" value="settrueWeight" type="hidden">';
  1609. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1610. print '<input type="hidden" name="token" value="'.newToken().'">';
  1611. print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text" class="width50">';
  1612. print $formproduct->selectMeasuringUnits("weight_units", "weight", $object->weight_units, 0, 2);
  1613. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1614. print ' <input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1615. print '</form>';
  1616. } else {
  1617. print $object->trueWeight;
  1618. print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : '';
  1619. }
  1620. // Calculated
  1621. if ($totalWeight > 0) {
  1622. if (!empty($object->trueWeight)) {
  1623. print ' ('.$langs->trans("SumOfProductWeights").': ';
  1624. }
  1625. 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');
  1626. if (!empty($object->trueWeight)) {
  1627. print ')';
  1628. }
  1629. }
  1630. print '</td></tr>';
  1631. // Width
  1632. print '<tr><td>'.$form->editfieldkey("Width", 'trueWidth', $object->trueWidth, $object, $user->rights->expedition->creer).'</td><td colspan="3">';
  1633. print $form->editfieldval("Width", 'trueWidth', $object->trueWidth, $object, $user->rights->expedition->creer);
  1634. print ($object->trueWidth && $object->width_units != '') ? ' '.measuringUnitString(0, "size", $object->width_units) : '';
  1635. print '</td></tr>';
  1636. // Height
  1637. print '<tr><td>'.$form->editfieldkey("Height", 'trueHeight', $object->trueHeight, $object, $user->rights->expedition->creer).'</td><td colspan="3">';
  1638. if ($action == 'edittrueHeight') {
  1639. print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1640. print '<input name="action" value="settrueHeight" type="hidden">';
  1641. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1642. print '<input type="hidden" name="token" value="'.newToken().'">';
  1643. print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text" class="width50">';
  1644. print $formproduct->selectMeasuringUnits("size_units", "size", $object->size_units, 0, 2);
  1645. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1646. print ' <input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1647. print '</form>';
  1648. } else {
  1649. print $object->trueHeight;
  1650. print ($object->trueHeight && $object->height_units != '') ? ' '.measuringUnitString(0, "size", $object->height_units) : '';
  1651. }
  1652. print '</td></tr>';
  1653. // Depth
  1654. print '<tr><td>'.$form->editfieldkey("Depth", 'trueDepth', $object->trueDepth, $object, $user->rights->expedition->creer).'</td><td colspan="3">';
  1655. print $form->editfieldval("Depth", 'trueDepth', $object->trueDepth, $object, $user->rights->expedition->creer);
  1656. print ($object->trueDepth && $object->depth_units != '') ? ' '.measuringUnitString(0, "size", $object->depth_units) : '';
  1657. print '</td></tr>';
  1658. // Volume
  1659. print '<tr><td>';
  1660. print $langs->trans("Volume");
  1661. print '</td>';
  1662. print '<td colspan="3">';
  1663. $calculatedVolume = 0;
  1664. $volumeUnit = 0;
  1665. if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
  1666. $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
  1667. $volumeUnit = $object->size_units * 3;
  1668. }
  1669. // If sending volume not defined we use sum of products
  1670. if ($calculatedVolume > 0) {
  1671. if ($volumeUnit < 50) {
  1672. 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');
  1673. } else {
  1674. print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit);
  1675. }
  1676. }
  1677. if ($totalVolume > 0) {
  1678. if ($calculatedVolume) {
  1679. print ' ('.$langs->trans("SumOfProductVolumes").': ';
  1680. }
  1681. 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');
  1682. //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
  1683. if ($calculatedVolume) {
  1684. print ')';
  1685. }
  1686. }
  1687. print "</td>\n";
  1688. print '</tr>';
  1689. // Other attributes
  1690. $cols = 2;
  1691. // Added by MMI Mathieu Moulin iProspective
  1692. // Extrafields show/hide
  1693. if ($conf->global->DOCUMENT_EXTRAFIELDS_SHOWHIDE) {
  1694. echo '<tr> <td colspan="2"><a href="javascript:;" onclick="$(\'#extrafields_form\').toggle();">'.$langs->trans('ToggleExtrafields').'</a></td> </tr>';
  1695. echo '<tbody id="extrafields_form" class="extrafields" style="display: none;">';
  1696. }
  1697. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1698. if ($conf->global->DOCUMENT_EXTRAFIELDS_SHOWHIDE) {
  1699. echo '</tbody>';
  1700. }
  1701. print '</table>';
  1702. print '</div>';
  1703. print '<div class="fichehalfright">';
  1704. print '<div class="underbanner clearboth"></div>';
  1705. print '<table class="border centpercent tableforfield">';
  1706. // Sending method
  1707. print '<tr><td height="10">';
  1708. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1709. print $langs->trans('SendingMethod');
  1710. print '</td>';
  1711. if ($action != 'editshipping_method_id') {
  1712. 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>';
  1713. }
  1714. print '</tr></table>';
  1715. print '</td><td colspan="2">';
  1716. if ($action == 'editshipping_method_id') {
  1717. print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1718. print '<input type="hidden" name="token" value="'.newToken().'">';
  1719. print '<input type="hidden" name="action" value="setshipping_method_id">';
  1720. $object->fetch_delivery_methods();
  1721. print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1);
  1722. if ($user->admin) {
  1723. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1724. }
  1725. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  1726. print '</form>';
  1727. } else {
  1728. if ($object->shipping_method_id > 0) {
  1729. // Get code using getLabelFromKey
  1730. $code = $langs->getLabelFromKey($db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
  1731. print $langs->trans("SendingMethod".strtoupper($code));
  1732. }
  1733. }
  1734. print '</td>';
  1735. print '</tr>';
  1736. // Tracking Number
  1737. print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber", 'tracking_number', $object->tracking_number, $object, $user->rights->expedition->creer).'</td><td colspan="3">';
  1738. print $form->editfieldval("TrackingNumber", 'tracking_number', $object->tracking_url, $object, $user->rights->expedition->creer, 'safehtmlstring', $object->tracking_number);
  1739. print '</td></tr>';
  1740. // Incoterms
  1741. if (!empty($conf->incoterm->enabled)) {
  1742. print '<tr><td>';
  1743. print '<table width="100%" class="nobordernopadding"><tr><td>';
  1744. print $langs->trans('IncotermLabel');
  1745. print '<td><td class="right">';
  1746. if ($user->rights->expedition->creer) {
  1747. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
  1748. } else {
  1749. print '&nbsp;';
  1750. }
  1751. print '</td></tr></table>';
  1752. print '</td>';
  1753. print '<td colspan="3">';
  1754. if ($action != 'editincoterm') {
  1755. print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
  1756. } else {
  1757. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
  1758. }
  1759. print '</td></tr>';
  1760. }
  1761. // Other attributes
  1762. $parameters = array('colspan' => ' colspan="3"', 'cols' => '3');
  1763. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1764. print $hookmanager->resPrint;
  1765. print "</table>";
  1766. print '</div>';
  1767. print '</div>';
  1768. print '<div class="clearboth"></div>';
  1769. // Lines of products
  1770. if ($action == 'editline') {
  1771. print ' <form name="updateline" id="updateline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;lineid='.$line_id.'" method="POST">
  1772. <input type="hidden" name="token" value="' . newToken().'">
  1773. <input type="hidden" name="action" value="updateline">
  1774. <input type="hidden" name="mode" value="">
  1775. <input type="hidden" name="id" value="' . $object->id.'">
  1776. ';
  1777. }
  1778. print '<br>';
  1779. print '<div class="div-table-responsive-no-min">';
  1780. print '<table class="noborder" width="100%" id="tablelines" >';
  1781. print '<thead>';
  1782. print '<tr class="liste_titre">';
  1783. // Adds a line numbering column
  1784. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  1785. print '<td width="5" class="center linecolnum">&nbsp;</td>';
  1786. }
  1787. // Product/Service
  1788. print '<td class="linecoldescription" >'.$langs->trans("Products").'</td>';
  1789. // Qty
  1790. print '<td class="center linecolqty">'.$langs->trans("QtyOrdered").'</td>';
  1791. if ($origin && $origin_id > 0) {
  1792. print '<td class="center linecolqtyinothershipments">'.$langs->trans("QtyInOtherShipments").'</td>';
  1793. }
  1794. if ($action == 'editline') {
  1795. $editColspan = 3;
  1796. if (empty($conf->stock->enabled)) {
  1797. $editColspan--;
  1798. }
  1799. if (empty($conf->productbatch->enabled)) {
  1800. $editColspan--;
  1801. }
  1802. print '<td class="center linecoleditlineotherinfo" colspan="'.$editColspan.'">';
  1803. if ($object->statut <= 1) {
  1804. print $langs->trans("QtyToShip").' - ';
  1805. } else {
  1806. print $langs->trans("QtyShipped").' - ';
  1807. }
  1808. if (!empty($conf->stock->enabled)) {
  1809. print $langs->trans("WarehouseSource").' - ';
  1810. }
  1811. if (!empty($conf->productbatch->enabled)) {
  1812. print $langs->trans("Batch");
  1813. }
  1814. print '</td>';
  1815. } else {
  1816. if ($object->statut <= 1) {
  1817. print '<td class="center linecolqtytoship">'.$langs->trans("QtyToShip").'</td>';
  1818. } else {
  1819. print '<td class="center linecolqtyshipped">'.$langs->trans("QtyShipped").'</td>';
  1820. }
  1821. if (!empty($conf->stock->enabled)) {
  1822. print '<td class="left linecolwarehousesource">'.$langs->trans("WarehouseSource").'</td>';
  1823. }
  1824. if (!empty($conf->productbatch->enabled)) {
  1825. print '<td class="left linecolbatch">'.$langs->trans("Batch").'</td>';
  1826. }
  1827. }
  1828. print '<td class="center linecolweight">'.$langs->trans("CalculatedWeight").'</td>';
  1829. print '<td class="center linecolvolume">'.$langs->trans("CalculatedVolume").'</td>';
  1830. //print '<td class="center">'.$langs->trans("Size").'</td>';
  1831. if ($object->statut == 0) {
  1832. print '<td class="linecoledit"></td>';
  1833. print '<td class="linecoldelete" width="10"></td>';
  1834. }
  1835. print "</tr>\n";
  1836. print '</thead>';
  1837. $outputlangs = $langs;
  1838. if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
  1839. $object->fetch_thirdparty();
  1840. $newlang = '';
  1841. if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  1842. $newlang = GETPOST('lang_id', 'aZ09');
  1843. }
  1844. if (empty($newlang)) {
  1845. $newlang = $object->thirdparty->default_lang;
  1846. }
  1847. if (!empty($newlang)) {
  1848. $outputlangs = new Translate("", $conf);
  1849. $outputlangs->setDefaultLang($newlang);
  1850. }
  1851. }
  1852. // Get list of products already sent for same source object into $alreadysent
  1853. $alreadysent = array();
  1854. if ($origin && $origin_id > 0) {
  1855. $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";
  1856. $sql .= ", ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot";
  1857. $sql .= ", e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition";
  1858. //if ($conf->delivery_note->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
  1859. $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';
  1860. $sql .= ', p.description as product_desc';
  1861. $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
  1862. $sql .= ", ".MAIN_DB_PREFIX."expedition as e";
  1863. $sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj";
  1864. //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";
  1865. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
  1866. $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
  1867. $sql .= " AND obj.fk_".$origin." = ".((int) $origin_id);
  1868. $sql .= " AND obj.rowid = ed.fk_origin_line";
  1869. $sql .= " AND ed.fk_expedition = e.rowid";
  1870. //if ($filter) $sql.= $filter;
  1871. $sql .= " ORDER BY obj.fk_product";
  1872. dol_syslog("expedition/card.php get list of shipment lines", LOG_DEBUG);
  1873. $resql = $db->query($sql);
  1874. if ($resql) {
  1875. $num = $db->num_rows($resql);
  1876. $i = 0;
  1877. while ($i < $num) {
  1878. $obj = $db->fetch_object($resql);
  1879. if ($obj) {
  1880. // $obj->rowid is rowid in $origin."det" table
  1881. $alreadysent[$obj->rowid][$obj->shipmentline_id] = array(
  1882. 'shipment_ref'=>$obj->shipment_ref, 'shipment_id'=>$obj->shipment_id, 'warehouse'=>$obj->fk_entrepot, 'qty_shipped'=>$obj->qty_shipped,
  1883. 'product_tosell'=>$obj->product_tosell, 'product_tobuy'=>$obj->product_tobuy, 'product_tobatch'=>$obj->product_tobatch,
  1884. 'date_valid'=>$db->jdate($obj->date_valid), 'date_delivery'=>$db->jdate($obj->date_delivery));
  1885. }
  1886. $i++;
  1887. }
  1888. }
  1889. //var_dump($alreadysent);
  1890. }
  1891. print '<tbody>';
  1892. // Loop on each product to send/sent
  1893. for ($i = 0; $i < $num_prod; $i++) {
  1894. $parameters = array('i' => $i, 'line' => $lines[$i], 'line_id' => $line_id, 'num' => $num_prod, 'alreadysent' => $alreadysent, 'editColspan' => !empty($editColspan) ? $editColspan : 0, 'outputlangs' => $outputlangs);
  1895. $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);
  1896. if ($reshook < 0) {
  1897. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1898. }
  1899. if (empty($reshook)) {
  1900. print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line
  1901. print '<tr class="oddeven" id="row-'.$lines[$i]->id.'" data-id="'.$lines[$i]->id.'" data-element="'.$lines[$i]->element.'" >';
  1902. // #
  1903. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  1904. print '<td class="center linecolnum">'.($i + 1).'</td>';
  1905. }
  1906. // Predefined product or service
  1907. if ($lines[$i]->fk_product > 0) {
  1908. // Define output language
  1909. if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
  1910. $prod = new Product($db);
  1911. $prod->fetch($lines[$i]->fk_product);
  1912. $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;
  1913. } else {
  1914. $label = (!empty($lines[$i]->label) ? $lines[$i]->label : $lines[$i]->product_label);
  1915. }
  1916. print '<td class="linecoldescription">';
  1917. // Show product and description
  1918. $product_static->type = $lines[$i]->fk_product_type;
  1919. $product_static->id = $lines[$i]->fk_product;
  1920. $product_static->ref = $lines[$i]->ref;
  1921. $product_static->status = $lines[$i]->product_tosell;
  1922. $product_static->status_buy = $lines[$i]->product_tobuy;
  1923. $product_static->status_batch = $lines[$i]->product_tobatch;
  1924. $product_static->weight = $lines[$i]->weight;
  1925. $product_static->weight_units = $lines[$i]->weight_units;
  1926. $product_static->length = $lines[$i]->length;
  1927. $product_static->length_units = $lines[$i]->length_units;
  1928. $product_static->width = !empty($lines[$i]->width) ? $lines[$i]->width : 0;
  1929. $product_static->width_units = !empty($lines[$i]->width_units) ? $lines[$i]->width_units : 0;
  1930. $product_static->height = !empty($lines[$i]->height) ? $lines[$i]->height : 0;
  1931. $product_static->height_units = !empty($lines[$i]->height_units) ? $lines[$i]->height_units : 0;
  1932. $product_static->surface = $lines[$i]->surface;
  1933. $product_static->surface_units = $lines[$i]->surface_units;
  1934. $product_static->volume = $lines[$i]->volume;
  1935. $product_static->volume_units = $lines[$i]->volume_units;
  1936. $text = $product_static->getNomUrl(1);
  1937. $text .= ' - '.$label;
  1938. $description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($lines[$i]->description));
  1939. print $form->textwithtooltip($text, $description, 3, '', '', $i);
  1940. print_date_range(!empty($lines[$i]->date_start) ? $lines[$i]->date_start : '', !empty($lines[$i]->date_end) ? $lines[$i]->date_end : '');
  1941. if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) {
  1942. print (!empty($lines[$i]->description) && $lines[$i]->description != $lines[$i]->product) ? '<br>'.dol_htmlentitiesbr($lines[$i]->description) : '';
  1943. }
  1944. print "</td>\n";
  1945. } else {
  1946. print '<td class="linecoldescription" >';
  1947. if ($lines[$i]->product_type == Product::TYPE_SERVICE) {
  1948. $text = img_object($langs->trans('Service'), 'service');
  1949. } else {
  1950. $text = img_object($langs->trans('Product'), 'product');
  1951. }
  1952. if (!empty($lines[$i]->label)) {
  1953. $text .= ' <strong>'.$lines[$i]->label.'</strong>';
  1954. print $form->textwithtooltip($text, $lines[$i]->description, 3, '', '', $i);
  1955. } else {
  1956. print $text.' '.nl2br($lines[$i]->description);
  1957. }
  1958. print_date_range($lines[$i]->date_start, $lines[$i]->date_end);
  1959. print "</td>\n";
  1960. }
  1961. $unit_order = '';
  1962. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  1963. $unit_order = measuringUnitString($lines[$i]->fk_unit);
  1964. }
  1965. // Qty ordered
  1966. print '<td class="center linecolqty">'.$lines[$i]->qty_asked.' '.$unit_order.'</td>';
  1967. // Qty in other shipments (with shipment and warehouse used)
  1968. if ($origin && $origin_id > 0) {
  1969. print '<td class="linecolqtyinothershipments center nowrap">';
  1970. foreach ($alreadysent as $key => $val) {
  1971. if ($lines[$i]->fk_origin_line == $key) {
  1972. $j = 0;
  1973. foreach ($val as $shipmentline_id => $shipmentline_var) {
  1974. if ($shipmentline_var['shipment_id'] == $lines[$i]->fk_expedition) {
  1975. continue; // We want to show only "other shipments"
  1976. }
  1977. $j++;
  1978. if ($j > 1) {
  1979. print '<br>';
  1980. }
  1981. $shipment_static->fetch($shipmentline_var['shipment_id']);
  1982. print $shipment_static->getNomUrl(1);
  1983. print ' - '.$shipmentline_var['qty_shipped'];
  1984. $htmltext = $langs->trans("DateValidation").' : '.(empty($shipmentline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($shipmentline_var['date_valid'], 'dayhour'));
  1985. if (!empty($conf->stock->enabled) && $shipmentline_var['warehouse'] > 0) {
  1986. $warehousestatic->fetch($shipmentline_var['warehouse']);
  1987. $htmltext .= '<br>'.$langs->trans("FromLocation").' : '.$warehousestatic->getNomUrl(1, '', 0, 1);
  1988. }
  1989. print ' '.$form->textwithpicto('', $htmltext, 1);
  1990. }
  1991. }
  1992. }
  1993. print '</td>';
  1994. }
  1995. if ($action == 'editline' && $lines[$i]->id == $line_id) {
  1996. // edit mode
  1997. print '<td colspan="'.$editColspan.'" class="center"><table class="nobordernopadding centpercent">';
  1998. if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) {
  1999. print '<!-- case edit 1 -->';
  2000. $line = new ExpeditionLigne($db);
  2001. foreach ($lines[$i]->detail_batch as $detail_batch) {
  2002. print '<tr>';
  2003. // Qty to ship or shipped
  2004. 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>';
  2005. // Batch number managment
  2006. if ($lines[$i]->entrepot_id == 0) {
  2007. // only show lot numbers from src warehouse when shipping from multiple warehouses
  2008. $line->fetch($detail_batch->fk_expeditiondet);
  2009. }
  2010. $entrepot_id = !empty($detail_batch->entrepot_id)?$detail_batch->entrepot_id:$lines[$i]->entrepot_id;
  2011. 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>';
  2012. print '</tr>';
  2013. }
  2014. // add a 0 qty lot row to be able to add a lot
  2015. print '<tr>';
  2016. // Qty to ship or shipped
  2017. print '<td><input class="qtyl" name="qtyl'.$line_id.'_0" id="qtyl'.$line_id.'_0" type="text" size="4" value="0"></td>';
  2018. // Batch number managment
  2019. print '<td>'.$formproduct->selectLotStock('', 'batchl'.$line_id.'_0', '', 1, 0, $lines[$i]->fk_product).'</td>';
  2020. print '</tr>';
  2021. } elseif (!empty($conf->stock->enabled)) {
  2022. if ($lines[$i]->fk_product > 0) {
  2023. if ($lines[$i]->entrepot_id > 0) {
  2024. print '<!-- case edit 2 -->';
  2025. print '<tr>';
  2026. // Qty to ship or shipped
  2027. 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>';
  2028. // Warehouse source
  2029. print '<td>'.$formproduct->selectWarehouses($lines[$i]->entrepot_id, 'entl'.$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. } elseif (count($lines[$i]->details_entrepot) > 1) {
  2034. print '<!-- case edit 3 -->';
  2035. foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
  2036. print '<tr>';
  2037. // Qty to ship or shipped
  2038. 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>';
  2039. // Warehouse source
  2040. print '<td>'.$formproduct->selectWarehouses($detail_entrepot->entrepot_id, 'entl'.$detail_entrepot->line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';
  2041. // Batch number managment
  2042. print '<td> - '.$langs->trans("NA").'</td>';
  2043. print '</tr>';
  2044. }
  2045. } else {
  2046. print '<!-- case edit 4 -->';
  2047. print '<tr><td colspan="3">'.$langs->trans("NotEnoughStock").'</td></tr>';
  2048. }
  2049. } else {
  2050. print '<!-- case edit 5 -->';
  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.'">'.$unit_order.'</td>';
  2054. // Warehouse source
  2055. print '<td></td>';
  2056. // Batch number managment
  2057. print '<td></td>';
  2058. print '</tr>';
  2059. }
  2060. } elseif (empty($conf->stock->enabled) && empty($conf->productbatch->enabled)) { // both product batch and stock are not activated.
  2061. print '<!-- case edit 6 -->';
  2062. print '<tr>';
  2063. // Qty to ship or shipped
  2064. print '<td><input class="qtyl" name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'"></td>';
  2065. // Warehouse source
  2066. print '<td></td>';
  2067. // Batch number managment
  2068. print '<td></td>';
  2069. print '</tr>';
  2070. }
  2071. print '</table></td>';
  2072. } else {
  2073. // Qty to ship or shipped
  2074. print '<td class="linecolqtytoship center">'.$lines[$i]->qty_shipped.' '.$unit_order.'</td>';
  2075. // Warehouse source
  2076. if (!empty($conf->stock->enabled)) {
  2077. print '<td class="linecolwarehousesource left">';
  2078. if ($lines[$i]->entrepot_id > 0) {
  2079. $entrepot = new Entrepot($db);
  2080. $entrepot->fetch($lines[$i]->entrepot_id);
  2081. print $entrepot->getNomUrl(1);
  2082. } elseif (count($lines[$i]->details_entrepot) > 1) {
  2083. $detail = '';
  2084. foreach ($lines[$i]->details_entrepot as $detail_entrepot) {
  2085. if ($detail_entrepot->entrepot_id > 0) {
  2086. $entrepot = new Entrepot($db);
  2087. $entrepot->fetch($detail_entrepot->entrepot_id);
  2088. $detail .= $langs->trans("DetailWarehouseFormat", $entrepot->libelle, $detail_entrepot->qty_shipped).'<br>';
  2089. }
  2090. }
  2091. print $form->textwithtooltip(img_picto('', 'object_stock').' '.$langs->trans("DetailWarehouseNumber"), $detail);
  2092. }
  2093. print '</td>';
  2094. }
  2095. // Batch number managment
  2096. if (!empty($conf->productbatch->enabled)) {
  2097. if (isset($lines[$i]->detail_batch)) {
  2098. print '<!-- Detail of lot -->';
  2099. print '<td class="linecolbatch">';
  2100. if ($lines[$i]->product_tobatch) {
  2101. $detail = '';
  2102. foreach ($lines[$i]->detail_batch as $dbatch) { // $dbatch is instance of ExpeditionLineBatch
  2103. $detail .= $langs->trans("Batch").': '.$dbatch->batch;
  2104. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  2105. $detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day");
  2106. }
  2107. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  2108. $detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby, "day");
  2109. }
  2110. $detail .= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
  2111. $detail .= '<br>';
  2112. }
  2113. print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $detail);
  2114. } else {
  2115. print $langs->trans("NA");
  2116. }
  2117. print '</td>';
  2118. } else {
  2119. print '<td class="linecolbatch" ></td>';
  2120. }
  2121. }
  2122. }
  2123. // Weight
  2124. print '<td class="center linecolweight">';
  2125. if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
  2126. print $lines[$i]->weight * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "weight", $lines[$i]->weight_units);
  2127. } else {
  2128. print '&nbsp;';
  2129. }
  2130. print '</td>';
  2131. // Volume
  2132. print '<td class="center linecolvolume">';
  2133. if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
  2134. print $lines[$i]->volume * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units);
  2135. } else {
  2136. print '&nbsp;';
  2137. }
  2138. print '</td>';
  2139. // Size
  2140. //print '<td class="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units).'</td>';
  2141. if ($action == 'editline' && $lines[$i]->id == $line_id) {
  2142. print '<td class="center" colspan="2" valign="middle">';
  2143. print '<input type="submit" class="button button-save" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';
  2144. print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"><br>';
  2145. print '</td>';
  2146. } elseif ($object->statut == Expedition::STATUS_DRAFT) {
  2147. // edit-delete buttons
  2148. print '<td class="linecoledit center">';
  2149. print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_edit().'</a>';
  2150. print '</td>';
  2151. print '<td class="linecoldelete" width="10">';
  2152. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_delete().'</a>';
  2153. print '</td>';
  2154. // Display lines extrafields
  2155. if (!empty($rowExtrafieldsStart)) {
  2156. print $rowExtrafieldsStart;
  2157. print $rowExtrafieldsView;
  2158. print $rowEnd;
  2159. }
  2160. }
  2161. print "</tr>";
  2162. // Display lines extrafields.
  2163. // $line is a line of shipment
  2164. if (!empty($extrafields)) {
  2165. $colspan = 6;
  2166. if ($origin && $origin_id > 0) {
  2167. $colspan++;
  2168. }
  2169. if (!empty($conf->productbatch->enabled)) {
  2170. $colspan++;
  2171. }
  2172. if (!empty($conf->stock->enabled)) {
  2173. $colspan++;
  2174. }
  2175. $line = $lines[$i];
  2176. $line->fetch_optionals();
  2177. // TODO Show all in same line by setting $display_type = 'line'
  2178. if ($action == 'editline' && $line->id == $line_id) {
  2179. print $lines[$i]->showOptionals($extrafields, 'edit', array('colspan'=>$colspan), !empty($indiceAsked) ? $indiceAsked : '', '', 0, 'card');
  2180. } else {
  2181. print $lines[$i]->showOptionals($extrafields, 'view', array('colspan'=>$colspan), !empty($indiceAsked) ? $indiceAsked : '', '', 0, 'card');
  2182. }
  2183. }
  2184. }
  2185. }
  2186. // TODO Show also lines ordered but not delivered
  2187. print "</table>\n";
  2188. print '</tbody>';
  2189. print '</div>';
  2190. }
  2191. print dol_get_fiche_end();
  2192. $object->fetchObjectLinked($object->id, $object->element);
  2193. /*
  2194. * Boutons actions
  2195. */
  2196. if (($user->socid == 0) && ($action != 'presend')) {
  2197. print '<div class="tabsAction">';
  2198. $parameters = array();
  2199. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  2200. // modified by hook
  2201. if (empty($reshook)) {
  2202. if ($object->statut == Expedition::STATUS_DRAFT && $num_prod > 0) {
  2203. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer))
  2204. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate))) {
  2205. print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=valid&token='.newToken().'&id='.$object->id, '');
  2206. } else {
  2207. print dolGetButtonAction($langs->trans('NotAllowed'), $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  2208. }
  2209. }
  2210. // TODO add alternative status
  2211. // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
  2212. if ($object->statut == Expedition::STATUS_CLOSED && $user->rights->expedition->creer) {
  2213. 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 ?
  2214. print dolGetButtonAction('', $langs->trans('ClassifyUnbilled'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
  2215. } else {
  2216. print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');
  2217. }
  2218. }
  2219. // Send
  2220. if (empty($user->socid)) {
  2221. if ($object->statut > 0) {
  2222. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send) {
  2223. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');
  2224. } else {
  2225. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  2226. }
  2227. }
  2228. }
  2229. // Create bill
  2230. if (isModEnabled('facture') && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED)) {
  2231. if ($user->rights->facture->creer) {
  2232. // TODO show button only if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))
  2233. // If we do that, we must also make this option official.
  2234. if (empty($conf->global->BILL_ON_SHIPMENT_DISABLE))
  2235. print dolGetButtonAction('', $langs->trans('CreateBill'), 'default', DOL_URL_ROOT.'/compta/facture/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid, '');
  2236. }
  2237. }
  2238. // This is just to generate a delivery receipt
  2239. //var_dump($object->linkedObjectsIds['delivery']);
  2240. if ($conf->delivery_note->enabled && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED) && $user->rights->expedition->delivery->creer && empty($object->linkedObjectsIds['delivery'])) {
  2241. print dolGetButtonAction('', $langs->trans('CreateDeliveryOrder'), 'default', $_SERVER["PHP_SELF"].'?action=create_delivery&token='.newToken().'&id='.$object->id, '');
  2242. }
  2243. // Close
  2244. if ($object->statut == Expedition::STATUS_VALIDATED) {
  2245. if ($user->rights->expedition->creer && $object->statut > 0 && !$object->billed) {
  2246. $label = "Close"; $paramaction = 'classifyclosed'; // = Transferred/Received
  2247. // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders
  2248. 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 ?
  2249. $label = "ClassifyBilled";
  2250. $paramaction = 'classifybilled';
  2251. }
  2252. print dolGetButtonAction('', $langs->trans($label), 'default', $_SERVER["PHP_SELF"].'?action='. $paramaction .'&token='.newToken().'&id='.$object->id, '');
  2253. }
  2254. }
  2255. // Cancel
  2256. if ($object->statut == Expedition::STATUS_VALIDATED) {
  2257. if ($user->rights->expedition->supprimer) {
  2258. print dolGetButtonAction('', $langs->trans('Cancel'), 'danger', $_SERVER["PHP_SELF"].'?action=cancel&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');
  2259. }
  2260. }
  2261. // Delete
  2262. if ($user->rights->expedition->supprimer) {
  2263. print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
  2264. }
  2265. }
  2266. print '</div>';
  2267. }
  2268. /*
  2269. * Documents generated
  2270. */
  2271. if ($action != 'presend' && $action != 'editline') {
  2272. print '<div class="fichecenter"><div class="fichehalfleft">';
  2273. $objectref = dol_sanitizeFileName($object->ref);
  2274. $filedir = $conf->expedition->dir_output."/sending/".$objectref;
  2275. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  2276. $genallowed = $user->rights->expedition->lire;
  2277. $delallowed = $user->rights->expedition->creer;
  2278. print $formfile->showdocuments('expedition', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  2279. // Show links to link elements
  2280. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
  2281. $somethingshown = $form->showLinkedObjectBlock($object, '');
  2282. print '</div><div class="fichehalfright">';
  2283. // List of actions on element
  2284. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  2285. $formactions = new FormActions($db);
  2286. $somethingshown = $formactions->showactions($object, 'shipping', $socid, 1);
  2287. print '</div></div>';
  2288. }
  2289. /*
  2290. * Action presend
  2291. */
  2292. //Select mail models is same action as presend
  2293. if (GETPOST('modelselected')) {
  2294. $action = 'presend';
  2295. }
  2296. // Presend form
  2297. $modelmail = 'shipping_send';
  2298. $defaulttopic = $langs->trans('SendShippingRef');
  2299. $diroutput = $conf->expedition->dir_output.'/sending';
  2300. $trackid = 'shi'.$object->id;
  2301. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  2302. }
  2303. // End of page
  2304. llxFooter();
  2305. $db->close();