card.php 87 KB

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