card.php 105 KB

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