card.php 86 KB

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