card.php 84 KB

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