card.php 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237
  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@capnetworks.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 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2016 Yasser Carreón <yacasia@gmail.com>
  14. * Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/reception/card.php
  31. * \ingroup reception
  32. * \brief Card of a reception
  33. */
  34. // Load Dolibarr environment
  35. require '../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.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/reception.lib.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.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. if (isModEnabled("product") || isModEnabled("service")) {
  47. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  48. }
  49. if (isModEnabled("propal")) {
  50. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  51. }
  52. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  53. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
  54. if (isModEnabled('productbatch')) {
  55. require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
  56. }
  57. if (isModEnabled('project')) {
  58. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  59. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  60. }
  61. $langs->loadLangs(array("receptions", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal', 'sendings'));
  62. if (isModEnabled('incoterm')) {
  63. $langs->load('incoterm');
  64. }
  65. if (isModEnabled('productbatch')) {
  66. $langs->load('productbatch');
  67. }
  68. $origin = GETPOST('origin', 'alpha') ? GETPOST('origin', 'alpha') : 'reception'; // Example: commande, propal
  69. $origin_id = GETPOST('id', 'int') ? GETPOST('id', 'int') : '';
  70. $id = $origin_id;
  71. if (empty($origin_id)) {
  72. $origin_id = GETPOST('origin_id', 'int'); // Id of order or propal
  73. }
  74. if (empty($origin_id)) {
  75. $origin_id = GETPOST('object_id', 'int'); // Id of order or propal
  76. }
  77. if (empty($origin_id)) {
  78. $origin_id = GETPOST('originid', 'int'); // Id of order or propal
  79. }
  80. $ref = GETPOST('ref', 'alpha');
  81. $line_id = GETPOST('lineid', 'int') ? GETPOST('lineid', 'int') : '';
  82. $facid = GETPOST('facid', 'int');
  83. $action = GETPOST('action', 'alpha');
  84. //Select mail models is same action as presend
  85. if (GETPOST('modelselected')) {
  86. $action = 'presend';
  87. }
  88. $confirm = GETPOST('confirm', 'alpha');
  89. $cancel = GETPOST('cancel', 'alpha');
  90. $backtopage = GETPOST('backtopage', 'alpha');
  91. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  92. //PDF
  93. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
  94. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
  95. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
  96. $object = new Reception($db);
  97. $objectorder = new CommandeFournisseur($db);
  98. $extrafields = new ExtraFields($db);
  99. // fetch optionals attributes and labels
  100. $extrafields->fetch_name_optionals_label($object->table_element);
  101. $extrafields->fetch_name_optionals_label($object->table_element_line);
  102. $extrafields->fetch_name_optionals_label($objectorder->table_element_line);
  103. // Load object. Make an object->fetch
  104. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  105. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  106. $hookmanager->initHooks(array('receptioncard', 'globalcard'));
  107. $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'));
  108. if ($id > 0 || !empty($ref)) {
  109. $object->fetch($id, $ref);
  110. $object->fetch_thirdparty();
  111. $typeobject = '';
  112. if (!empty($object->origin)) {
  113. $origin = $object->origin;
  114. $object->fetch_origin();
  115. $typeobject = $object->origin;
  116. }
  117. // Set $origin_id and $objectsrc
  118. if (($origin == 'order_supplier' || $origin == 'supplier_order') && is_object($object->origin_object) && isModEnabled("supplier_order")) {
  119. $origin_id = $object->origin_object->id;
  120. $objectsrc = $object->origin_object;
  121. }
  122. }
  123. // Security check
  124. $socid = '';
  125. if ($user->socid) {
  126. $socid = $user->socid;
  127. }
  128. // TODO Test on reception module on only
  129. if (isModEnabled("reception") || $origin == 'reception' || empty($origin)) {
  130. $result = restrictedArea($user, 'reception', $object->id);
  131. } else {
  132. // We do not use the reception module, so we test permission on the supplier orders
  133. if ($origin == 'supplierorder' || $origin == 'order_supplier') {
  134. $result = restrictedArea($user, 'fournisseur', $origin_id, 'commande_fournisseur', 'commande');
  135. } elseif (!$user->hasRight($origin, 'lire') && !$user->hasRight($origin, 'read')) {
  136. accessforbidden();
  137. }
  138. }
  139. if (isModEnabled("reception")) {
  140. $permissiontoread = $user->rights->reception->lire;
  141. $permissiontoadd = $user->rights->reception->creer;
  142. $permissiondellink = $user->rights->reception->creer; // Used by the include of actions_dellink.inc.php
  143. $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->reception->creer)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->reception->reception_advance->validate)));
  144. $permissiontodelete = $user->rights->reception->supprimer;
  145. } else {
  146. $permissiontoread = $user->rights->fournisseur->commande->receptionner;
  147. $permissiontoadd = $user->rights->fournisseur->commande->receptionner;
  148. $permissiondellink = $user->rights->fournisseur->commande->receptionner; // Used by the include of actions_dellink.inc.php
  149. $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->fournisseur->commande->receptionner)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($user->rights->fournisseur->commande_advance->check)));
  150. $permissiontodelete = $user->rights->fournisseur->commande->receptionner;
  151. }
  152. /*
  153. * Actions
  154. */
  155. $parameters = array();
  156. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  157. if ($reshook < 0) {
  158. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  159. }
  160. if (empty($reshook)) {
  161. /*
  162. $backurlforlist = DOL_URL_ROOT.'/reception/list.php';
  163. if (empty($backtopage) || ($cancel && empty($id))) {
  164. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  165. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  166. $backtopage = $backurlforlist;
  167. } else {
  168. $backtopage = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  169. }
  170. }
  171. }
  172. */
  173. if ($cancel) {
  174. if (!empty($backtopageforcancel)) {
  175. header("Location: ".$backtopageforcancel);
  176. exit;
  177. } elseif (!empty($backtopage)) {
  178. header("Location: ".$backtopage);
  179. exit;
  180. }
  181. $action = '';
  182. }
  183. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  184. // Reopen
  185. if ($action == 'reopen' && $permissiontoadd) {
  186. $result = $object->reOpen();
  187. }
  188. // Confirm back to draft status
  189. if ($action == 'modif' && $permissiontoadd) {
  190. $result = $object->setDraft($user);
  191. if ($result >= 0) {
  192. // Define output language
  193. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  194. $outputlangs = $langs;
  195. $newlang = '';
  196. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  197. $newlang = GETPOST('lang_id', 'aZ09');
  198. }
  199. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  200. $newlang = $object->thirdparty->default_lang;
  201. }
  202. if (!empty($newlang)) {
  203. $outputlangs = new Translate("", $conf);
  204. $outputlangs->setDefaultLang($newlang);
  205. }
  206. $model = $object->model_pdf;
  207. $ret = $object->fetch($id); // Reload to get new records
  208. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  209. }
  210. } else {
  211. setEventMessages($object->error, $object->errors, 'errors');
  212. }
  213. }
  214. // Set incoterm
  215. if ($action == 'set_incoterms' && isModEnabled('incoterm') && $permissiontoadd) {
  216. $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
  217. }
  218. if ($action == 'setref_supplier' && $permissiontoadd) {
  219. if ($result < 0) {
  220. setEventMessages($object->error, $object->errors, 'errors');
  221. }
  222. $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'RECEPTION_MODIFY');
  223. if ($result < 0) {
  224. setEventMessages($object->error, $object->errors, 'errors');
  225. $action = 'editref_supplier';
  226. } else {
  227. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  228. exit;
  229. }
  230. }
  231. if ($action == 'update_extras' && $permissiontoadd) {
  232. $object->oldcopy = dol_clone($object, 2);
  233. // Fill array 'array_options' with data from update form
  234. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  235. if ($ret < 0) {
  236. $error++;
  237. }
  238. if (!$error) {
  239. // Actions on extra fields
  240. $result = $object->insertExtraFields('RECEPTION_MODIFY');
  241. if ($result < 0) {
  242. setEventMessages($object->error, $object->errors, 'errors');
  243. $error++;
  244. }
  245. }
  246. if ($error) {
  247. $action = 'edit_extras';
  248. }
  249. }
  250. // Create reception
  251. if ($action == 'add' && $permissiontoadd) {
  252. $error = 0;
  253. $predef = '';
  254. $db->begin();
  255. $object->note = GETPOST('note', 'alpha');
  256. $object->origin = $origin;
  257. $object->origin_id = $origin_id;
  258. $object->fk_project = GETPOST('projectid', 'int');
  259. $object->weight = GETPOST('weight', 'int') == '' ? null : GETPOST('weight', 'int');
  260. $object->trueHeight = GETPOST('trueHeight', 'int') == '' ? null : GETPOST('trueHeight', 'int');
  261. $object->trueWidth = GETPOST('trueWidth', 'int') == '' ? null : GETPOST('trueWidth', 'int');
  262. $object->trueDepth = GETPOST('trueDepth', 'int') == '' ? null : GETPOST('trueDepth', 'int');
  263. $object->size_units = GETPOST('size_units', 'int');
  264. $object->weight_units = GETPOST('weight_units', 'int');
  265. // On va boucler sur chaque ligne du document d'origine pour completer objet reception
  266. // avec info diverses + qte a livrer
  267. if ($object->origin == "supplierorder") {
  268. $classname = 'CommandeFournisseur';
  269. } else {
  270. $classname = ucfirst($object->origin);
  271. }
  272. $objectsrc = new $classname($db);
  273. $objectsrc->fetch($object->origin_id);
  274. $object->socid = $objectsrc->socid;
  275. $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
  276. $object->model_pdf = GETPOST('model');
  277. $object->date_delivery = $date_delivery; // Date delivery planed
  278. $object->fk_delivery_address = $objectsrc->fk_delivery_address;
  279. $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
  280. $object->tracking_number = GETPOST('tracking_number', 'alpha');
  281. $object->note_private = GETPOST('note_private', 'restricthtml');
  282. $object->note_public = GETPOST('note_public', 'restricthtml');
  283. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  284. $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
  285. $batch_line = array();
  286. $stockLine = array();
  287. $array_options = array();
  288. $totalqty = 0;
  289. $num = 0;
  290. foreach ($_POST as $key => $value) {
  291. // without batch module enabled
  292. if (strpos($key, 'qtyasked') !== false) {
  293. $num++;
  294. }
  295. }
  296. // Loop lines to calculate $totalqty
  297. for ($i = 1; $i <= $num; $i++) {
  298. $idl = "idl".$i; // id line source
  299. //$sub_qty = array();
  300. //$subtotalqty = 0;
  301. //$j = 0;
  302. //$batch = "batchl".$i."_0";
  303. //$stockLocation = "ent1".$i."_0";
  304. $qty = "qtyl".$i; // qty
  305. //reception line for product with no batch management and no multiple stock location
  306. if (GETPOST($qty, 'alpha') > 0) {
  307. $totalqty += price2num(GETPOST($qty, 'alpha'), 'MS');
  308. }
  309. // Extrafields
  310. $array_options[$i] = $extrafields->getOptionalsFromPost($object->table_element_line, $i);
  311. }
  312. if ($totalqty > 0) { // There is at least one thing to ship
  313. for ($i = 1; $i <= $num; $i++) {
  314. $idl = "idl".$i; // id line source
  315. $lineToTest = '';
  316. $lineId = GETPOST($idl, 'int');
  317. foreach ($objectsrc->lines as $linesrc) {
  318. if ($linesrc->id == $lineId) {
  319. $lineToTest = $linesrc;
  320. break;
  321. }
  322. }
  323. if (empty($lineToTest)) {
  324. continue;
  325. }
  326. $qty = "qtyl".$i;
  327. $comment = "comment".$i;
  328. // EATBY <-> DLUO and SELLBY <-> DLC, see productbatch.class.php
  329. $eatby = "dluo".$i;
  330. $sellby = "dlc".$i;
  331. $batch = "batch".$i;
  332. $cost_price = "cost_price".$i;
  333. //var_dump(GETPOST("productl".$i, 'int').' '.GETPOST('entl'.$i, 'int').' '.GETPOST($idl, 'int').' '.GETPOST($qty, 'int').' '.GETPOST($batch, 'alpha'));
  334. //if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS')) || (GETPOST($qty, 'int') < 0 && getDolGlobalString('RECEPTION_ALLOW_NEGATIVE_QTY'))) {
  335. if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS'))) {
  336. $ent = "entl".$i;
  337. $idl = "idl".$i;
  338. $entrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int');
  339. /*
  340. if (!empty($lineToTest)) {
  341. $fk_product = $lineToTest->fk_product;
  342. } else {
  343. $fk_product = $linesrc->fk_product;
  344. }*/
  345. $fk_product = GETPOST("productl".$i, 'int');
  346. if ($entrepot_id < 0) {
  347. $entrepot_id = '';
  348. }
  349. if (!($fk_product > 0) && !getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
  350. $entrepot_id = 0;
  351. }
  352. $eatby = GETPOST($eatby, 'alpha');
  353. $sellby = GETPOST($sellby, 'alpha');
  354. $eatbydate = str_replace('/', '-', $eatby);
  355. $sellbydate = str_replace('/', '-', $sellby);
  356. if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
  357. $ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'), price2num(GETPOST($cost_price, 'double'), 'MU'));
  358. } else {
  359. $ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch, 'alpha'));
  360. }
  361. if ($ret < 0) {
  362. setEventMessages($object->error, $object->errors, 'errors');
  363. $error++;
  364. }
  365. }
  366. }
  367. // Fill array 'array_options' with data from add form
  368. $ret = $extrafields->setOptionalsFromPost(null, $object);
  369. if ($ret < 0) {
  370. $error++;
  371. }
  372. if (!$error) {
  373. $ret = $object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
  374. if ($ret <= 0) {
  375. setEventMessages($object->error, $object->errors, 'errors');
  376. $error++;
  377. }
  378. }
  379. } else {
  380. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
  381. $error++;
  382. }
  383. if (!$error) {
  384. $db->commit();
  385. header("Location: card.php?id=".$object->id);
  386. exit;
  387. } else {
  388. $db->rollback();
  389. $_GET["commande_id"] = GETPOST('commande_id', 'int');
  390. $action = 'create';
  391. }
  392. } elseif ($action == 'confirm_valid' && $confirm == 'yes' && $permissiontovalidate) {
  393. $object->fetch_thirdparty();
  394. $result = $object->valid($user);
  395. if ($result < 0) {
  396. $langs->load("errors");
  397. setEventMessages($langs->trans($object->error), null, 'errors');
  398. } else {
  399. // Define output language
  400. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  401. $outputlangs = $langs;
  402. $newlang = '';
  403. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  404. $newlang = GETPOST('lang_id', 'aZ09');
  405. }
  406. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  407. $newlang = $object->thirdparty->default_lang;
  408. }
  409. if (!empty($newlang)) {
  410. $outputlangs = new Translate("", $conf);
  411. $outputlangs->setDefaultLang($newlang);
  412. }
  413. $model = $object->model_pdf;
  414. $ret = $object->fetch($id); // Reload to get new records
  415. $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  416. if ($result < 0) {
  417. dol_print_error($db, $result);
  418. }
  419. }
  420. }
  421. } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
  422. $result = $object->delete($user);
  423. if ($result > 0) {
  424. header("Location: ".DOL_URL_ROOT.'/reception/index.php');
  425. exit;
  426. } else {
  427. setEventMessages($object->error, $object->errors, 'errors');
  428. }
  429. // TODO add alternative status
  430. /*} elseif ($action == 'reopen' && (!empty($user->rights->reception->creer) || !empty($user->rights->reception->reception_advance->validate))) {
  431. $result = $object->setStatut(0);
  432. if ($result < 0) {
  433. setEventMessages($object->error, $object->errors, 'errors');
  434. }*/
  435. } elseif ($action == 'setdate_livraison' && $permissiontoadd) {
  436. $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));
  437. $object->fetch($id);
  438. $result = $object->setDeliveryDate($user, $datedelivery);
  439. if ($result < 0) {
  440. setEventMessages($object->error, $object->errors, 'errors');
  441. }
  442. } elseif ($action == 'settracking_number' || $action == 'settracking_url'
  443. || $action == 'settrueWeight'
  444. || $action == 'settrueWidth'
  445. || $action == 'settrueHeight'
  446. || $action == 'settrueDepth'
  447. || $action == 'setshipping_method_id') {
  448. // Action update
  449. $error = 0;
  450. if ($action == 'settracking_number') {
  451. $object->tracking_number = trim(GETPOST('tracking_number', 'alpha'));
  452. }
  453. if ($action == 'settracking_url') {
  454. $object->tracking_url = trim(GETPOST('tracking_url', 'int'));
  455. }
  456. if ($action == 'settrueWeight') {
  457. $object->trueWeight = trim(GETPOST('trueWeight', 'int'));
  458. $object->weight_units = GETPOST('weight_units', 'int');
  459. }
  460. if ($action == 'settrueWidth') {
  461. $object->trueWidth = trim(GETPOST('trueWidth', 'int'));
  462. }
  463. if ($action == 'settrueHeight') {
  464. $object->trueHeight = trim(GETPOST('trueHeight', 'int'));
  465. $object->size_units = GETPOST('size_units', 'int');
  466. }
  467. if ($action == 'settrueDepth') {
  468. $object->trueDepth = trim(GETPOST('trueDepth', 'int'));
  469. }
  470. if ($action == 'setshipping_method_id') {
  471. $object->shipping_method_id = trim(GETPOST('shipping_method_id', 'int'));
  472. }
  473. if (!$error) {
  474. if ($object->update($user) >= 0) {
  475. header("Location: card.php?id=".$object->id);
  476. exit;
  477. }
  478. setEventMessages($object->error, $object->errors, 'errors');
  479. }
  480. $action = "";
  481. } elseif ($action == 'builddoc' && $permissiontoread) {
  482. // Build document
  483. // En get ou en post
  484. // Save last template used to generate document
  485. if (GETPOST('model')) {
  486. $object->setDocModel($user, GETPOST('model', 'alpha'));
  487. }
  488. // Define output language
  489. $outputlangs = $langs;
  490. $newlang = '';
  491. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  492. $newlang = GETPOST('lang_id', 'aZ09');
  493. }
  494. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  495. $newlang = $reception->thirdparty->default_lang;
  496. }
  497. if (!empty($newlang)) {
  498. $outputlangs = new Translate("", $conf);
  499. $outputlangs->setDefaultLang($newlang);
  500. }
  501. $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  502. if ($result <= 0) {
  503. setEventMessages($object->error, $object->errors, 'errors');
  504. $action = '';
  505. }
  506. } elseif ($action == 'remove_file' && $permissiontoadd) {
  507. // Delete file in doc form
  508. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  509. $upload_dir = $conf->reception->dir_output;
  510. $file = $upload_dir.'/'.GETPOST('file');
  511. $ret = dol_delete_file($file, 0, 0, 0, $object);
  512. if ($ret) {
  513. setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  514. } else {
  515. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  516. }
  517. } elseif ($action == 'classifybilled') {
  518. $result = $object->setBilled();
  519. if ($result >= 0) {
  520. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  521. exit();
  522. } else {
  523. setEventMessages($object->error, $object->errors, 'errors');
  524. $action = '';
  525. }
  526. } elseif ($action == 'classifyclosed' && $permissiontoread) {
  527. $result = $object->setClosed();
  528. if ($result >= 0) {
  529. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  530. exit();
  531. } else {
  532. setEventMessages($object->error, $object->errors, 'errors');
  533. $action = '';
  534. }
  535. } elseif ($action == 'deleteline' && !empty($line_id) && $permissiontoread) {
  536. // delete a line
  537. $lines = $object->lines;
  538. $line = new CommandeFournisseurDispatch($db);
  539. $num_prod = count($lines);
  540. for ($i = 0; $i < $num_prod; $i++) {
  541. if ($lines[$i]->id == $line_id) {
  542. // delete single warehouse line
  543. $line->id = $line_id;
  544. if (!$error && $line->delete($user) < 0) {
  545. $error++;
  546. }
  547. }
  548. unset($_POST["lineid"]);
  549. }
  550. if (!$error) {
  551. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  552. exit();
  553. } else {
  554. setEventMessages($line->error, $line->errors, 'errors');
  555. }
  556. } elseif ($action == 'updateline' && GETPOST('save') && $permissiontoadd) {
  557. // Update a line
  558. // Clean parameters
  559. $qty = 0;
  560. $entrepot_id = 0;
  561. $batch_id = 0;
  562. $lines = $object->lines;
  563. $num_prod = count($lines);
  564. for ($i = 0; $i < $num_prod; $i++) {
  565. if ($lines[$i]->id == $line_id) { // we have found line to update
  566. $line = new CommandeFournisseurDispatch($db);
  567. $line->fetch($line_id);
  568. // Extrafields Lines
  569. $extrafields->fetch_name_optionals_label($object->table_element_line);
  570. $line->array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
  571. $line->fk_product = $lines[$i]->fk_product;
  572. if ($lines[$i]->fk_product > 0) {
  573. // single warehouse reception line
  574. $stockLocation = "entl".$line_id;
  575. $qty = "qtyl".$line_id;
  576. $comment = "comment".$line_id;
  577. $line->id = $line_id;
  578. $line->fk_entrepot = GETPOST($stockLocation, 'int');
  579. $line->qty = GETPOST($qty, 'int');
  580. $line->comment = GETPOST($comment, 'alpha');
  581. if (isModEnabled('productbatch')) {
  582. $batch = "batch".$line_id;
  583. $dlc = "dlc".$line_id;
  584. $dluo = "dluo".$line_id;
  585. // EATBY <-> DLUO
  586. $eatby = GETPOST($dluo, 'alpha');
  587. $eatbydate = str_replace('/', '-', $eatby);
  588. // SELLBY <-> DLC
  589. $sellby = GETPOST($dlc, 'alpha');
  590. $sellbydate = str_replace('/', '-', $sellby);
  591. $line->batch = GETPOST($batch, 'alpha');
  592. $line->eatby = strtotime($eatbydate);
  593. $line->sellby = strtotime($sellbydate);
  594. }
  595. if ($line->update($user) < 0) {
  596. setEventMessages($line->error, $line->errors, 'errors');
  597. $error++;
  598. }
  599. } else { // Product no predefined
  600. $qty = "qtyl".$line_id;
  601. $line->id = $line_id;
  602. $line->qty = GETPOST($qty, 'int');
  603. $line->fk_entrepot = 0;
  604. if ($line->update($user) < 0) {
  605. setEventMessages($line->error, $line->errors, 'errors');
  606. $error++;
  607. }
  608. unset($_POST[$qty]);
  609. }
  610. }
  611. }
  612. unset($_POST["lineid"]);
  613. if (!$error) {
  614. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  615. // Define output language
  616. $outputlangs = $langs;
  617. $newlang = '';
  618. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  619. $newlang = GETPOST('lang_id', 'aZ09');
  620. }
  621. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  622. $newlang = $object->thirdparty->default_lang;
  623. }
  624. if (!empty($newlang)) {
  625. $outputlangs = new Translate("", $conf);
  626. $outputlangs->setDefaultLang($newlang);
  627. }
  628. $ret = $object->fetch($object->id); // Reload to get new records
  629. $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  630. }
  631. } else {
  632. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To reshow the record we edit
  633. exit();
  634. }
  635. } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
  636. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To reshow the record we edit
  637. exit();
  638. }
  639. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  640. // Actions to send emails
  641. if (empty($id)) {
  642. $id = $facid;
  643. }
  644. $triggersendname = 'RECEPTION_SENTBYMAIL';
  645. $paramname = 'id';
  646. $mode = 'emailfromreception';
  647. $autocopy = 'MAIN_MAIL_AUTOCOPY_RECEPTION_TO';
  648. $trackid = 'rec'.$object->id;
  649. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  650. }
  651. /*
  652. * View
  653. */
  654. $title = $object->ref.' - '.$langs->trans('Reception');
  655. llxHeader('', $title, 'Reception');
  656. $form = new Form($db);
  657. $formfile = new FormFile($db);
  658. $formproduct = new FormProduct($db);
  659. if (isModEnabled('project')) {
  660. $formproject = new FormProjets($db);
  661. }
  662. $product_static = new Product($db);
  663. $reception_static = new Reception($db);
  664. $warehousestatic = new Entrepot($db);
  665. if ($action == 'create2') {
  666. print load_fiche_titre($langs->trans("CreateReception"), '', 'dollyrevert');
  667. print '<br>'.$langs->trans("ReceptionCreationIsDoneFromOrder");
  668. $action = '';
  669. $id = '';
  670. $ref = '';
  671. }
  672. // Mode creation.
  673. if ($action == 'create') {
  674. $recept = new Reception($db);
  675. print load_fiche_titre($langs->trans("CreateReception"));
  676. if (!$origin) {
  677. setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors');
  678. }
  679. if ($origin) {
  680. if ($origin == 'supplierorder') {
  681. $classname = 'CommandeFournisseur';
  682. } else {
  683. $classname = ucfirst($origin);
  684. }
  685. $objectsrc = new $classname($db);
  686. if ($objectsrc->fetch($origin_id)) { // This include the fetch_lines
  687. $soc = new Societe($db);
  688. $soc->fetch($objectsrc->socid);
  689. $author = new User($db);
  690. $author->fetch($objectsrc->user_author_id);
  691. if (isModEnabled('stock')) {
  692. $entrepot = new Entrepot($db);
  693. }
  694. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  695. print '<input type="hidden" name="token" value="'.newToken().'">';
  696. print '<input type="hidden" name="action" value="add">';
  697. print '<input type="hidden" name="origin" value="'.$origin.'">';
  698. print '<input type="hidden" name="origin_id" value="'.$objectsrc->id.'">';
  699. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  700. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  701. if (GETPOST('entrepot_id', 'int')) {
  702. print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id', 'int').'">';
  703. }
  704. print dol_get_fiche_head('');
  705. print '<table class="border centpercent">';
  706. // Ref
  707. print '<tr><td class="titlefieldcreate fieldrequired">';
  708. if ($origin == 'supplierorder' && isModEnabled("supplier_order")) {
  709. print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$objectsrc->id.'">'.img_object($langs->trans("ShowOrder"), 'order').' '.$objectsrc->ref;
  710. }
  711. if ($origin == 'propal' && isModEnabled("propal")) {
  712. print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/card.php?id='.$objectsrc->id.'">'.img_object($langs->trans("ShowProposal"), 'propal').' '.$objectsrc->ref;
  713. }
  714. print '</a></td>';
  715. print "</tr>\n";
  716. // Ref client
  717. print '<tr><td>';
  718. if ($origin == 'supplier_order') {
  719. print $langs->trans('SupplierOrder');
  720. } else {
  721. print $langs->trans('RefSupplier');
  722. }
  723. print '</td><td colspan="3">';
  724. print '<input type="text" name="ref_supplier" value="'.$objectsrc->ref_supplier.'" />';
  725. print '</td>';
  726. print '</tr>';
  727. // Tiers
  728. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Company').'</td>';
  729. print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
  730. print '</tr>';
  731. // Project
  732. if (isModEnabled('project')) {
  733. $projectid = GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : 0;
  734. if (empty($projectid) && !empty($objectsrc->fk_project)) {
  735. $projectid = $objectsrc->fk_project;
  736. }
  737. if ($origin == 'project') {
  738. $projectid = ($originid ? $originid : 0);
  739. }
  740. $langs->load("projects");
  741. print '<tr>';
  742. print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
  743. print img_picto('', 'project', 'class="paddingright"');
  744. print $formproject->select_projects((!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1, 0, 'maxwidth500');
  745. print ' &nbsp; <a 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" title="'.$langs->trans("AddProject").'"></span></a>';
  746. print '</td>';
  747. print '</tr>';
  748. }
  749. // Date delivery planned
  750. print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
  751. print '<td colspan="3">';
  752. $date_delivery = ($date_delivery ? $date_delivery : $objectsrc->delivery_date); // $date_delivery comes from GETPOST
  753. print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
  754. print "</td>\n";
  755. print '</tr>';
  756. // Note Public
  757. print '<tr><td>'.$langs->trans("NotePublic").'</td>';
  758. print '<td colspan="3">';
  759. $doleditor = new DolEditor('note_public', $objectsrc->note_public, '', 60, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
  760. print $doleditor->Create(1);
  761. print "</td></tr>";
  762. // Note Private
  763. if ($objectsrc->note_private && !$user->socid) {
  764. print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
  765. print '<td colspan="3">';
  766. $doleditor = new DolEditor('note_private', $objectsrc->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
  767. print $doleditor->Create(1);
  768. print "</td></tr>";
  769. }
  770. // Weight
  771. print '<tr><td>';
  772. print $langs->trans("Weight");
  773. print '</td><td colspan="3"><input name="weight" size="4" value="'.GETPOST('weight', 'int').'"> ';
  774. $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units', 'int'), 0, 2);
  775. $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
  776. print $form->textwithpicto($text, $htmltext);
  777. print '</td></tr>';
  778. // Dim
  779. print '<tr><td>';
  780. print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");
  781. print ' </td><td colspan="3"><input name="trueWidth" size="4" value="'.GETPOST('trueWidth', 'int').'">';
  782. print ' x <input name="trueHeight" size="4" value="'.GETPOST('trueHeight', 'int').'">';
  783. print ' x <input name="trueDepth" size="4" value="'.GETPOST('trueDepth', 'int').'">';
  784. print ' ';
  785. $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units', 'int'), 0, 2);
  786. $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
  787. print $form->textwithpicto($text, $htmltext);
  788. print '</td></tr>';
  789. // Delivery method
  790. print "<tr><td>".$langs->trans("ReceptionMethod")."</td>";
  791. print '<td colspan="3">';
  792. $recept->fetch_delivery_methods();
  793. print $form->selectarray("shipping_method_id", $recept->meths, GETPOST('shipping_method_id', 'int'), 1, 0, 0, "", 1);
  794. if ($user->admin) {
  795. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  796. }
  797. print "</td></tr>\n";
  798. // Tracking number
  799. print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
  800. print '<td colspan="3">';
  801. print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';
  802. print "</td></tr>\n";
  803. // Other attributes
  804. $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'cols' => '3', 'socid'=>$socid);
  805. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $recept, $action); // Note that $action and $objectsrc may have been modified by hook
  806. print $hookmanager->resPrint;
  807. // Here $object can be of an object Reception
  808. $extrafields->fetch_name_optionals_label($object->table_element);
  809. if (empty($reshook) && !empty($extrafields->attributes[$object->table_element]['label'])) {
  810. // copy from order
  811. if ($objectsrc->fetch_optionals() > 0) {
  812. $recept->array_options = array_merge($recept->array_options, $objectsrc->array_options);
  813. }
  814. print $recept->showOptionals($extrafields, 'create', $parameters);
  815. }
  816. // Incoterms
  817. if (isModEnabled('incoterm')) {
  818. print '<tr>';
  819. print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $objectsrc->label_incoterms, 1).'</label></td>';
  820. print '<td colspan="3" class="maxwidthonsmartphone">';
  821. print $form->select_incoterms((!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : ''), (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : ''));
  822. print '</td></tr>';
  823. }
  824. // Document model
  825. include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
  826. $list = ModelePdfReception::liste_modeles($db);
  827. if (count($list) > 1) {
  828. print "<tr><td>".$langs->trans("DefaultModel")."</td>";
  829. print '<td colspan="3">';
  830. print $form->selectarray('model', $list, $conf->global->RECEPTION_ADDON_PDF);
  831. print "</td></tr>\n";
  832. }
  833. print "</table>";
  834. print dol_get_fiche_end();
  835. // Number of lines show on the reception card
  836. $numAsked = 0;
  837. /**
  838. * @var array $suffix2numAsked map HTTP query parameter suffixes (like '1_0') to line indices so that
  839. * extrafields from HTTP query can be assigned to the correct dispatch line
  840. */
  841. $suffix2numAsked = array();
  842. $dispatchLines = array();
  843. foreach ($_POST as $key => $value) {
  844. // If create form is coming from the button "Create Reception" of previous page
  845. // without batch module enabled or product with no lot/serial
  846. $reg = array();
  847. if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
  848. $numAsked++;
  849. $paramSuffix = $reg[1] . '_' . $reg[2];
  850. $suffix2numAsked[$paramSuffix] = $numAsked;
  851. // $numline=$reg[2] + 1; // line of product
  852. $numline = $numAsked;
  853. $prod = "product_" . $paramSuffix;
  854. $qty = "qty_" . $paramSuffix;
  855. $ent = "entrepot_" . $paramSuffix;
  856. $pu = "pu_" . $paramSuffix; // This is unit price including discount
  857. $fk_commandefourndet = "fk_commandefourndet_" . $paramSuffix;
  858. $dispatchLines[$numAsked] = array('paramSuffix'=>$paramSuffix, 'prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'));
  859. }
  860. // with batch module enabled and product with lot/serial
  861. if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
  862. $numAsked++;
  863. $paramSuffix = $reg[1] . '_' . $reg[2];
  864. $suffix2numAsked[$paramSuffix] = $numAsked;
  865. // eat-by date dispatch
  866. // $numline=$reg[2] + 1; // line of product
  867. $numline = $numAsked;
  868. $prod = 'product_batch_' . $paramSuffix;
  869. $qty = 'qty_' . $paramSuffix;
  870. $ent = 'entrepot_' . $paramSuffix;
  871. $pu = 'pu_' . $paramSuffix;
  872. $lot = 'lot_number_' . $paramSuffix;
  873. $dDLUO = dol_mktime(12, 0, 0, GETPOST('dluo_'.$paramSuffix.'month', 'int'), GETPOST('dluo_'.$paramSuffix.'day', 'int'), GETPOST('dluo_'.$paramSuffix.'year', 'int'));
  874. $dDLC = dol_mktime(12, 0, 0, GETPOST('dlc_'.$paramSuffix.'month', 'int'), GETPOST('dlc_'.$paramSuffix.'day', 'int'), GETPOST('dlc_'.$paramSuffix.'year', 'int'));
  875. $fk_commandefourndet = 'fk_commandefourndet_'.$paramSuffix;
  876. $dispatchLines[$numAsked] = array('paramSuffix'=>$paramSuffix, 'prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha'));
  877. }
  878. // If create form is coming from same page, it means that post was sent but an error occured
  879. if (preg_match('/^productl([0-9]+)$/i', $key, $reg)) {
  880. $numAsked++;
  881. $paramSuffix = $reg[1];
  882. $suffix2numAsked[$paramSuffix] = $numAsked;
  883. // eat-by date dispatch
  884. // $numline=$reg[2] + 1; // line of product
  885. $numline = $numAsked;
  886. $prod = 'productid'.$paramSuffix;
  887. $comment = 'comment'.$paramSuffix;
  888. $qty = 'qtyl'.$paramSuffix;
  889. $ent = 'entl'.$paramSuffix;
  890. $pu = 'pul'.$paramSuffix;
  891. $lot = 'batch'.$paramSuffix;
  892. $dDLUO = dol_mktime(12, 0, 0, GETPOST('dluo'.$paramSuffix.'month', 'int'), GETPOST('dluo'.$paramSuffix.'day', 'int'), GETPOST('dluo'.$paramSuffix.'year', 'int'));
  893. $dDLC = dol_mktime(12, 0, 0, GETPOST('dlc'.$paramSuffix.'month', 'int'), GETPOST('dlc'.$paramSuffix.'day', 'int'), GETPOST('dlc'.$paramSuffix.'year', 'int'));
  894. $fk_commandefourndet = 'fk_commandefournisseurdet'.$paramSuffix;
  895. $dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' =>GETPOST($ent, 'int'), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' =>GETPOST($comment), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha'));
  896. }
  897. }
  898. // If extrafield values are passed in the HTTP query, assign them to the correct dispatch line
  899. // Note that if an extrafield with the same name exists in the origin supplier order line, the value
  900. // from the HTTP query will be ignored
  901. foreach ($suffix2numAsked as $suffix => $n) {
  902. $dispatchLines[$n]['array_options'] = $extrafields->getOptionalsFromPost('commande_fournisseur_dispatch', '_' . $suffix, '');
  903. }
  904. print '<script type="text/javascript">
  905. jQuery(document).ready(function() {
  906. jQuery("#autofill").click(function(event) {
  907. event.preventDefault();';
  908. $i = 1;
  909. while ($i <= $numAsked) {
  910. print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
  911. $i++;
  912. }
  913. print '});
  914. jQuery("#autoreset").click(function(event) {
  915. event.preventDefault();';
  916. $i = 1;
  917. while ($i <= $numAsked) {
  918. print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
  919. $i++;
  920. }
  921. print '});
  922. });
  923. </script>';
  924. print '<br>';
  925. print '<table class="noborder centpercent">';
  926. // Load receptions already done for same order
  927. $objectsrc->loadReceptions();
  928. if ($numAsked) {
  929. print '<tr class="liste_titre">';
  930. print '<td>'.$langs->trans("Description").'</td>';
  931. print '<td>'.$langs->trans("Comment").'</td>';
  932. print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
  933. print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
  934. print '<td class="center">'.$langs->trans("QtyToReceive");
  935. if (getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
  936. print '<td>'.$langs->trans("BuyingPrice").'</td>';
  937. }
  938. if (!isModEnabled('productbatch')) {
  939. print ' <br><center><a href="#" id="autofill"><span class="fas fa-fill pictofixedwidth" style=""></span> '.$langs->trans("Fill").'</a>';
  940. print ' &nbsp; &nbsp; <a href="#" id="autoreset"><span class="fas fa-eraser pictofixedwidth" style=""></span>'.$langs->trans("Reset").'</a></center><br>';
  941. }
  942. print '</td>';
  943. if (isModEnabled('stock')) {
  944. print '<td class="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
  945. }
  946. if (isModEnabled('productbatch')) {
  947. print '<td class="left">'.$langs->trans("batch_number").'</td>';
  948. if (!getDolGlobalInt('PRODUCT_DISABLE_SELLBY')) {
  949. print '<td class="left">'.$langs->trans("SellByDate").'</td>';
  950. }
  951. if (!getDolGlobalInt('PRODUCT_DISABLE_EATBY')) {
  952. print '<td class="left">'.$langs->trans("EatByDate").'</td>';
  953. }
  954. }
  955. print "</tr>\n";
  956. }
  957. // $objectsrc->lines contains the line of the purchase order
  958. // $dispatchLines is list of lines with dispatching detail (with product, qty and warehouse). One purchase order line may have n of this dispatch lines.
  959. $arrayofpurchaselinealreadyoutput= array();
  960. // $_POST contains fk_commandefourndet_X_Y where Y is num of product line and X is number of splitted line
  961. $indiceAsked = 1;
  962. while ($indiceAsked <= $numAsked) { // Loop on $dispatchLines. Warning: $dispatchLines must be sorted by fk_commandefourndet (it is a regroupment key on output)
  963. $product = new Product($db);
  964. // We search the purchase order line that is linked to the dispatchLines
  965. foreach ($objectsrc->lines as $supplierLine) {
  966. if ($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id) {
  967. $line = $supplierLine;
  968. break;
  969. }
  970. }
  971. // Show product and description
  972. $type = $line->product_type ? $line->product_type : $line->fk_product_type;
  973. // Try to enhance type detection using date_start and date_end for free lines where type
  974. // was not saved.
  975. if (!empty($line->date_start)) {
  976. $type = 1;
  977. }
  978. if (!empty($line->date_end)) {
  979. $type = 1;
  980. }
  981. print '<!-- line fk_commandefourndet='.$line->id.' for product='.$line->fk_product.' -->'."\n";
  982. print '<tr class="oddeven">'."\n";
  983. // Product label
  984. if ($line->fk_product > 0) { // If predefined product
  985. $product->fetch($line->fk_product);
  986. $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
  987. //var_dump($product->stock_warehouse[1]);
  988. //var_dump($dispatchLines[$indiceAsked]);
  989. print '<td>';
  990. print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
  991. print '<input type="hidden" name="productl'.$indiceAsked.'" value="'.$line->fk_product.'">';
  992. if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
  993. print '<input type="hidden" name="productid'.$indiceAsked.'" value="'.$line->fk_product.'">';
  994. // Show product and description
  995. $product_static = $product;
  996. $text = $product_static->getNomUrl(1);
  997. $text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label);
  998. $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($line->desc));
  999. print $form->textwithtooltip($text, $description, 3, '', '', $i);
  1000. // Show range
  1001. print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
  1002. // Add description in form
  1003. if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
  1004. print ($line->desc && $line->desc != $line->product_label) ? '<br>'.dol_htmlentitiesbr($line->desc) : '';
  1005. }
  1006. }
  1007. print '</td>';
  1008. } else {
  1009. print "<td>";
  1010. if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
  1011. if ($type == 1) {
  1012. $text = img_object($langs->trans('Service'), 'service');
  1013. } else {
  1014. $text = img_object($langs->trans('Product'), 'product');
  1015. }
  1016. if (!empty($line->label)) {
  1017. $text .= ' <strong>'.$line->label.'</strong>';
  1018. print $form->textwithtooltip($text, $line->desc, 3, '', '', $i);
  1019. } else {
  1020. print $text.' '.nl2br($line->desc);
  1021. }
  1022. // Show range
  1023. print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
  1024. }
  1025. print "</td>\n";
  1026. }
  1027. // Comment
  1028. //$defaultcomment = 'Line create from order line id '.$line->id;
  1029. $defaultcomment = $dispatchLines[$indiceAsked]['comment'];
  1030. print '<td>';
  1031. print '<input type="text" class="maxwidth100" name="comment'.$indiceAsked.'" value="'.$defaultcomment.'">';
  1032. print '</td>';
  1033. // Qty in source purchase order line
  1034. print '<td class="center">';
  1035. if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
  1036. print $line->qty;
  1037. }
  1038. print '<input type="hidden" name="fk_commandefournisseurdet'.$indiceAsked.'" value="'.$line->id.'">';
  1039. print '<input type="hidden" name="pul'.$indiceAsked.'" value="'.$line->pu_ht.'">';
  1040. print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
  1041. print '</td>';
  1042. $qtyProdCom = $line->qty;
  1043. // Qty already received
  1044. print '<td class="center">';
  1045. $quantityDelivered = $objectsrc->receptions[$line->id];
  1046. if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
  1047. print $quantityDelivered;
  1048. }
  1049. print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
  1050. print '</td>';
  1051. if ($line->product_type == 1 && !getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
  1052. $quantityToBeDelivered = 0;
  1053. } else {
  1054. $quantityToBeDelivered = $dispatchLines[$indiceAsked]['qty'];
  1055. }
  1056. $warehouse_id = $dispatchLines[$indiceAsked]['ent'];
  1057. $warehouseObject = null;
  1058. if (isModEnabled('stock')) {
  1059. // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
  1060. print '<!-- Case warehouse already known or product not a predefined product -->';
  1061. if (array_key_exists($dispatchLines[$indiceAsked]['ent'], $product->stock_warehouse)) {
  1062. $stock = +$product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
  1063. }
  1064. $deliverableQty = $dispatchLines[$indiceAsked]['qty'];
  1065. $cost_price = $dispatchLines[$indiceAsked]['pu'];
  1066. // Quantity to send
  1067. print '<td class="center">';
  1068. if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
  1069. if (GETPOST('qtyl'.$indiceAsked, 'int')) {
  1070. $defaultqty = GETPOST('qtyl'.$indiceAsked, 'int');
  1071. }
  1072. print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
  1073. print '<input class="right" name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
  1074. } else {
  1075. print $langs->trans("NA");
  1076. }
  1077. print '</td>';
  1078. if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
  1079. print '<td>';
  1080. print '<input class="width75 right" name="cost_price'.$indiceAsked.'" id="cost_price'.$indiceAsked.'" value="'.$cost_price.'">';
  1081. print '</td>';
  1082. }
  1083. // Stock
  1084. if (isModEnabled('stock')) {
  1085. print '<td class="left">';
  1086. if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { // Type of product need stock change ?
  1087. // Show warehouse combo list
  1088. $ent = "entl".$indiceAsked;
  1089. $idl = "idl".$indiceAsked;
  1090. $tmpentrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : $warehouse_id;
  1091. if ($line->fk_product > 0) {
  1092. print '<!-- Show warehouse selection -->';
  1093. print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 0, 0, $line->fk_product, '', 1);
  1094. }
  1095. } else {
  1096. print $langs->trans("Service");
  1097. }
  1098. print '</td>';
  1099. }
  1100. if (isModEnabled('productbatch')) {
  1101. if (!empty($product->status_batch)) {
  1102. print '<td><input name="batch'.$indiceAsked.'" value="'.$dispatchLines[$indiceAsked]['lot'].'"></td>';
  1103. if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
  1104. print '<td class="nowraponall">';
  1105. print $form->selectDate($dispatchLines[$indiceAsked]['DLC'], 'dlc'.$indiceAsked, '', '', 1, "");
  1106. print '</td>';
  1107. }
  1108. if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
  1109. print '<td class="nowraponall">';
  1110. print $form->selectDate($dispatchLines[$indiceAsked]['DLUO'], 'dluo'.$indiceAsked, '', '', 1, "");
  1111. print '</td>';
  1112. }
  1113. } else {
  1114. print '<td colspan="3"></td>';
  1115. }
  1116. }
  1117. }
  1118. $arrayofpurchaselinealreadyoutput[$line->id] = $line->id;
  1119. print "</tr>\n";
  1120. // Display lines for extrafields of the Reception line
  1121. // $line is a 'CommandeFournisseurLigne', $dispatchLines contains values of Reception lines so properties of CommandeFournisseurDispatch
  1122. if (!empty($extrafields)) {
  1123. $colspan = 5;
  1124. if (isModEnabled('productbatch')) {
  1125. $colspan += 2;
  1126. if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
  1127. $colspan += 1;
  1128. }
  1129. if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
  1130. $colspan += 1;
  1131. }
  1132. }
  1133. $recLine = new CommandeFournisseurDispatch($db);
  1134. $srcLine = new CommandeFournisseurLigne($db);
  1135. $srcLine->id = $line->id;
  1136. $srcLine->fetch_optionals(); // fetch extrafields also available in orderline
  1137. if (empty($recLine->array_options) && !empty($dispatchLines[$indiceAsked]['array_options'])) {
  1138. $recLine->array_options = $dispatchLines[$indiceAsked]['array_options'];
  1139. }
  1140. $recLine->array_options = array_merge($recLine->array_options, $srcLine->array_options);
  1141. print $recLine->showOptionals($extrafields, 'edit', array('style'=>'class="oddeven"', 'colspan'=>$colspan), $indiceAsked, '', 1);
  1142. }
  1143. $indiceAsked++;
  1144. }
  1145. print "</table>";
  1146. print '<br>';
  1147. print $form->buttonsSaveCancel("Create");
  1148. print '</form>';
  1149. print '<br>';
  1150. } else {
  1151. dol_print_error($db);
  1152. }
  1153. }
  1154. } elseif ($id || $ref) {
  1155. /* *************************************************************************** */
  1156. /* */
  1157. /* Edit and view mode */
  1158. /* */
  1159. /* *************************************************************************** */
  1160. $lines = $object->lines;
  1161. $num_prod = count($lines);
  1162. $indiceAsked = 0;
  1163. if ($object->id <= 0) {
  1164. print $langs->trans("NoRecordFound");
  1165. llxFooter();
  1166. exit;
  1167. }
  1168. if (!empty($object->origin) && $object->origin_id > 0) {
  1169. $object->origin = 'CommandeFournisseur';
  1170. $typeobject = $object->origin;
  1171. $origin = $object->origin;
  1172. $origin_id = $object->origin_id;
  1173. $object->fetch_origin(); // Load property $object->commande, $object->propal, ...
  1174. }
  1175. $soc = new Societe($db);
  1176. $soc->fetch($object->socid);
  1177. $res = $object->fetch_optionals();
  1178. $head = reception_prepare_head($object);
  1179. print dol_get_fiche_head($head, 'reception', $langs->trans("Reception"), -1, 'dollyrevert');
  1180. $formconfirm = '';
  1181. // Confirm deleteion
  1182. if ($action == 'delete') {
  1183. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteReception'), $langs->trans("ConfirmDeleteReception", $object->ref), 'confirm_delete', '', 0, 1);
  1184. }
  1185. // Confirmation validation
  1186. if ($action == 'valid') {
  1187. $objectref = substr($object->ref, 1, 4);
  1188. if ($objectref == 'PROV') {
  1189. $numref = $object->getNextNumRef($soc);
  1190. } else {
  1191. $numref = $object->ref;
  1192. }
  1193. $text = $langs->trans("ConfirmValidateReception", $numref);
  1194. if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION')) {
  1195. $text .= '<br>'.img_picto('', 'movement', 'class="pictofixedwidth"').$langs->trans("StockMovementWillBeRecorded").'.';
  1196. } elseif (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
  1197. $text .= '<br>'.img_picto('', 'movement', 'class="pictofixedwidth"').$langs->trans("StockMovementNotYetRecorded").'.';
  1198. }
  1199. if (isModEnabled('notification')) {
  1200. require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  1201. $notify = new Notify($db);
  1202. $text .= '<br>';
  1203. $text .= $notify->confirmMessage('RECEPTION_VALIDATE', $object->socid, $object);
  1204. }
  1205. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateReception'), $text, 'confirm_valid', '', 0, 1, 250);
  1206. }
  1207. // Confirm cancelation
  1208. if ($action == 'annuler') {
  1209. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelReception'), $langs->trans("ConfirmCancelReception", $object->ref), 'confirm_cancel', '', 0, 1);
  1210. }
  1211. if (!$formconfirm) {
  1212. $parameters = array('formConfirm' => $formconfirm);
  1213. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1214. if (empty($reshook)) {
  1215. $formconfirm .= $hookmanager->resPrint;
  1216. } elseif ($reshook > 0) {
  1217. $formconfirm = $hookmanager->resPrint;
  1218. }
  1219. }
  1220. // Print form confirm
  1221. print $formconfirm;
  1222. // Calculate totalWeight and totalVolume for all products
  1223. // by adding weight and volume of each product line.
  1224. $tmparray = $object->getTotalWeightVolume();
  1225. $totalWeight = $tmparray['weight'];
  1226. $totalVolume = $tmparray['volume'];
  1227. if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {
  1228. $objectsrc = new Commande($db);
  1229. $objectsrc->fetch($object->$typeobject->id);
  1230. }
  1231. if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {
  1232. $objectsrc = new Propal($db);
  1233. $objectsrc->fetch($object->$typeobject->id);
  1234. }
  1235. if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && isModEnabled("supplier_order")) {
  1236. $objectsrc = new CommandeFournisseur($db);
  1237. $objectsrc->fetch($object->$typeobject->id);
  1238. }
  1239. // Reception card
  1240. $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  1241. $morehtmlref = '<div class="refidno">';
  1242. // Ref customer reception
  1243. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', 0, 1);
  1244. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', null, null, '', 1);
  1245. // Thirdparty
  1246. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  1247. // Project
  1248. if (isModEnabled('project')) {
  1249. $langs->load("projects");
  1250. $morehtmlref .= '<br>';
  1251. if (0) { // Do not change on reception
  1252. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  1253. if ($action != 'classify' && $permissiontoadd) {
  1254. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  1255. }
  1256. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  1257. } else {
  1258. if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
  1259. $proj = new Project($db);
  1260. $proj->fetch($objectsrc->fk_project);
  1261. $morehtmlref .= $proj->getNomUrl(1);
  1262. if ($proj->title) {
  1263. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  1264. }
  1265. }
  1266. }
  1267. }
  1268. $morehtmlref .= '</div>';
  1269. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  1270. print '<div class="fichecenter">';
  1271. print '<div class="fichehalfleft">';
  1272. print '<div class="underbanner clearboth"></div>';
  1273. print '<table class="border centpercent tableforfield">';
  1274. // Linked documents
  1275. if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {
  1276. print '<tr><td>';
  1277. print $langs->trans("RefOrder").'</td>';
  1278. print '<td colspan="3">';
  1279. print $objectsrc->getNomUrl(1, 'commande');
  1280. print "</td>\n";
  1281. print '</tr>';
  1282. }
  1283. if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {
  1284. print '<tr><td>';
  1285. print $langs->trans("RefProposal").'</td>';
  1286. print '<td colspan="3">';
  1287. print $objectsrc->getNomUrl(1, 'reception');
  1288. print "</td>\n";
  1289. print '</tr>';
  1290. }
  1291. if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && isModEnabled("propal")) {
  1292. print '<tr><td>';
  1293. print $langs->trans("SupplierOrder").'</td>';
  1294. print '<td colspan="3">';
  1295. print $objectsrc->getNomUrl(1, 'reception');
  1296. print "</td>\n";
  1297. print '</tr>';
  1298. }
  1299. // Date creation
  1300. print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
  1301. print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour", "tzuserrel")."</td>\n";
  1302. print '</tr>';
  1303. // Delivery date planned
  1304. print '<tr><td height="10">';
  1305. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1306. print $langs->trans('DateDeliveryPlanned');
  1307. print '</td>';
  1308. if ($action != 'editdate_livraison') {
  1309. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
  1310. }
  1311. print '</tr></table>';
  1312. print '</td><td colspan="2">';
  1313. if ($action == 'editdate_livraison') {
  1314. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1315. print '<input type="hidden" name="token" value="'.newToken().'">';
  1316. print '<input type="hidden" name="action" value="setdate_livraison">';
  1317. print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);
  1318. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  1319. print '</form>';
  1320. } else {
  1321. print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
  1322. }
  1323. print '</td>';
  1324. print '</tr>';
  1325. // Weight
  1326. print '<tr><td>';
  1327. print $form->editfieldkey("Weight", 'trueWeight', $object->trueWeight, $object, $user->hasRight('reception', 'creer'));
  1328. print '</td><td colspan="3">';
  1329. if ($action == 'edittrueWeight') {
  1330. print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1331. print '<input name="action" value="settrueWeight" type="hidden">';
  1332. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1333. print '<input type="hidden" name="token" value="'.newToken().'">';
  1334. print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
  1335. print $formproduct->selectMeasuringUnits("weight_units", "weight", $object->weight_units, 0, 2);
  1336. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1337. print ' <input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1338. print '</form>';
  1339. } else {
  1340. print $object->trueWeight;
  1341. print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : '';
  1342. }
  1343. // Calculated
  1344. if ($totalWeight > 0) {
  1345. if (!empty($object->trueWeight)) {
  1346. print ' ('.$langs->trans("SumOfProductWeights").': ';
  1347. }
  1348. 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');
  1349. if (!empty($object->trueWeight)) {
  1350. print ')';
  1351. }
  1352. }
  1353. print '</td></tr>';
  1354. // Width
  1355. print '<tr><td>'.$form->editfieldkey("Width", 'trueWidth', $object->trueWidth, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
  1356. print $form->editfieldval("Width", 'trueWidth', $object->trueWidth, $object, $user->hasRight('reception', 'creer'));
  1357. print ($object->trueWidth && $object->width_units != '') ? ' '.measuringUnitString(0, "size", $object->width_units) : '';
  1358. print '</td></tr>';
  1359. // Height
  1360. print '<tr><td>'.$form->editfieldkey("Height", 'trueHeight', $object->trueHeight, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
  1361. if ($action == 'edittrueHeight') {
  1362. print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  1363. print '<input name="action" value="settrueHeight" type="hidden">';
  1364. print '<input name="id" value="'.$object->id.'" type="hidden">';
  1365. print '<input type="hidden" name="token" value="'.newToken().'">';
  1366. print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
  1367. print $formproduct->selectMeasuringUnits("size_units", "size", $object->size_units, 0, 2);
  1368. print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
  1369. print ' <input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
  1370. print '</form>';
  1371. } else {
  1372. print $object->trueHeight;
  1373. print ($object->trueHeight && $object->height_units != '') ? ' '.measuringUnitString(0, "size", $object->height_units) : '';
  1374. }
  1375. print '</td></tr>';
  1376. // Depth
  1377. print '<tr><td>'.$form->editfieldkey("Depth", 'trueDepth', $object->trueDepth, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
  1378. print $form->editfieldval("Depth", 'trueDepth', $object->trueDepth, $object, $user->hasRight('reception', 'creer'));
  1379. print ($object->trueDepth && $object->depth_units != '') ? ' '.measuringUnitString(0, "size", $object->depth_units) : '';
  1380. print '</td></tr>';
  1381. // Volume
  1382. print '<tr><td>';
  1383. print $langs->trans("Volume");
  1384. print '</td>';
  1385. print '<td colspan="3">';
  1386. $calculatedVolume = 0;
  1387. $volumeUnit = 0;
  1388. if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
  1389. $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
  1390. $volumeUnit = $object->size_units * 3;
  1391. }
  1392. // If reception volume not defined we use sum of products
  1393. if ($calculatedVolume > 0) {
  1394. if ($volumeUnit < 50) {
  1395. 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');
  1396. } else {
  1397. print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit);
  1398. }
  1399. }
  1400. if ($totalVolume > 0) {
  1401. if ($calculatedVolume) {
  1402. print ' ('.$langs->trans("SumOfProductVolumes").': ';
  1403. }
  1404. 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');
  1405. //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
  1406. if ($calculatedVolume) {
  1407. print ')';
  1408. }
  1409. }
  1410. print "</td>\n";
  1411. print '</tr>';
  1412. // Other attributes
  1413. $cols = 2;
  1414. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1415. print '</table>';
  1416. print '</div>';
  1417. print '<div class="fichehalfright">';
  1418. print '<div class="underbanner clearboth"></div>';
  1419. print '<table class="border centpercent tableforfield">';
  1420. // Reception method
  1421. print '<tr><td height="10">';
  1422. print '<table class="nobordernopadding centpercent"><tr><td>';
  1423. print $langs->trans('ReceptionMethod');
  1424. print '</td>';
  1425. if ($action != 'editshipping_method_id') {
  1426. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'), 1).'</a></td>';
  1427. }
  1428. print '</tr></table>';
  1429. print '</td><td colspan="2">';
  1430. if ($action == 'editshipping_method_id') {
  1431. print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1432. print '<input type="hidden" name="token" value="'.newToken().'">';
  1433. print '<input type="hidden" name="action" value="setshipping_method_id">';
  1434. $object->fetch_delivery_methods();
  1435. print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1);
  1436. if ($user->admin) {
  1437. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1438. }
  1439. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  1440. print '</form>';
  1441. } else {
  1442. if ($object->shipping_method_id > 0) {
  1443. // Get code using getLabelFromKey
  1444. $code = $langs->getLabelFromKey($db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
  1445. print $langs->trans("SendingMethod".strtoupper($code));
  1446. }
  1447. }
  1448. print '</td>';
  1449. print '</tr>';
  1450. // Tracking Number
  1451. print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber", 'tracking_number', $object->tracking_number, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
  1452. print $form->editfieldval("TrackingNumber", 'tracking_number', $object->tracking_url, $object, $user->hasRight('reception', 'creer'), 'safehtmlstring', $object->tracking_number);
  1453. print '</td></tr>';
  1454. // Incoterms
  1455. if (isModEnabled('incoterm')) {
  1456. print '<tr><td>';
  1457. print '<table width="100%" class="nobordernopadding"><tr><td>';
  1458. print $langs->trans('IncotermLabel');
  1459. print '<td><td class="right">';
  1460. if ($user->hasRight('reception', 'creer')) {
  1461. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/reception/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
  1462. } else {
  1463. print '&nbsp;';
  1464. }
  1465. print '</td></tr></table>';
  1466. print '</td>';
  1467. print '<td colspan="3">';
  1468. if ($action != 'editincoterm') {
  1469. print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
  1470. } else {
  1471. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
  1472. }
  1473. print '</td></tr>';
  1474. }
  1475. print "</table>";
  1476. print '</div>';
  1477. print '</div>';
  1478. print '<div class="clearboth"></div>';
  1479. // Lines of products
  1480. if ($action == 'editline') {
  1481. print '<form name="updateline" id="updateline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;lineid='.$line_id.'" method="POST">
  1482. <input type="hidden" name="token" value="' . newToken().'">
  1483. <input type="hidden" name="action" value="updateline">
  1484. <input type="hidden" name="mode" value="">
  1485. <input type="hidden" name="id" value="' . $object->id.'">';
  1486. }
  1487. print '<br><br>';
  1488. print '<div class="div-table-responsive-no-min">';
  1489. print '<table id="tablelines" class="noborder centpercent">';
  1490. print '<thead>';
  1491. print '<tr class="liste_titre">';
  1492. // #
  1493. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
  1494. print '<td width="5" class="center">&nbsp;</td>';
  1495. }
  1496. // Product/Service
  1497. print '<td>'.$langs->trans("Products").'</td>';
  1498. // Comment
  1499. print '<td>'.$langs->trans("Comment").'</td>';
  1500. // Qty
  1501. print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
  1502. if ($origin && $origin_id > 0) {
  1503. print '<td class="center">'.$langs->trans("QtyInOtherReceptions").'</td>';
  1504. }
  1505. if ($action == 'editline') {
  1506. $editColspan = 3;
  1507. if (!isModEnabled('stock')) {
  1508. $editColspan--;
  1509. }
  1510. if (empty($conf->productbatch->enabled)) {
  1511. $editColspan--;
  1512. }
  1513. print '<td class="center" colspan="'.$editColspan.'">';
  1514. if ($object->statut <= 1) {
  1515. print $langs->trans("QtyToReceive").' - ';
  1516. } else {
  1517. print $langs->trans("QtyReceived").' - ';
  1518. }
  1519. if (isModEnabled('stock')) {
  1520. print $langs->trans("WarehouseTarget").' - ';
  1521. }
  1522. if (isModEnabled('productbatch')) {
  1523. print $langs->trans("Batch");
  1524. }
  1525. print '</td>';
  1526. } else {
  1527. $statusreceived = $object::STATUS_CLOSED;
  1528. if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION")) {
  1529. $statusreceived = $object::STATUS_VALIDATED;
  1530. }
  1531. if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION_CLOSE")) {
  1532. $statusreceived = $object::STATUS_CLOSED;
  1533. }
  1534. if ($object->statut < $statusreceived) {
  1535. print '<td class="center">'.$langs->trans("QtyToReceive").'</td>';
  1536. } else {
  1537. print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
  1538. }
  1539. if (isModEnabled('stock')) {
  1540. print '<td class="left">'.$langs->trans("WarehouseTarget").'</td>';
  1541. }
  1542. if (isModEnabled('productbatch')) {
  1543. print '<td class="left">'.$langs->trans("Batch").'</td>';
  1544. }
  1545. }
  1546. print '<td class="center">'.$langs->trans("CalculatedWeight").'</td>';
  1547. print '<td class="center">'.$langs->trans("CalculatedVolume").'</td>';
  1548. //print '<td class="center">'.$langs->trans("Size").'</td>';
  1549. if ($object->statut == 0) {
  1550. print '<td class="linecoledit"></td>';
  1551. print '<td class="linecoldelete" width="10"></td>';
  1552. }
  1553. print "</tr>\n";
  1554. print '</thead>';
  1555. $var = false;
  1556. if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
  1557. $object->fetch_thirdparty();
  1558. $outputlangs = $langs;
  1559. $newlang = '';
  1560. if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  1561. $newlang = GETPOST('lang_id', 'aZ09');
  1562. }
  1563. if (empty($newlang)) {
  1564. $newlang = $object->thirdparty->default_lang;
  1565. }
  1566. if (!empty($newlang)) {
  1567. $outputlangs = new Translate("", $conf);
  1568. $outputlangs->setDefaultLang($newlang);
  1569. }
  1570. }
  1571. // Get list of products already sent for same source object into $alreadysent
  1572. $alreadysent = array();
  1573. $origin = 'commande_fournisseur';
  1574. if ($origin && $origin_id > 0) {
  1575. $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";
  1576. $sql .= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot";
  1577. $sql .= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception";
  1578. //if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
  1579. $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';
  1580. $sql .= ', p.description as product_desc';
  1581. $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
  1582. $sql .= ", ".MAIN_DB_PREFIX."reception as e";
  1583. $sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj";
  1584. //if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid AND obj.rowid = ld.fk_origin_line";
  1585. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
  1586. $sql .= " WHERE e.entity IN (".getEntity('reception').")";
  1587. $sql .= " AND obj.fk_commande = ".((int) $origin_id);
  1588. $sql .= " AND obj.rowid = ed.fk_commandefourndet";
  1589. $sql .= " AND ed.fk_reception = e.rowid";
  1590. $sql .= " AND ed.fk_reception !=".((int) $object->id);
  1591. //if ($filter) $sql.= $filter;
  1592. $sql .= " ORDER BY obj.fk_product";
  1593. dol_syslog("get list of reception lines", LOG_DEBUG);
  1594. $resql = $db->query($sql);
  1595. if ($resql) {
  1596. $num = $db->num_rows($resql);
  1597. $i = 0;
  1598. while ($i < $num) {
  1599. $obj = $db->fetch_object($resql);
  1600. if ($obj) {
  1601. // $obj->rowid is rowid in $origin."det" table
  1602. $alreadysent[$obj->rowid][$obj->receptionline_id] = array('reception_ref'=>$obj->reception_ref, 'reception_id'=>$obj->reception_id, 'warehouse'=>$obj->fk_entrepot, 'qty'=>$obj->qty, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery);
  1603. }
  1604. $i++;
  1605. }
  1606. }
  1607. //var_dump($alreadysent);
  1608. }
  1609. $arrayofpurchaselinealreadyoutput = array();
  1610. // Loop on each product to send/sent. Warning: $lines must be sorted by ->fk_commandefourndet (it is a regroupment key on output)
  1611. print '<tbody>';
  1612. for ($i = 0; $i < $num_prod; $i++) {
  1613. print '<!-- origin line id = '.(!empty($lines[$i]->origin_line_id) ? $lines[$i]->origin_line_id : 0).' -->'; // id of order line
  1614. print '<tr class="oddeven" id="row-'.$lines[$i]->id.'" data-id="'.$lines[$i]->id.'" data-element="'.$lines[$i]->element.'">';
  1615. // #
  1616. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
  1617. print '<td class="center">'.($i + 1).'</td>';
  1618. }
  1619. // Predefined product or service
  1620. if ($lines[$i]->fk_product > 0) {
  1621. // Define output language
  1622. if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
  1623. $prod = new Product($db);
  1624. $prod->fetch($lines[$i]->fk_product);
  1625. $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label;
  1626. } else {
  1627. $label = (!empty($lines[$i]->product->label) ? $lines[$i]->product->label : $lines[$i]->product->product_label);
  1628. }
  1629. print '<td class="linecoldescription">';
  1630. if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
  1631. $text = $lines[$i]->product->getNomUrl(1);
  1632. $text .= ' - '.$label;
  1633. $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($lines[$i]->product->description));
  1634. print $form->textwithtooltip($text, $description, 3, '', '', $i);
  1635. print_date_range(!empty($lines[$i]->date_start) ? $lines[$i]->date_start : 0, !empty($lines[$i]->date_end) ? $lines[$i]->date_end : 0);
  1636. if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
  1637. print (!empty($lines[$i]->product->description) && $lines[$i]->description != $lines[$i]->product->description) ? '<br>'.dol_htmlentitiesbr($lines[$i]->description) : '';
  1638. }
  1639. }
  1640. print "</td>\n";
  1641. } else {
  1642. print '<td class="linecoldescription">';
  1643. if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
  1644. if ($lines[$i]->product_type == Product::TYPE_SERVICE) {
  1645. $text = img_object($langs->trans('Service'), 'service');
  1646. } else {
  1647. $text = img_object($langs->trans('Product'), 'product');
  1648. }
  1649. if (!empty($lines[$i]->label)) {
  1650. $text .= ' <strong>'.$lines[$i]->label.'</strong>';
  1651. print $form->textwithtooltip($text, $lines[$i]->description, 3, '', '', $i);
  1652. } else {
  1653. print $text.' '.nl2br($lines[$i]->description);
  1654. }
  1655. print_date_range($lines[$i]->date_start, $lines[$i]->date_end);
  1656. }
  1657. print "</td>\n";
  1658. }
  1659. if ($action == 'editline' && $lines[$i]->id == $line_id) {
  1660. print '<td><input name="comment'.$line_id.'" id="comment'.$line_id.'" value="'.dol_escape_htmltag($lines[$i]->comment).'"></td>';
  1661. } else {
  1662. print '<td style="white-space: pre-wrap; max-width: 200px;">'.dol_escape_htmltag($lines[$i]->comment).'</td>';
  1663. }
  1664. // Qty ordered
  1665. print '<td class="center linecolqty">';
  1666. if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
  1667. print $lines[$i]->qty_asked;
  1668. }
  1669. print '</td>';
  1670. // Qty in other receptions (with reception and warehouse used)
  1671. if ($origin && $origin_id > 0) {
  1672. print '<td class="center nowrap linecolqtyinotherreceptions">';
  1673. $htmltooltip = '';
  1674. $qtyalreadyreceived = 0;
  1675. if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
  1676. foreach ($alreadysent as $key => $val) {
  1677. if ($lines[$i]->fk_commandefourndet == $key) {
  1678. $j = 0;
  1679. foreach ($val as $receptionline_id => $receptionline_var) {
  1680. if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) {
  1681. continue; // We want to show only "other receptions"
  1682. }
  1683. $j++;
  1684. if ($j > 1) {
  1685. $htmltooltip .= '<br>';
  1686. }
  1687. $reception_static->fetch($receptionline_var['reception_id']);
  1688. $htmltooltip .= $reception_static->getNomUrl(1, 0, 0, 0, 1);
  1689. $htmltooltip .= ' - '.$receptionline_var['qty'];
  1690. $htmltext = $langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($receptionline_var['date_valid'], 'dayhour'));
  1691. if (isModEnabled('stock') && $receptionline_var['warehouse'] > 0) {
  1692. $warehousestatic->fetch($receptionline_var['warehouse']);
  1693. $htmltext .= '<br>'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1, '', 0, 1);
  1694. }
  1695. $htmltooltip .= ' '.$form->textwithpicto('', $htmltext, 1);
  1696. $qtyalreadyreceived += $receptionline_var['qty'];
  1697. }
  1698. if ($j) {
  1699. $htmltooltip = $langs->trans("QtyInOtherReceptions").'...<br><br>'.$htmltooltip.'<br><input type="submit" name="dummyhiddenbuttontogetfocus" style="display:none" autofocus>';
  1700. }
  1701. }
  1702. }
  1703. }
  1704. print $form->textwithpicto($qtyalreadyreceived, $htmltooltip, 1, 'info', '', 0, 3, 'tooltip'.$lines[$i]->id);
  1705. print '</td>';
  1706. }
  1707. if ($action == 'editline' && $lines[$i]->id == $line_id) {
  1708. // edit mode
  1709. print '<td colspan="'.$editColspan.'" class="center"><table class="nobordernopadding">';
  1710. if (isModEnabled('stock')) {
  1711. if ($lines[$i]->fk_product > 0) {
  1712. print '<!-- case edit 1 -->';
  1713. print '<tr>';
  1714. // Qty to receive or received
  1715. print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'"></td>';
  1716. // Warehouse source
  1717. print '<td>'.$formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';
  1718. // Batch number managment
  1719. if ($conf->productbatch->enabled && !empty($lines[$i]->product->status_batch)) {
  1720. print '<td class="nowraponall left"><input name="batch'.$line_id.'" id="batch'.$line_id.'" type="text" value="'.$lines[$i]->batch.'"><br>';
  1721. if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
  1722. print $langs->trans('SellByDate').' : ';
  1723. print $form->selectDate($lines[$i]->sellby, 'dlc'.$line_id, '', '', 1, "").'</br>';
  1724. }
  1725. if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
  1726. print $langs->trans('EatByDate').' : ';
  1727. print $form->selectDate($lines[$i]->eatby, 'dluo'.$line_id, '', '', 1, "");
  1728. }
  1729. print '</td>';
  1730. }
  1731. print '</tr>';
  1732. } else {
  1733. print '<!-- case edit 2 -->';
  1734. print '<tr>';
  1735. // Qty to receive or received
  1736. print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'"></td>';
  1737. // Warehouse source
  1738. print '<td></td>';
  1739. // Batch number managment
  1740. print '<td></td>';
  1741. print '</tr>';
  1742. }
  1743. }
  1744. print '</table></td>';
  1745. } else {
  1746. // Qty to receive or received
  1747. print '<td class="center linecolqtytoreceive">'.$lines[$i]->qty.'</td>';
  1748. // Warehouse source
  1749. if (isModEnabled('stock')) {
  1750. if ($lines[$i]->fk_entrepot > 0) {
  1751. $entrepot = new Entrepot($db);
  1752. $entrepot->fetch($lines[$i]->fk_entrepot);
  1753. print '<td class="left tdoverflowmax150" title="'.dol_escape_htmltag($entrepot->label).'">';
  1754. print $entrepot->getNomUrl(1);
  1755. print '</td>';
  1756. } else {
  1757. print '<td></td>';
  1758. }
  1759. }
  1760. // Batch number managment
  1761. if (isModEnabled('productbatch')) {
  1762. if (isset($lines[$i]->batch)) {
  1763. print '<!-- Detail of lot -->';
  1764. print '<td class="linecolbatch nowrap">';
  1765. $detail = $langs->trans("NA");
  1766. if ($lines[$i]->product->status_batch > 0 && $lines[$i]->fk_product > 0) {
  1767. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  1768. $productlot = new Productlot($db);
  1769. $reslot = $productlot->fetch(0, $lines[$i]->fk_product, $lines[$i]->batch);
  1770. if ($reslot > 0) {
  1771. $detail = $productlot->getNomUrl(1);
  1772. } else {
  1773. // lot is not created and info is only in reception lines
  1774. $batchinfo = $langs->trans("Batch").': '.$lines[$i]->batch;
  1775. if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
  1776. $batchinfo .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby, "day");
  1777. }
  1778. if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
  1779. $batchinfo .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby, "day");
  1780. }
  1781. $detail = $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $batchinfo);
  1782. }
  1783. }
  1784. print $detail . '</td>';
  1785. } else {
  1786. print '<td></td>';
  1787. }
  1788. }
  1789. }
  1790. // Weight
  1791. print '<td class="center linecolweight">';
  1792. if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
  1793. print $lines[$i]->product->weight * $lines[$i]->qty.' '.measuringUnitString(0, "weight", $lines[$i]->product->weight_units);
  1794. } else {
  1795. print '&nbsp;';
  1796. }
  1797. print '</td>';
  1798. // Volume
  1799. print '<td class="center linecolvolume">';
  1800. if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
  1801. print $lines[$i]->product->volume * $lines[$i]->qty.' '.measuringUnitString(0, "volume", $lines[$i]->product->volume_units);
  1802. } else {
  1803. print '&nbsp;';
  1804. }
  1805. print '</td>';
  1806. if ($action == 'editline' && $lines[$i]->id == $line_id) {
  1807. print '<td class="center valignmiddle" colspan="2">';
  1808. print '<input type="submit" class="button small button-save" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';
  1809. print '<input type="submit" class="button small button-cancel" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"><br>';
  1810. print '</td>';
  1811. } elseif ($object->statut == Reception::STATUS_DRAFT) {
  1812. // edit-delete buttons
  1813. print '<td class="linecoledit center">';
  1814. print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_edit().'</a>';
  1815. print '</td>';
  1816. print '<td class="linecoldelete" width="10">';
  1817. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_delete().'</a>';
  1818. print '</td>';
  1819. // Display lines extrafields
  1820. if (!empty($rowExtrafieldsStart)) {
  1821. print $rowExtrafieldsStart;
  1822. print $rowExtrafieldsView;
  1823. print $rowEnd;
  1824. }
  1825. }
  1826. print "</tr>";
  1827. $arrayofpurchaselinealreadyoutput[$lines[$i]->fk_commandefourndet] = $lines[$i]->fk_commandefourndet;
  1828. // Display lines extrafields
  1829. $extralabelslines = $extrafields->attributes[$lines[$i]->table_element];
  1830. if (!empty($extralabelslines) && is_array($extralabelslines) && count($extralabelslines) > 0) {
  1831. $colspan = 8;
  1832. if (isModEnabled('stock')) {
  1833. $colspan++;
  1834. }
  1835. if (isModEnabled('productbatch')) {
  1836. $colspan++;
  1837. }
  1838. $line = new CommandeFournisseurDispatch($db);
  1839. $line->id = $lines[$i]->id;
  1840. $line->fetch_optionals();
  1841. if ($action == 'editline' && $lines[$i]->id == $line_id) {
  1842. print $line->showOptionals($extrafields, 'edit', array('colspan'=>$colspan), '');
  1843. } else {
  1844. print $line->showOptionals($extrafields, 'view', array('colspan'=>$colspan), '');
  1845. }
  1846. }
  1847. }
  1848. print '</tbody>';
  1849. // TODO Show also lines ordered but not delivered
  1850. print "</table>\n";
  1851. print '</div>';
  1852. print dol_get_fiche_end();
  1853. $object->fetchObjectLinked($object->id, $object->element);
  1854. /*
  1855. * Boutons actions
  1856. */
  1857. if (($user->socid == 0) && ($action != 'presend')) {
  1858. print '<div class="tabsAction">';
  1859. $parameters = array();
  1860. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1861. if (empty($reshook)) {
  1862. if ($object->statut == Reception::STATUS_DRAFT && $num_prod > 0) {
  1863. if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer'))
  1864. || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate'))) {
  1865. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken().'">'.$langs->trans("Validate").'</a>';
  1866. } else {
  1867. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
  1868. }
  1869. }
  1870. // Back to draft
  1871. if ($object->statut == Reception::STATUS_VALIDATED && $user->hasRight('reception', 'creer')) {
  1872. print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modif&token='.newToken().'">'.$langs->trans('SetToDraft').'</a></div>';
  1873. }
  1874. // TODO add alternative status
  1875. // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
  1876. if ($object->statut == Reception::STATUS_CLOSED && $user->hasRight('reception', 'creer')) {
  1877. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>';
  1878. }
  1879. // Send
  1880. if (empty($user->socid)) {
  1881. if ($object->statut > 0) {
  1882. if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('reception', 'reception_advance', 'send')) {
  1883. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendByMail').'</a>';
  1884. } else {
  1885. print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
  1886. }
  1887. }
  1888. }
  1889. // Create bill
  1890. if (isModEnabled("supplier_invoice") && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED)) {
  1891. if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer')) {
  1892. if (getDolGlobalString('WORKFLOW_BILL_ON_RECEPTION') !== '0') {
  1893. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
  1894. }
  1895. }
  1896. }
  1897. // Set Billed and Closed
  1898. if ($object->statut == Reception::STATUS_VALIDATED) {
  1899. if ($user->hasRight('reception', 'creer') && $object->statut > 0) {
  1900. if (!$object->billed && getDolGlobalString('WORKFLOW_BILL_ON_RECEPTION') !== '0') {
  1901. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled&token='.newToken().'">'.$langs->trans('ClassifyBilled').'</a>';
  1902. }
  1903. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifyclosed&token='.newToken().'">'.$langs->trans("Close").'</a>';
  1904. }
  1905. }
  1906. if ($user->hasRight('reception', 'supprimer')) {
  1907. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
  1908. }
  1909. }
  1910. print '</div>';
  1911. }
  1912. /*
  1913. * Documents generated
  1914. */
  1915. if ($action != 'presend' && $action != 'editline') {
  1916. print '<div class="fichecenter"><div class="fichehalfleft">';
  1917. $objectref = dol_sanitizeFileName($object->ref);
  1918. $filedir = $conf->reception->dir_output."/".$objectref;
  1919. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1920. $genallowed = $user->rights->reception->lire;
  1921. $delallowed = $user->rights->reception->creer;
  1922. print $formfile->showdocuments('reception', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  1923. // Show links to link elements
  1924. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
  1925. $somethingshown = $form->showLinkedObjectBlock($object, '');
  1926. print '</div><div class="fichehalfright">';
  1927. print '</div></div>';
  1928. }
  1929. // Presend form
  1930. $modelmail = 'shipping_send';
  1931. $defaulttopic = 'SendReceptionRef';
  1932. $diroutput = $conf->reception->dir_output;
  1933. $trackid = 'rec'.$object->id;
  1934. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  1935. }
  1936. llxFooter();
  1937. $db->close();