card.php 88 KB

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