card.php 89 KB

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