card.php 111 KB

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