card.php 86 KB

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