card.php 98 KB

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