card.php 79 KB

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