card.php 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  7. * Copyright (C) 2006 Auguria SARL <info@auguria.org>
  8. * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2013-2016 Marcos García <marcosgdf@gmail.com>
  10. * Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  11. * Copyright (C) 2011-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
  12. * Copyright (C) 2014 Cédric Gross <c.gross@kreiz-it.fr>
  13. * Copyright (C) 2014-2015 Ferran Marcet <fmarcet@2byte.es>
  14. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  15. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  16. * Copyright (C) 2016-2022 Charlene Benke <charlene@patas-monkey.com>
  17. * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
  18. * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
  19. * Copyright (C) 2019-2022 Frédéric France <frederic.france@netlogic.fr>
  20. * Copyright (C) 2019-2020 Thibault FOUCART <support@ptibogxiv.net>
  21. * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
  22. * Copyright (C) 2022 Vincent de Grandpré <vincent@de-grandpre.quebec>
  23. *
  24. * This program is free software; you can redistribute it and/or modify
  25. * it under the terms of the GNU General Public License as published by
  26. * the Free Software Foundation; either version 3 of the License, or
  27. * (at your option) any later version.
  28. *
  29. * This program is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. * GNU General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU General Public License
  35. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  36. */
  37. /**
  38. * \file htdocs/product/card.php
  39. * \ingroup product
  40. * \brief Page to show product
  41. */
  42. // Load Dolibarr environment
  43. require '../main.inc.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  48. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  50. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  51. require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php';
  52. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  53. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  54. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  55. require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
  56. if (isModEnabled('propal')) {
  57. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  58. }
  59. if (isModEnabled('facture')) {
  60. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  61. }
  62. if (isModEnabled('commande')) {
  63. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  64. }
  65. if (isModEnabled('accounting')) {
  66. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  67. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  68. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  69. }
  70. if (isModEnabled('bom')) {
  71. require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
  72. }
  73. // Load translation files required by the page
  74. $langs->loadLangs(array('products', 'other'));
  75. if (isModEnabled('stock')) {
  76. $langs->load("stocks");
  77. }
  78. if (isModEnabled('facture')) {
  79. $langs->load("bills");
  80. }
  81. if (isModEnabled('productbatch')) {
  82. $langs->load("productbatch");
  83. }
  84. $mesg = ''; $error = 0; $errors = array();
  85. $refalreadyexists = 0;
  86. // Get parameters
  87. $id = GETPOST('id', 'int');
  88. if (!empty($conf->global->MAIN_SECURITY_ALLOW_UNSECURED_REF_LABELS)) {
  89. $ref = (GETPOSTISSET('ref') ? GETPOST('ref', 'nohtml') : null);
  90. } else {
  91. $ref = (GETPOSTISSET('ref') ? GETPOST('ref', 'alpha') : null);
  92. }
  93. $type = (GETPOSTISSET('type') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT);
  94. $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
  95. $cancel = GETPOST('cancel', 'alpha');
  96. $backtopage = GETPOST('backtopage', 'alpha');
  97. $confirm = GETPOST('confirm', 'alpha');
  98. $socid = GETPOST('socid', 'int');
  99. $duration_value = GETPOST('duration_value', 'int');
  100. $duration_unit = GETPOST('duration_unit', 'alpha');
  101. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  102. $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha');
  103. $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export', 'alpha');
  104. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  105. $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
  106. $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
  107. $checkmandatory = GETPOST('accountancy_code_buy_export', 'alpha');
  108. // by default 'alphanohtml' (better security); hidden conf MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML allows basic html
  109. if (!empty($conf->global->MAIN_SECURITY_ALLOW_UNSECURED_REF_LABELS)) {
  110. $label_security_check = 'nohtml';
  111. } else {
  112. $label_security_check = empty($conf->global->MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML) ? 'alphanohtml' : 'restricthtml';
  113. }
  114. if (!empty($user->socid)) {
  115. $socid = $user->socid;
  116. }
  117. // Load object modCodeProduct
  118. $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard');
  119. if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') {
  120. $module = substr($module, 0, dol_strlen($module) - 4);
  121. }
  122. $result = dol_include_once('/core/modules/product/'.$module.'.php');
  123. if ($result > 0) {
  124. $modCodeProduct = new $module();
  125. }
  126. $object = new Product($db);
  127. $object->type = $type; // so test later to fill $usercancxxx is correct
  128. $extrafields = new ExtraFields($db);
  129. // fetch optionals attributes and labels
  130. $extrafields->fetch_name_optionals_label($object->table_element);
  131. if ($id > 0 || !empty($ref)) {
  132. $result = $object->fetch($id, $ref);
  133. if ($result < 0) {
  134. dol_print_error($db, $object->error, $object->errors);
  135. }
  136. if (isModEnabled("product")) {
  137. $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
  138. } elseif (isModEnabled("service")) {
  139. $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
  140. }
  141. if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { // For backward compatiblity, we scan also old dirs
  142. if (isModEnabled("product")) {
  143. $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos";
  144. } else {
  145. $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos";
  146. }
  147. }
  148. }
  149. $modulepart = 'product';
  150. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  151. $canvas = !empty($object->canvas) ? $object->canvas : GETPOST("canvas");
  152. $objcanvas = null;
  153. if (!empty($canvas)) {
  154. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  155. $objcanvas = new Canvas($db, $action);
  156. $objcanvas->getCanvas('product', 'card', $canvas);
  157. }
  158. // Security check
  159. $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
  160. $fieldtype = (!empty($id) ? 'rowid' : 'ref');
  161. if ($object->id > 0) {
  162. if ($object->type == $object::TYPE_PRODUCT) {
  163. restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
  164. }
  165. if ($object->type == $object::TYPE_SERVICE) {
  166. restrictedArea($user, 'service', $object->id, 'product&product', '', '');
  167. }
  168. } else {
  169. restrictedArea($user, 'produit|service', 0, 'product&product', '', '', $fieldtype);
  170. }
  171. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  172. $hookmanager->initHooks(array('productcard', 'globalcard'));
  173. // Permissions
  174. $usercanread = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'read')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'lire')));
  175. $usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'creer')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'creer')));
  176. $usercandelete = (($object->type == Product::TYPE_PRODUCT && $user->hasRight('produit', 'supprimer')) || ($object->type == Product::TYPE_SERVICE && $user->hasRight('service', 'supprimer')));
  177. /*
  178. * Actions
  179. */
  180. if ($cancel) {
  181. $action = '';
  182. }
  183. $createbarcode = isModEnabled('barcode');
  184. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->creer_advance)) {
  185. $createbarcode = 0;
  186. }
  187. $parameters = array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
  188. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  189. if ($reshook < 0) {
  190. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  191. }
  192. if (empty($reshook)) {
  193. $backurlforlist = DOL_URL_ROOT.'/product/list.php?type='.$type;
  194. if (empty($backtopage) || ($cancel && empty($id))) {
  195. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  196. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  197. $backtopage = $backurlforlist;
  198. } else {
  199. $backtopage = DOL_URL_ROOT.'/product/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  200. }
  201. }
  202. }
  203. if ($cancel) {
  204. if (!empty($backtopageforcancel)) {
  205. header("Location: ".$backtopageforcancel);
  206. exit;
  207. } elseif (!empty($backtopage)) {
  208. header("Location: ".$backtopage);
  209. exit;
  210. }
  211. $action = '';
  212. }
  213. // merge products
  214. if ($action == 'confirm_merge' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
  215. $error = 0;
  216. $productOriginId = GETPOST('product_origin', 'int');
  217. $productOrigin = new Product($db);
  218. if ($productOriginId <= 0) {
  219. $langs->load('errors');
  220. setEventMessages($langs->trans('ErrorProductIdIsMandatory', $langs->transnoentitiesnoconv('MergeOriginProduct')), null, 'errors');
  221. } else {
  222. if (!$error && $productOrigin->fetch($productOriginId) < 1) {
  223. setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
  224. $error++;
  225. }
  226. if (!$error) {
  227. // TODO Move the merge function into class of object.
  228. $db->begin();
  229. // Recopy some data
  230. $listofproperties = array(
  231. 'ref',
  232. 'ref_ext',
  233. 'label',
  234. 'description',
  235. 'url',
  236. 'barcode',
  237. 'fk_barcode_type',
  238. 'import_key',
  239. 'mandatory_period',
  240. 'accountancy_code_buy',
  241. 'accountancy_code_buy_intra',
  242. 'accountancy_code_buy_export',
  243. 'accountancy_code_sell',
  244. 'accountancy_code_sell_intra',
  245. 'accountancy_code_sell_export'
  246. );
  247. foreach ($listofproperties as $property) {
  248. if (empty($object->$property)) {
  249. $object->$property = $productOrigin->$property;
  250. }
  251. }
  252. // Concat some data
  253. $listofproperties = array(
  254. 'note_public', 'note_private'
  255. );
  256. foreach ($listofproperties as $property) {
  257. $object->$property = dol_concatdesc($object->$property, $productOrigin->$property);
  258. }
  259. // Merge extrafields
  260. if (is_array($productOrigin->array_options)) {
  261. foreach ($productOrigin->array_options as $key => $val) {
  262. if (empty($object->array_options[$key])) {
  263. $object->array_options[$key] = $val;
  264. }
  265. }
  266. }
  267. // Merge categories
  268. $static_cat = new Categorie($db);
  269. $custcats_ori = $static_cat->containing($productOrigin->id, 'product', 'id');
  270. $custcats = $static_cat->containing($object->id, 'product', 'id');
  271. $custcats = array_merge($custcats, $custcats_ori);
  272. $object->setCategories($custcats);
  273. // If product has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
  274. if ($productOrigin->barcode == $object->barcode) {
  275. dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
  276. $productOrigin->barcode = '';
  277. //$productOrigin->update($productOrigin->id, $user, 0, 'merge');
  278. }
  279. // Update
  280. $result = $object->update($object->id, $user, 0, 'merge');
  281. if ($result <= 0) {
  282. setEventMessages($object->error, $object->errors, 'errors');
  283. $error++;
  284. }
  285. // Move links
  286. if (!$error) {
  287. // TODO add this functionality into the api_products.class.php
  288. // TODO Mutualise the list into object product.class.php
  289. $objects = array(
  290. 'ActionComm' => '/comm/action/class/actioncomm.class.php',
  291. 'Bom' => '/bom/class/bom.class.php',
  292. // do not use Categorie, it cause foreign key error, merge is done before
  293. //'Categorie' => '/categories/class/categorie.class.php',
  294. 'Commande' => '/commande/class/commande.class.php',
  295. 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
  296. 'Contrat' => '/contrat/class/contrat.class.php',
  297. 'Delivery' => '/delivery/class/delivery.class.php',
  298. 'Facture' => '/compta/facture/class/facture.class.php',
  299. 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
  300. 'FactureRec' => '/compta/facture/class/facture-rec.class.php',
  301. 'FichinterRec' => '/fichinter/class/fichinterrec.class.php',
  302. 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
  303. 'Propal' => '/comm/propal/class/propal.class.php',
  304. 'Reception' => '/reception/class/reception.class.php',
  305. 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
  306. );
  307. //First, all core objects must update their tables
  308. foreach ($objects as $object_name => $object_file) {
  309. require_once DOL_DOCUMENT_ROOT.$object_file;
  310. if (!$error && !$object_name::replaceProduct($db, $productOrigin->id, $object->id)) {
  311. $error++;
  312. setEventMessages($db->lasterror(), null, 'errors');
  313. break;
  314. }
  315. }
  316. }
  317. // External modules should update their ones too
  318. if (!$error) {
  319. $parameters = array('soc_origin' => $productOrigin->id, 'soc_dest' => $object->id);
  320. $reshook = $hookmanager->executeHooks(
  321. 'replaceProduct',
  322. $parameters,
  323. $object,
  324. $action
  325. );
  326. if ($reshook < 0) {
  327. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  328. $error++;
  329. }
  330. }
  331. if (!$error) {
  332. $object->context = array(
  333. 'merge' => 1,
  334. 'mergefromid' => $productOrigin->id,
  335. );
  336. // Call trigger
  337. $result = $object->call_trigger('PRODUCT_MODIFY', $user);
  338. if ($result < 0) {
  339. setEventMessages($object->error, $object->errors, 'errors');
  340. $error++;
  341. }
  342. // End call triggers
  343. }
  344. if (!$error) {
  345. // We finally remove the old product
  346. // TODO merge attached files from old product into new one before delete
  347. if ($productOrigin->delete($user) < 1) {
  348. $error++;
  349. }
  350. }
  351. if (!$error) {
  352. setEventMessages($langs->trans('ProductsMergeSuccess'), null, 'mesgs');
  353. $db->commit();
  354. } else {
  355. $langs->load("errors");
  356. setEventMessages($langs->trans('ErrorsProductsMerge'), null, 'errors');
  357. $db->rollback();
  358. }
  359. }
  360. }
  361. }
  362. // Type
  363. if ($action == 'setfk_product_type' && $usercancreate) {
  364. $result = $object->setValueFrom('fk_product_type', GETPOST('fk_product_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
  365. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  366. exit;
  367. }
  368. // Actions to build doc
  369. $upload_dir = $conf->product->dir_output;
  370. $permissiontoadd = $usercancreate;
  371. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  372. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  373. // Barcode type
  374. if ($action == 'setfk_barcode_type' && $createbarcode) {
  375. $result = $object->setValueFrom('fk_barcode_type', GETPOST('fk_barcode_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
  376. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  377. exit;
  378. }
  379. // Barcode value
  380. if ($action == 'setbarcode' && $createbarcode) {
  381. $result = $object->check_barcode(GETPOST('barcode'), GETPOST('barcode_type_code'));
  382. if ($result >= 0) {
  383. $result = $object->setValueFrom('barcode', GETPOST('barcode'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
  384. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  385. exit;
  386. } else {
  387. $langs->load("errors");
  388. if ($result == -1) {
  389. $errors[] = 'ErrorBadBarCodeSyntax';
  390. } elseif ($result == -2) {
  391. $errors[] = 'ErrorBarCodeRequired';
  392. } elseif ($result == -3) {
  393. $errors[] = 'ErrorBarCodeAlreadyUsed';
  394. } else {
  395. $errors[] = 'FailedToValidateBarCode';
  396. }
  397. $error++;
  398. setEventMessages('', $errors, 'errors');
  399. }
  400. }
  401. // Add a product or service
  402. if ($action == 'add' && $usercancreate) {
  403. $error = 0;
  404. if (!GETPOST('label', $label_security_check)) {
  405. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Label')), null, 'errors');
  406. $action = "create";
  407. $error++;
  408. }
  409. if (empty($ref)) {
  410. if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
  411. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors');
  412. $action = "create";
  413. $error++;
  414. }
  415. }
  416. if (!empty($duration_value) && empty($duration_unit)) {
  417. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Unit')), null, 'errors');
  418. $action = "create";
  419. $error++;
  420. }
  421. if (!$error) {
  422. $units = GETPOST('units', 'int');
  423. $object->ref = $ref;
  424. $object->label = GETPOST('label', $label_security_check);
  425. $object->price_base_type = GETPOST('price_base_type', 'aZ09');
  426. $object->mandatory_period = !empty(GETPOST("mandatoryperiod", 'alpha')) ? 1 : 0;
  427. if ($object->price_base_type == 'TTC') {
  428. $object->price_ttc = GETPOST('price');
  429. } else {
  430. $object->price = GETPOST('price');
  431. }
  432. if ($object->price_base_type == 'TTC') {
  433. $object->price_min_ttc = GETPOST('price_min');
  434. } else {
  435. $object->price_min = GETPOST('price_min');
  436. }
  437. $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
  438. // We must define tva_tx, npr and local taxes
  439. $vatratecode = '';
  440. $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot
  441. $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
  442. $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0';
  443. // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
  444. $reg = array();
  445. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  446. // We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in update price.
  447. $vatratecode = $reg[1];
  448. // Get record from code
  449. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  450. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  451. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  452. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  453. $sql .= " AND t.code = '".$db->escape($vatratecode)."'";
  454. $resql = $db->query($sql);
  455. if ($resql) {
  456. $obj = $db->fetch_object($resql);
  457. $npr = $obj->recuperableonly;
  458. $localtax1 = $obj->localtax1;
  459. $localtax2 = $obj->localtax2;
  460. $localtax1_type = $obj->localtax1_type;
  461. $localtax2_type = $obj->localtax2_type;
  462. }
  463. }
  464. $object->default_vat_code = $vatratecode;
  465. $object->tva_tx = $tva_tx;
  466. $object->tva_npr = $npr;
  467. $object->localtax1_tx = $localtax1;
  468. $object->localtax2_tx = $localtax2;
  469. $object->localtax1_type = $localtax1_type;
  470. $object->localtax2_type = $localtax2_type;
  471. $object->type = $type;
  472. $object->status = GETPOST('statut');
  473. $object->status_buy = GETPOST('statut_buy');
  474. $object->status_batch = GETPOST('status_batch');
  475. $object->batch_mask = GETPOST('batch_mask');
  476. $object->barcode_type = GETPOST('fk_barcode_type');
  477. $object->barcode = GETPOST('barcode');
  478. // Set barcode_type_xxx from barcode_type id
  479. $stdobject = new GenericObject($db);
  480. $stdobject->element = 'product';
  481. $stdobject->barcode_type = GETPOST('fk_barcode_type');
  482. $result = $stdobject->fetch_barcode();
  483. if ($result < 0) {
  484. $error++;
  485. $mesg = 'Failed to get bar code type information ';
  486. setEventMessages($mesg.$stdobject->error, $stdobject->errors, 'errors');
  487. }
  488. $object->barcode_type_code = $stdobject->barcode_type_code;
  489. $object->barcode_type_coder = $stdobject->barcode_type_coder;
  490. $object->barcode_type_label = $stdobject->barcode_type_label;
  491. $object->description = dol_htmlcleanlastbr(GETPOST('desc', 'restricthtml'));
  492. $object->url = GETPOST('url');
  493. $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private', 'restricthtml'));
  494. $object->note = $object->note_private; // deprecated
  495. $object->customcode = GETPOST('customcode', 'alphanohtml');
  496. $object->country_id = GETPOST('country_id', 'int');
  497. $object->state_id = GETPOST('state_id', 'int');
  498. $object->lifetime = GETPOST('lifetime', 'int');
  499. $object->qc_frequency = GETPOST('qc_frequency', 'int');
  500. $object->duration_value = $duration_value;
  501. $object->duration_unit = $duration_unit;
  502. $object->fk_default_warehouse = GETPOST('fk_default_warehouse');
  503. $object->fk_default_workstation = GETPOST('fk_default_workstation');
  504. $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte') ?GETPOST('seuil_stock_alerte') : 0;
  505. $object->desiredstock = GETPOST('desiredstock') ?GETPOST('desiredstock') : 0;
  506. $object->canvas = GETPOST('canvas');
  507. $object->net_measure = GETPOST('net_measure');
  508. $object->net_measure_units = GETPOST('net_measure_units'); // This is not the fk_unit but the power of unit
  509. $object->weight = GETPOST('weight');
  510. $object->weight_units = GETPOST('weight_units'); // This is not the fk_unit but the power of unit
  511. $object->length = GETPOST('size');
  512. $object->length_units = GETPOST('size_units'); // This is not the fk_unit but the power of unit
  513. $object->width = GETPOST('sizewidth');
  514. $object->height = GETPOST('sizeheight');
  515. $object->surface = GETPOST('surface');
  516. $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit
  517. $object->volume = GETPOST('volume');
  518. $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit
  519. $finished = GETPOST('finished', 'int');
  520. if ($finished >= 0) {
  521. $object->finished = $finished;
  522. } else {
  523. $object->finished = null;
  524. }
  525. $units = GETPOST('units', 'int');
  526. if ($units > 0) {
  527. $object->fk_unit = $units;
  528. } else {
  529. $object->fk_unit = null;
  530. }
  531. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  532. $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha');
  533. $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export', 'alpha');
  534. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  535. $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
  536. $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
  537. if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
  538. $object->accountancy_code_sell = '';
  539. } else {
  540. $object->accountancy_code_sell = $accountancy_code_sell;
  541. }
  542. if (empty($accountancy_code_sell_intra) || $accountancy_code_sell_intra == '-1') {
  543. $object->accountancy_code_sell_intra = '';
  544. } else {
  545. $object->accountancy_code_sell_intra = $accountancy_code_sell_intra;
  546. }
  547. if (empty($accountancy_code_sell_export) || $accountancy_code_sell_export == '-1') {
  548. $object->accountancy_code_sell_export = '';
  549. } else {
  550. $object->accountancy_code_sell_export = $accountancy_code_sell_export;
  551. }
  552. if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
  553. $object->accountancy_code_buy = '';
  554. } else {
  555. $object->accountancy_code_buy = $accountancy_code_buy;
  556. }
  557. if (empty($accountancy_code_buy_intra) || $accountancy_code_buy_intra == '-1') {
  558. $object->accountancy_code_buy_intra = '';
  559. } else {
  560. $object->accountancy_code_buy_intra = $accountancy_code_buy_intra;
  561. }
  562. if (empty($accountancy_code_buy_export) || $accountancy_code_buy_export == '-1') {
  563. $object->accountancy_code_buy_export = '';
  564. } else {
  565. $object->accountancy_code_buy_export = $accountancy_code_buy_export;
  566. }
  567. // MultiPrix
  568. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  569. for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
  570. if (GETPOSTISSET("price_".$i)) {
  571. $object->multiprices["$i"] = price2num(GETPOST("price_".$i), 'MU');
  572. $object->multiprices_base_type["$i"] = GETPOST("multiprices_base_type_".$i);
  573. } else {
  574. $object->multiprices["$i"] = "";
  575. }
  576. }
  577. }
  578. // Fill array 'array_options' with data from add form
  579. $ret = $extrafields->setOptionalsFromPost(null, $object);
  580. if ($ret < 0) {
  581. $error++;
  582. }
  583. if (!$ref && !empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
  584. // Generate ref...
  585. $ref = $modCodeProduct->getNextValue($object, $type);
  586. }
  587. if (!$error) {
  588. $id = $object->create($user);
  589. }
  590. if ($id > 0) {
  591. // Category association
  592. $categories = GETPOST('categories', 'array');
  593. $object->setCategories($categories);
  594. if (!empty($backtopage)) {
  595. $backtopage = preg_replace('/__ID__/', $object->id, $backtopage); // New method to autoselect project after a New on another form object creation
  596. if (preg_match('/\?/', $backtopage)) {
  597. $backtopage .= '&socid='.$object->id; // Old method
  598. }
  599. header("Location: ".$backtopage);
  600. exit;
  601. } else {
  602. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  603. exit;
  604. }
  605. } else {
  606. if (count($object->errors)) {
  607. setEventMessages($object->error, $object->errors, 'errors');
  608. } else {
  609. if ($object->error == 'ErrorProductAlreadyExists') {
  610. // allow to hook on ErrorProductAlreadyExists in any module
  611. $reshook = $hookmanager->executeHooks('onProductAlreadyExists', $parameters, $object, $action);
  612. if ($reshook < 0) {
  613. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  614. }
  615. if ($object->error) {
  616. // check again to prevent translation issue,
  617. // as error may have been cleared in hook function
  618. setEventMessages($langs->trans($object->error), null, 'errors');
  619. }
  620. } else {
  621. setEventMessages($langs->trans($object->error), null, 'errors');
  622. }
  623. }
  624. $action = "create";
  625. }
  626. }
  627. }
  628. // Update a product or service
  629. if ($action == 'update' && $usercancreate) {
  630. if (GETPOST('cancel', 'alpha')) {
  631. $action = '';
  632. } else {
  633. if ($object->id > 0) {
  634. $object->oldcopy = clone $object;
  635. if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
  636. $object->ref = $ref;
  637. }
  638. $object->label = GETPOST('label', $label_security_check);
  639. $desc = dol_htmlcleanlastbr(preg_replace('/&nbsp;$/', '', GETPOST('desc', 'restricthtml')));
  640. $object->description = $desc;
  641. $object->url = GETPOST('url');
  642. if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  643. $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private', 'restricthtml'));
  644. $object->note = $object->note_private;
  645. }
  646. $object->customcode = GETPOST('customcode', 'alpha');
  647. $object->country_id = GETPOST('country_id', 'int');
  648. $object->state_id = GETPOST('state_id', 'int');
  649. $object->lifetime = GETPOST('lifetime', 'int');
  650. $object->qc_frequency = GETPOST('qc_frequency', 'int');
  651. $object->status = GETPOST('statut', 'int');
  652. $object->status_buy = GETPOST('statut_buy', 'int');
  653. $object->status_batch = GETPOST('status_batch', 'aZ09');
  654. $object->batch_mask = GETPOST('batch_mask', 'alpha');
  655. $object->fk_default_warehouse = GETPOST('fk_default_warehouse');
  656. $object->fk_default_workstation = GETPOST('fk_default_workstation');
  657. // removed from update view so GETPOST always empty
  658. /*
  659. $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte');
  660. $object->desiredstock = GETPOST('desiredstock');
  661. */
  662. $object->duration_value = GETPOST('duration_value', 'int');
  663. $object->duration_unit = GETPOST('duration_unit', 'alpha');
  664. $object->canvas = GETPOST('canvas');
  665. $object->net_measure = GETPOST('net_measure');
  666. $object->net_measure_units = GETPOST('net_measure_units'); // This is not the fk_unit but the power of unit
  667. $object->weight = GETPOST('weight');
  668. $object->weight_units = GETPOST('weight_units'); // This is not the fk_unit but the power of unit
  669. $object->length = GETPOST('size');
  670. $object->length_units = GETPOST('size_units'); // This is not the fk_unit but the power of unit
  671. $object->width = GETPOST('sizewidth');
  672. $object->height = GETPOST('sizeheight');
  673. $object->surface = GETPOST('surface');
  674. $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit
  675. $object->volume = GETPOST('volume');
  676. $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit
  677. $finished = GETPOST('finished', 'int');
  678. if ($finished >= 0) {
  679. $object->finished = $finished;
  680. } else {
  681. $object->finished = null;
  682. }
  683. $fk_default_bom = GETPOST('fk_default_bom', 'int');
  684. if ($fk_default_bom >= 0) {
  685. $object->fk_default_bom = $fk_default_bom;
  686. } else {
  687. $object->fk_default_bom = null;
  688. }
  689. $units = GETPOST('units', 'int');
  690. if ($units > 0) {
  691. $object->fk_unit = $units;
  692. } else {
  693. $object->fk_unit = null;
  694. }
  695. $object->barcode_type = GETPOST('fk_barcode_type');
  696. $object->barcode = GETPOST('barcode');
  697. // Set barcode_type_xxx from barcode_type id
  698. $stdobject = new GenericObject($db);
  699. $stdobject->element = 'product';
  700. $stdobject->barcode_type = GETPOST('fk_barcode_type');
  701. $result = $stdobject->fetch_barcode();
  702. if ($result < 0) {
  703. $error++;
  704. $mesg = 'Failed to get bar code type information ';
  705. setEventMessages($mesg.$stdobject->error, $stdobject->errors, 'errors');
  706. }
  707. $object->barcode_type_code = $stdobject->barcode_type_code;
  708. $object->barcode_type_coder = $stdobject->barcode_type_coder;
  709. $object->barcode_type_label = $stdobject->barcode_type_label;
  710. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  711. $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha');
  712. $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export', 'alpha');
  713. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  714. $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
  715. $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
  716. $checkmandatory = GETPOST('mandatoryperiod', 'alpha');
  717. if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
  718. $object->accountancy_code_sell = '';
  719. } else {
  720. $object->accountancy_code_sell = $accountancy_code_sell;
  721. }
  722. if (empty($accountancy_code_sell_intra) || $accountancy_code_sell_intra == '-1') {
  723. $object->accountancy_code_sell_intra = '';
  724. } else {
  725. $object->accountancy_code_sell_intra = $accountancy_code_sell_intra;
  726. }
  727. if (empty($accountancy_code_sell_export) || $accountancy_code_sell_export == '-1') {
  728. $object->accountancy_code_sell_export = '';
  729. } else {
  730. $object->accountancy_code_sell_export = $accountancy_code_sell_export;
  731. }
  732. if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
  733. $object->accountancy_code_buy = '';
  734. } else {
  735. $object->accountancy_code_buy = $accountancy_code_buy;
  736. }
  737. if (empty($accountancy_code_buy_intra) || $accountancy_code_buy_intra == '-1') {
  738. $object->accountancy_code_buy_intra = '';
  739. } else {
  740. $object->accountancy_code_buy_intra = $accountancy_code_buy_intra;
  741. }
  742. if (empty($accountancy_code_buy_export) || $accountancy_code_buy_export == '-1') {
  743. $object->accountancy_code_buy_export = '';
  744. } else {
  745. $object->accountancy_code_buy_export = $accountancy_code_buy_export;
  746. }
  747. if ($object->isService()) {
  748. $object->mandatory_period = (!empty($checkmandatory)) ? 1 : 0 ;
  749. }
  750. // Fill array 'array_options' with data from add form
  751. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  752. if ($ret < 0) {
  753. $error++;
  754. }
  755. if (!$error && $object->check()) {
  756. if ($object->update($object->id, $user) > 0) {
  757. // Category association
  758. $categories = GETPOST('categories', 'array');
  759. $object->setCategories($categories);
  760. $action = 'view';
  761. } else {
  762. if (count($object->errors)) {
  763. setEventMessages($object->error, $object->errors, 'errors');
  764. } else {
  765. setEventMessages($langs->trans($object->error), null, 'errors');
  766. }
  767. $action = 'edit';
  768. }
  769. } else {
  770. if (count($object->errors)) {
  771. setEventMessages($object->error, $object->errors, 'errors');
  772. } else {
  773. setEventMessages($langs->trans("ErrorProductBadRefOrLabel"), null, 'errors');
  774. }
  775. $action = 'edit';
  776. }
  777. }
  778. }
  779. }
  780. // Action clone object
  781. if ($action == 'confirm_clone' && $confirm != 'yes') {
  782. $action = '';
  783. }
  784. if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
  785. if (!GETPOST('clone_content') && !GETPOST('clone_prices')) {
  786. setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
  787. } else {
  788. if ($object->id > 0) {
  789. $error = 0;
  790. $clone = dol_clone($object, 2);
  791. $clone->id = null;
  792. $clone->ref = GETPOST('clone_ref', 'alphanohtml');
  793. $clone->status = 0;
  794. $clone->status_buy = 0;
  795. $clone->barcode = -1;
  796. if ($clone->check()) {
  797. $db->begin();
  798. $clone->context['createfromclone'] = 'createfromclone';
  799. $id = $clone->create($user);
  800. if ($id > 0) {
  801. if (GETPOST('clone_composition')) {
  802. $result = $clone->clone_associations($object->id, $id);
  803. if ($result < 1) {
  804. setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
  805. setEventMessages($clone->error, $clone->errors, 'errors');
  806. $error++;
  807. }
  808. }
  809. if (!$error && GETPOST('clone_categories')) {
  810. $result = $clone->cloneCategories($object->id, $id);
  811. if ($result < 1) {
  812. setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
  813. setEventMessages($clone->error, $clone->errors, 'errors');
  814. $error++;
  815. }
  816. }
  817. if (!$error && GETPOST('clone_prices')) {
  818. $result = $clone->clone_price($object->id, $id);
  819. if ($result < 1) {
  820. setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
  821. setEventMessages($clone->error, $clone->errors, 'errors');
  822. $error++;
  823. }
  824. }
  825. // $clone->clone_fournisseurs($object->id, $id);
  826. } else {
  827. if ($clone->error == 'ErrorProductAlreadyExists') {
  828. $refalreadyexists++;
  829. $action = "";
  830. $mesg = $langs->trans("ErrorProductAlreadyExists", $clone->ref);
  831. $mesg .= ' <a href="' . $_SERVER["PHP_SELF"] . '?ref=' . $clone->ref . '">' . $langs->trans("ShowCardHere") . '</a>.';
  832. setEventMessages($mesg, null, 'errors');
  833. } else {
  834. if (count($clone->errors)) {
  835. setEventMessages($clone->error, $clone->errors, 'errors');
  836. dol_print_error($db, $clone->errors);
  837. } else {
  838. setEventMessages($langs->trans($clone->error), null, 'errors');
  839. dol_print_error($db, $clone->error);
  840. }
  841. }
  842. $error++;
  843. }
  844. unset($clone->context['createfromclone']);
  845. if ($error) {
  846. $db->rollback();
  847. } else {
  848. $db->commit();
  849. $db->close();
  850. header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
  851. exit;
  852. }
  853. } else {
  854. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NewRefForClone")), null, 'errors');
  855. }
  856. } else {
  857. dol_print_error($db, $object->error);
  858. }
  859. }
  860. $action = 'clone';
  861. }
  862. // Delete a product
  863. if ($action == 'confirm_delete' && $confirm != 'yes') {
  864. $action = '';
  865. }
  866. if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) {
  867. $result = $object->delete($user);
  868. if ($result > 0) {
  869. header('Location: '.DOL_URL_ROOT.'/product/list.php?type='.$object->type.'&delprod='.urlencode($object->ref));
  870. exit;
  871. } else {
  872. setEventMessages($langs->trans($object->error), null, 'errors');
  873. $reload = 0;
  874. $action = '';
  875. }
  876. }
  877. // Add product into object
  878. if ($object->id > 0 && $action == 'addin') {
  879. $thirpdartyid = 0;
  880. if (GETPOST('propalid') > 0) {
  881. $propal = new Propal($db);
  882. $result = $propal->fetch(GETPOST('propalid'));
  883. if ($result <= 0) {
  884. dol_print_error($db, $propal->error);
  885. exit;
  886. }
  887. $thirpdartyid = $propal->socid;
  888. } elseif (GETPOST('commandeid') > 0) {
  889. $commande = new Commande($db);
  890. $result = $commande->fetch(GETPOST('commandeid'));
  891. if ($result <= 0) {
  892. dol_print_error($db, $commande->error);
  893. exit;
  894. }
  895. $thirpdartyid = $commande->socid;
  896. } elseif (GETPOST('factureid') > 0) {
  897. $facture = new Facture($db);
  898. $result = $facture->fetch(GETPOST('factureid'));
  899. if ($result <= 0) {
  900. dol_print_error($db, $facture->error);
  901. exit;
  902. }
  903. $thirpdartyid = $facture->socid;
  904. }
  905. if ($thirpdartyid > 0) {
  906. $soc = new Societe($db);
  907. $result = $soc->fetch($thirpdartyid);
  908. if ($result <= 0) {
  909. dol_print_error($db, $soc->error);
  910. exit;
  911. }
  912. $desc = $object->description;
  913. $tva_tx = get_default_tva($mysoc, $soc, $object->id);
  914. $tva_npr = get_default_npr($mysoc, $soc, $object->id);
  915. if (empty($tva_tx)) {
  916. $tva_npr = 0;
  917. }
  918. $localtax1_tx = get_localtax($tva_tx, 1, $soc, $mysoc, $tva_npr);
  919. $localtax2_tx = get_localtax($tva_tx, 2, $soc, $mysoc, $tva_npr);
  920. $pu_ht = $object->price;
  921. $pu_ttc = $object->price_ttc;
  922. $price_base_type = $object->price_base_type;
  923. // If multiprice
  924. if ($conf->global->PRODUIT_MULTIPRICES && $soc->price_level) {
  925. $pu_ht = $object->multiprices[$soc->price_level];
  926. $pu_ttc = $object->multiprices_ttc[$soc->price_level];
  927. $price_base_type = $object->multiprices_base_type[$soc->price_level];
  928. } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
  929. require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
  930. $prodcustprice = new Productcustomerprice($db);
  931. $filter = array('t.fk_product' => $object->id, 't.fk_soc' => $soc->id);
  932. $result = $prodcustprice->fetchAll('', '', 0, 0, $filter);
  933. if ($result) {
  934. if (count($prodcustprice->lines) > 0) {
  935. $pu_ht = price($prodcustprice->lines [0]->price);
  936. $pu_ttc = price($prodcustprice->lines [0]->price_ttc);
  937. $price_base_type = $prodcustprice->lines [0]->price_base_type;
  938. $tva_tx = $prodcustprice->lines [0]->tva_tx;
  939. }
  940. }
  941. }
  942. $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
  943. $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
  944. // On reevalue prix selon taux tva car taux tva transaction peut etre different
  945. // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
  946. if ($tmpvat != $tmpprodvat) {
  947. if ($price_base_type != 'HT') {
  948. $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
  949. } else {
  950. $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
  951. }
  952. }
  953. if (GETPOST('propalid') > 0) {
  954. // Define cost price for margin calculation
  955. $buyprice = 0;
  956. if (($result = $propal->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) {
  957. dol_syslog($langs->trans('FailedToGetCostPrice'));
  958. setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors');
  959. } else {
  960. $buyprice = $result;
  961. }
  962. $result = $propal->addline(
  963. $desc,
  964. $pu_ht,
  965. price2num(GETPOST('qty'), 'MS'),
  966. $tva_tx,
  967. $localtax1_tx, // localtax1
  968. $localtax2_tx, // localtax2
  969. $object->id,
  970. price2num(GETPOST('remise_percent'), '', 2),
  971. $price_base_type,
  972. $pu_ttc,
  973. 0,
  974. 0,
  975. -1,
  976. 0,
  977. 0,
  978. 0,
  979. $buyprice,
  980. '',
  981. '',
  982. '',
  983. 0,
  984. $object->fk_unit
  985. );
  986. if ($result > 0) {
  987. header("Location: ".DOL_URL_ROOT."/comm/propal/card.php?id=".$propal->id);
  988. return;
  989. }
  990. setEventMessages($langs->trans("ErrorUnknown").": $result", null, 'errors');
  991. } elseif (GETPOST('commandeid') > 0) {
  992. // Define cost price for margin calculation
  993. $buyprice = 0;
  994. if (($result = $commande->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) {
  995. dol_syslog($langs->trans('FailedToGetCostPrice'));
  996. setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors');
  997. } else {
  998. $buyprice = $result;
  999. }
  1000. $result = $commande->addline(
  1001. $desc,
  1002. $pu_ht,
  1003. price2num(GETPOST('qty'), 'MS'),
  1004. $tva_tx,
  1005. $localtax1_tx, // localtax1
  1006. $localtax2_tx, // localtax2
  1007. $object->id,
  1008. price2num(GETPOST('remise_percent'), '', 2),
  1009. '',
  1010. '',
  1011. $price_base_type,
  1012. $pu_ttc,
  1013. '',
  1014. '',
  1015. 0,
  1016. -1,
  1017. 0,
  1018. 0,
  1019. null,
  1020. $buyprice,
  1021. '',
  1022. 0,
  1023. $object->fk_unit
  1024. );
  1025. if ($result > 0) {
  1026. header("Location: ".DOL_URL_ROOT."/commande/card.php?id=".urlencode($commande->id));
  1027. exit;
  1028. }
  1029. } elseif (GETPOST('factureid') > 0) {
  1030. // Define cost price for margin calculation
  1031. $buyprice = 0;
  1032. if (($result = $facture->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) {
  1033. dol_syslog($langs->trans('FailedToGetCostPrice'));
  1034. setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors');
  1035. } else {
  1036. $buyprice = $result;
  1037. }
  1038. $result = $facture->addline(
  1039. $desc,
  1040. $pu_ht,
  1041. price2num(GETPOST('qty'), 'MS'),
  1042. $tva_tx,
  1043. $localtax1_tx,
  1044. $localtax2_tx,
  1045. $object->id,
  1046. price2num(GETPOST('remise_percent'), '', 2),
  1047. '',
  1048. '',
  1049. '',
  1050. '',
  1051. '',
  1052. $price_base_type,
  1053. $pu_ttc,
  1054. Facture::TYPE_STANDARD,
  1055. -1,
  1056. 0,
  1057. '',
  1058. 0,
  1059. 0,
  1060. null,
  1061. $buyprice,
  1062. '',
  1063. 0,
  1064. 100,
  1065. '',
  1066. $object->fk_unit
  1067. );
  1068. if ($result > 0) {
  1069. header("Location: ".DOL_URL_ROOT."/compta/facture/card.php?facid=".$facture->id);
  1070. exit;
  1071. }
  1072. }
  1073. } else {
  1074. $action = "";
  1075. setEventMessages($langs->trans("WarningSelectOneDocument"), null, 'warnings');
  1076. }
  1077. }
  1078. }
  1079. /*
  1080. * View
  1081. */
  1082. $form = new Form($db);
  1083. $formfile = new FormFile($db);
  1084. $formproduct = new FormProduct($db);
  1085. $formcompany = new FormCompany($db);
  1086. if (isModEnabled('accounting')) {
  1087. $formaccounting = new FormAccounting($db);
  1088. }
  1089. $title = $langs->trans('ProductServiceCard');
  1090. $help_url = '';
  1091. $shortlabel = dol_trunc($object->label, 16);
  1092. if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
  1093. if ($action == 'create') {
  1094. $title = $langs->trans("NewProduct");
  1095. } else {
  1096. $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Card');
  1097. $help_url = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos|DE:Modul_Produkte';
  1098. }
  1099. }
  1100. if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
  1101. if ($action == 'create') {
  1102. $title = $langs->trans("NewService");
  1103. } else {
  1104. $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Card');
  1105. $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Leistungen';
  1106. }
  1107. }
  1108. llxHeader('', $title, $help_url);
  1109. // Load object modBarCodeProduct
  1110. $res = 0;
  1111. if (isModEnabled('barcode') && !empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) {
  1112. $module = strtolower($conf->global->BARCODE_PRODUCT_ADDON_NUM);
  1113. $dirbarcode = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
  1114. foreach ($dirbarcode as $dirroot) {
  1115. $res = dol_include_once($dirroot.$module.'.php');
  1116. if ($res) {
  1117. break;
  1118. }
  1119. }
  1120. if ($res > 0) {
  1121. $modBarCodeProduct = new $module();
  1122. }
  1123. }
  1124. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
  1125. // -----------------------------------------
  1126. // When used with CANVAS
  1127. // -----------------------------------------
  1128. if (empty($object->error) && $id) {
  1129. $result = $object->fetch($id);
  1130. if ($result <= 0) {
  1131. dol_print_error('', $object->error);
  1132. }
  1133. }
  1134. $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
  1135. $objcanvas->display_canvas($action); // Show template
  1136. } else {
  1137. // -----------------------------------------
  1138. // When used in standard mode
  1139. // -----------------------------------------
  1140. if ($action == 'create' && $usercancreate) {
  1141. //WYSIWYG Editor
  1142. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1143. if (!empty($conf->use_javascript_ajax)) {
  1144. print '<script type="text/javascript">';
  1145. print '$(document).ready(function () {
  1146. $("#selectcountry_id").change(function() {
  1147. document.formprod.action.value="create";
  1148. document.formprod.submit();
  1149. });
  1150. });';
  1151. print '</script>'."\n";
  1152. }
  1153. // Load object modCodeProduct
  1154. $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard');
  1155. if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') {
  1156. $module = substr($module, 0, dol_strlen($module) - 4);
  1157. }
  1158. $result = dol_include_once('/core/modules/product/'.$module.'.php');
  1159. if ($result > 0) {
  1160. $modCodeProduct = new $module();
  1161. }
  1162. dol_set_focus('input[name="ref"]');
  1163. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formprod">';
  1164. print '<input type="hidden" name="token" value="'.newToken().'">';
  1165. print '<input type="hidden" name="action" value="add">';
  1166. print '<input type="hidden" name="type" value="'.$type.'">'."\n";
  1167. if (!empty($modCodeProduct->code_auto)) {
  1168. print '<input type="hidden" name="code_auto" value="1">';
  1169. }
  1170. if (!empty($modBarCodeProduct->code_auto)) {
  1171. print '<input type="hidden" name="barcode_auto" value="1">';
  1172. }
  1173. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  1174. if ($type == 1) {
  1175. $picto = 'service';
  1176. $title = $langs->trans("NewService");
  1177. } else {
  1178. $picto = 'product';
  1179. $title = $langs->trans("NewProduct");
  1180. }
  1181. $linkback = "";
  1182. print load_fiche_titre($title, $linkback, $picto);
  1183. // We set country_id, country_code and country for the selected country
  1184. $object->country_id = GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : null;
  1185. if ($object->country_id > 0) {
  1186. $tmparray = getCountry($object->country_id, 'all');
  1187. $object->country_code = $tmparray['code'];
  1188. $object->country = $tmparray['label'];
  1189. }
  1190. print dol_get_fiche_head('');
  1191. print '<table class="border centpercent">';
  1192. if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
  1193. print '<tr>';
  1194. $tmpcode = '';
  1195. if (!empty($modCodeProduct->code_auto)) {
  1196. $tmpcode = $modCodeProduct->getNextValue($object, $type);
  1197. }
  1198. print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="ref" name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref', 'alphanohtml') : $tmpcode).'">';
  1199. if ($refalreadyexists) {
  1200. print $langs->trans("RefAlreadyExists");
  1201. }
  1202. print '</td></tr>';
  1203. }
  1204. // Label
  1205. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label', $label_security_check)).'"></td></tr>';
  1206. // On sell
  1207. print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
  1208. $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
  1209. print $form->selectarray('statut', $statutarray, GETPOST('statut'));
  1210. print '</td></tr>';
  1211. // To buy
  1212. print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
  1213. $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
  1214. print $form->selectarray('statut_buy', $statutarray, GETPOST('statut_buy'));
  1215. print '</td></tr>';
  1216. // Batch number management
  1217. if (isModEnabled('productbatch')) {
  1218. print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
  1219. $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial"));
  1220. print $form->selectarray('status_batch', $statutarray, GETPOST('status_batch'));
  1221. print '</td></tr>';
  1222. // Product specific batch number management
  1223. $status_batch = GETPOST('status_batch');
  1224. if ($status_batch !== '0') {
  1225. $langs->load("admin");
  1226. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
  1227. $tooltip .= '<br>'.$langs->trans("GenericMaskCodes2");
  1228. $tooltip .= '<br>'.$langs->trans("GenericMaskCodes3");
  1229. $tooltip .= '<br>'.$langs->trans("GenericMaskCodes4a", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
  1230. $tooltip .= '<br>'.$langs->trans("GenericMaskCodes5");
  1231. if ((!empty($conf->global->PRODUCTBATCH_LOT_USE_PRODUCT_MASKS) && $conf->global->PRODUCTBATCH_LOT_ADDON == 'mod_lot_advanced')
  1232. || (!empty($conf->global->PRODUCTBATCH_SN_USE_PRODUCT_MASKS) && $conf->global->PRODUCTBATCH_SN_ADDON == 'mod_sn_advanced')) {
  1233. print '<tr><td id="mask_option">'.$langs->trans("ManageLotMask").'</td>';
  1234. $inherited_mask_lot = getDolGlobalString('LOT_ADVANCED_MASK');
  1235. $inherited_mask_sn = getDolGlobalString('SN_ADVANCED_MASK');
  1236. print '<td id="field_mask">';
  1237. print $form->textwithpicto('<input type="text" class="flat minwidth175" name="batch_mask" id="batch_mask_input">', $tooltip, 1, 1);
  1238. print '<script type="text/javascript">
  1239. $(document).ready(function() {
  1240. $("#field_mask, #mask_option").addClass("hideobject");
  1241. $("#status_batch").on("change", function () {
  1242. console.log("We change batch status");
  1243. var optionSelected = $("option:selected", this);
  1244. var valueSelected = this.value;
  1245. $("#field_mask, #mask_option").addClass("hideobject");
  1246. ';
  1247. if (getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced') {
  1248. print '
  1249. if (this.value == 1) {
  1250. $("#field_mask, #mask_option").toggleClass("hideobject");
  1251. $("#batch_mask_input").val("'.$inherited_mask_lot.'");
  1252. }
  1253. ';
  1254. }
  1255. if ($conf->global->PRODUCTBATCH_SN_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_SN_ADDON == 'mod_sn_advanced') {
  1256. print '
  1257. if (this.value == 2) {
  1258. $("#field_mask, #mask_option").toggleClass("hideobject");
  1259. $("#batch_mask_input").val("'.$inherited_mask_sn.'");
  1260. }
  1261. ';
  1262. }
  1263. print '
  1264. })
  1265. })
  1266. </script>';
  1267. print '</td></tr>';
  1268. }
  1269. }
  1270. }
  1271. $showbarcode = isModEnabled('barcode');
  1272. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
  1273. $showbarcode = 0;
  1274. }
  1275. if ($showbarcode) {
  1276. print '<tr><td>'.$langs->trans('BarcodeType').'</td><td>';
  1277. if (GETPOSTISSET('fk_barcode_type')) {
  1278. $fk_barcode_type = GETPOST('fk_barcode_type')?GETPOST('fk_barcode_type'):0;
  1279. } else {
  1280. if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) {
  1281. $fk_barcode_type = getDolGlobalInt("PRODUIT_DEFAULT_BARCODE_TYPE");
  1282. } else {
  1283. $fk_barcode_type=0;
  1284. }
  1285. }
  1286. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
  1287. $formbarcode = new FormBarCode($db);
  1288. print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
  1289. print '</td>';
  1290. print '</tr><tr>';
  1291. print '<td>'.$langs->trans("BarcodeValue").'</td><td>';
  1292. $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
  1293. if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) {
  1294. $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
  1295. }
  1296. print img_picto('', 'barcode', 'class="pictofixedwidth"');
  1297. print '<input class="maxwidth100" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
  1298. print '</td></tr>';
  1299. }
  1300. // Description (used in invoice, propal...)
  1301. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  1302. $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_DETAILS'), ROWS_4, '90%');
  1303. $doleditor->Create();
  1304. print "</td></tr>";
  1305. if (empty($conf->global->PRODUCT_DISABLE_PUBLIC_URL)) {
  1306. // Public URL
  1307. print '<tr><td>'.$langs->trans("PublicUrl").'</td><td>';
  1308. print img_picto('', 'globe', 'class="pictofixedwidth"');
  1309. print '<input type="text" name="url" class="quatrevingtpercent" value="'.GETPOST('url').'">';
  1310. print '</td></tr>';
  1311. }
  1312. if ($type != 1 && isModEnabled('stock')) {
  1313. // Default warehouse
  1314. print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
  1315. print img_picto($langs->trans("DefaultWarehouse"), 'stock', 'class="pictofixedwidth"');
  1316. print $formproduct->selectWarehouses(GETPOST('fk_default_warehouse', 'int'), 'fk_default_warehouse', 'warehouseopen', 1, 0, 0, '', 0, 0, array(), 'minwidth300 widthcentpercentminusxx maxwidth500');
  1317. print ' <a href="'.DOL_URL_ROOT.'/product/stock/card.php?action=create&token='.newToken().'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create&token='.newToken()).'">';
  1318. print '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddWarehouse").'"></span>';
  1319. print '</a>';
  1320. print '</td>';
  1321. print '</tr>';
  1322. if (empty($conf->global->PRODUCT_DISABLE_STOCK_LEVELS)) {
  1323. // Stock min level
  1324. print '<tr><td>'.$form->textwithpicto($langs->trans("StockLimit"), $langs->trans("StockLimitDesc"), 1).'</td><td>';
  1325. print '<input name="seuil_stock_alerte" class="maxwidth50" value="'.GETPOST('seuil_stock_alerte').'">';
  1326. print '</td>';
  1327. print '</tr>';
  1328. // Stock desired level
  1329. print '<tr><td>'.$form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1).'</td><td>';
  1330. print '<input name="desiredstock" class="maxwidth50" value="'.GETPOST('desiredstock').'">';
  1331. print '</td></tr>';
  1332. }
  1333. } else {
  1334. if (empty($conf->global->PRODUCT_DISABLE_STOCK_LEVELS)) {
  1335. print '<input name="seuil_stock_alerte" type="hidden" value="0">';
  1336. print '<input name="desiredstock" type="hidden" value="0">';
  1337. }
  1338. }
  1339. if ($type == 1 && isModEnabled("workstation")) {
  1340. // Default workstation
  1341. print '<tr><td>'.$langs->trans("DefaultWorkstation").'</td><td>';
  1342. print img_picto($langs->trans("DefaultWorkstation"), 'workstation', 'class="pictofixedwidth"');
  1343. print $formproduct->selectWorkstations($object->fk_default_workstation, 'fk_default_workstation', 1);
  1344. print '</td></tr>';
  1345. }
  1346. // Duration
  1347. if ($type == 1) {
  1348. print '<tr><td>'.$langs->trans("Duration").'</td><td>';
  1349. print img_picto('', 'clock', 'class="pictofixedwidth"');
  1350. print '<input name="duration_value" size="4" value="'.GETPOST('duration_value', 'int').'">';
  1351. print $formproduct->selectMeasuringUnits("duration_unit", "time", (GETPOSTISSET('duration_value') ? GETPOST('duration_value', 'alpha') : 'h'), 0, 1);
  1352. // Mandatory period
  1353. print ' &nbsp; &nbsp; &nbsp; ';
  1354. print '<input type="checkbox" id="mandatoryperiod" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').'>';
  1355. print '<label for="mandatoryperiod">';
  1356. $htmltooltip = $langs->trans("mandatoryHelper");
  1357. print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 0);
  1358. print '</label>';
  1359. print '</td></tr>';
  1360. }
  1361. if ($type != 1) { // Nature, Weight and volume only applies to products and not to services
  1362. if (empty($conf->global->PRODUCT_DISABLE_NATURE)) {
  1363. // Nature
  1364. print '<tr><td>'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
  1365. print $formproduct->selectProductNature('finished', $object->finished);
  1366. print '</td></tr>';
  1367. }
  1368. }
  1369. if ($type != 1) {
  1370. if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) {
  1371. // Brut Weight
  1372. print '<tr><td>'.$langs->trans("Weight").'</td><td>';
  1373. print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"');
  1374. print '<input name="weight" size="4" value="'.GETPOST('weight').'">';
  1375. print $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOSTISSET('weight_units') ?GETPOST('weight_units', 'alpha') : (empty($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? 0 : $conf->global->MAIN_WEIGHT_DEFAULT_UNIT), 0, 2);
  1376. print '</td></tr>';
  1377. }
  1378. // Brut Length
  1379. if (empty($conf->global->PRODUCT_DISABLE_SIZE)) {
  1380. print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td>';
  1381. print img_picto('', 'fa-ruler', 'class="pictofixedwidth"');
  1382. print '<input name="size" class="width50" value="'.GETPOST('size').'"> x ';
  1383. print '<input name="sizewidth" class="width50" value="'.GETPOST('sizewidth').'"> x ';
  1384. print '<input name="sizeheight" class="width50" value="'.GETPOST('sizeheight').'">';
  1385. print $formproduct->selectMeasuringUnits("size_units", "size", GETPOSTISSET('size_units') ?GETPOST('size_units', 'alpha') : '0', 0, 2);
  1386. print '</td></tr>';
  1387. }
  1388. if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) {
  1389. // Brut Surface
  1390. print '<tr><td>'.$langs->trans("Surface").'</td><td>';
  1391. print '<input name="surface" size="4" value="'.GETPOST('surface').'">';
  1392. print $formproduct->selectMeasuringUnits("surface_units", "surface", GETPOSTISSET('surface_units') ?GETPOST('surface_units', 'alpha') : '0', 0, 2);
  1393. print '</td></tr>';
  1394. }
  1395. if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) {
  1396. // Brut Volume
  1397. print '<tr><td>'.$langs->trans("Volume").'</td><td>';
  1398. print '<input name="volume" size="4" value="'.GETPOST('volume').'">';
  1399. print $formproduct->selectMeasuringUnits("volume_units", "volume", GETPOSTISSET('volume_units') ?GETPOST('volume_units', 'alpha') : '0', 0, 2);
  1400. print '</td></tr>';
  1401. }
  1402. if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) {
  1403. // Net Measure
  1404. print '<tr><td>'.$langs->trans("NetMeasure").'</td><td>';
  1405. print '<input name="net_measure" size="4" value="'.GETPOST('net_measure').'">';
  1406. print $formproduct->selectMeasuringUnits("net_measure_units", '', GETPOSTISSET('net_measure_units') ?GETPOST('net_measure_units', 'alpha') : (empty($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? 0 : $conf->global->MAIN_WEIGHT_DEFAULT_UNIT), 0, 0);
  1407. print '</td></tr>';
  1408. }
  1409. }
  1410. // Units
  1411. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  1412. print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td>';
  1413. print '<td>';
  1414. print $form->selectUnits(empty($line->fk_unit) ? $conf->global->PRODUCT_USE_UNITS : $line->fk_unit, 'units');
  1415. print '</td></tr>';
  1416. }
  1417. // Custom code
  1418. if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO) && empty($type)) {
  1419. print '<tr><td class="wordbreak">'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.GETPOST('customcode').'"></td></tr>';
  1420. // Origin country
  1421. print '<tr><td>'.$langs->trans("CountryOrigin").'</td>';
  1422. print '<td>';
  1423. print img_picto('', 'globe-americas', 'class="pictofixedwidth"');
  1424. print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 widthcentpercentminusx maxwidth500');
  1425. if ($user->admin) {
  1426. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1427. }
  1428. print '</td></tr>';
  1429. // State
  1430. if (empty($conf->global->PRODUCT_DISABLE_STATE)) {
  1431. print '<tr>';
  1432. if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) {
  1433. print '<td>'.$form->editfieldkey('RegionStateOrigin', 'state_id', '', $object, 0).'</td><td>';
  1434. } else {
  1435. print '<td>'.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).'</td><td>';
  1436. }
  1437. print img_picto('', 'state', 'class="pictofixedwidth"');
  1438. print $formcompany->select_state($object->state_id, $object->country_code);
  1439. print '</tr>';
  1440. }
  1441. }
  1442. // Quality control
  1443. if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
  1444. print '<tr><td>'.$langs->trans("LifeTime").'</td><td><input name="lifetime" class="maxwidth50" value="'.GETPOST('lifetime').'"></td></tr>';
  1445. print '<tr><td>'.$langs->trans("QCFrequency").'</td><td><input name="qc_frequency" class="maxwidth50" value="'.GETPOST('qc_frequency').'"></td></tr>';
  1446. }
  1447. // Other attributes
  1448. $parameters = array('colspan' => ' colspan="2"', 'cols'=>2);
  1449. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1450. print $hookmanager->resPrint;
  1451. if (empty($reshook)) {
  1452. print $object->showOptionals($extrafields, 'create', $parameters);
  1453. }
  1454. // Note (private, no output on invoices, propales...)
  1455. //if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) available in create mode
  1456. //{
  1457. print '<tr><td class="tdtop">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>';
  1458. // We use dolibarr_details as type of DolEditor here, because we must not accept images as description is included into PDF and not accepted by TCPDF.
  1459. $doleditor = new DolEditor('note_private', GETPOST('note_private', 'restricthtml'), '', 140, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE'), ROWS_8, '90%');
  1460. $doleditor->Create();
  1461. print "</td></tr>";
  1462. //}
  1463. if (isModEnabled('categorie')) {
  1464. // Categories
  1465. print '<tr><td>'.$langs->trans("Categories").'</td><td>';
  1466. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1);
  1467. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1468. print "</td></tr>";
  1469. }
  1470. print '</table>';
  1471. print '<hr>';
  1472. if (empty($conf->global->PRODUCT_DISABLE_PRICES)) {
  1473. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  1474. // We do no show price array on create when multiprices enabled.
  1475. // We must set them on prices tab.
  1476. print '<table class="border centpercent">';
  1477. // VAT
  1478. print '<tr><td class="titlefieldcreate">'.$langs->trans("VATRate").'</td><td>';
  1479. $defaultva = get_default_tva($mysoc, $mysoc);
  1480. print $form->load_tva("tva_tx", $defaultva, $mysoc, $mysoc, 0, 0, '', false, 1);
  1481. print '</td></tr>';
  1482. print '</table>';
  1483. print '<br>';
  1484. } else {
  1485. print '<table class="border centpercent">';
  1486. // Price
  1487. print '<tr><td class="titlefieldcreate">'.$langs->trans("SellingPrice").'</td>';
  1488. print '<td><input name="price" class="maxwidth50" value="'.$object->price.'">';
  1489. print $form->selectPriceBaseType($conf->global->PRODUCT_PRICE_BASE_TYPE, "price_base_type");
  1490. print '</td></tr>';
  1491. // Min price
  1492. print '<tr><td>'.$langs->trans("MinPrice").'</td>';
  1493. print '<td><input name="price_min" class="maxwidth50" value="'.$object->price_min.'">';
  1494. print '</td></tr>';
  1495. // VAT
  1496. print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
  1497. $defaultva = get_default_tva($mysoc, $mysoc);
  1498. print $form->load_tva("tva_tx", $defaultva, $mysoc, $mysoc, 0, 0, '', false, 1);
  1499. print '</td></tr>';
  1500. print '</table>';
  1501. print '<br>';
  1502. }
  1503. }
  1504. // Accountancy codes
  1505. print '<!-- accountancy codes -->'."\n";
  1506. print '<table class="border centpercent">';
  1507. if (empty($conf->global->PRODUCT_DISABLE_ACCOUNTING)) {
  1508. if (isModEnabled('accounting')) {
  1509. // Accountancy_code_sell
  1510. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  1511. print '<td>';
  1512. if ($type == 0) {
  1513. $accountancy_code_sell = (GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_SOLD_ACCOUNT"));
  1514. } else {
  1515. $accountancy_code_sell = (GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_SOLD_ACCOUNT"));
  1516. }
  1517. print $formaccounting->select_account($accountancy_code_sell, 'accountancy_code_sell', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
  1518. print '</td></tr>';
  1519. // Accountancy_code_sell_intra
  1520. if ($mysoc->isInEEC()) {
  1521. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
  1522. print '<td>';
  1523. if ($type == 0) {
  1524. $accountancy_code_sell_intra = (GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT"));
  1525. } else {
  1526. $accountancy_code_sell_intra = (GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT"));
  1527. }
  1528. print $formaccounting->select_account($accountancy_code_sell_intra, 'accountancy_code_sell_intra', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
  1529. print '</td></tr>';
  1530. }
  1531. // Accountancy_code_sell_export
  1532. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
  1533. print '<td>';
  1534. if ($type == 0) {
  1535. $accountancy_code_sell_export = (GETPOST('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT"));
  1536. } else {
  1537. $accountancy_code_sell_export = (GETPOST('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT"));
  1538. }
  1539. print $formaccounting->select_account($accountancy_code_sell_export, 'accountancy_code_sell_export', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
  1540. print '</td></tr>';
  1541. // Accountancy_code_buy
  1542. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  1543. print '<td>';
  1544. if ($type == 0) {
  1545. $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : getDolGlobalString("ACCOUNTING_PRODUCT_BUY_ACCOUNT"));
  1546. } else {
  1547. $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : getDolGlobalString("ACCOUNTING_SERVICE_BUY_ACCOUNT"));
  1548. }
  1549. print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
  1550. print '</td></tr>';
  1551. // Accountancy_code_buy_intra
  1552. if ($mysoc->isInEEC()) {
  1553. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
  1554. print '<td>';
  1555. if ($type == 0) {
  1556. $accountancy_code_buy_intra = (GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT"));
  1557. } else {
  1558. $accountancy_code_buy_intra = (GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT"));
  1559. }
  1560. print $formaccounting->select_account($accountancy_code_buy_intra, 'accountancy_code_buy_intra', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
  1561. print '</td></tr>';
  1562. }
  1563. // Accountancy_code_buy_export
  1564. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
  1565. print '<td>';
  1566. if ($type == 0) {
  1567. $accountancy_code_buy_export = (GETPOST('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export', 'alpha') : getDolGlobalString("ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT"));
  1568. } else {
  1569. $accountancy_code_buy_export = (GETPOST('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export', 'alpha') : getDolGlobalString("ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT"));
  1570. }
  1571. print $formaccounting->select_account($accountancy_code_buy_export, 'accountancy_code_buy_export', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
  1572. print '</td></tr>';
  1573. } else {// For external software
  1574. if (!empty($accountancy_code_sell)) {
  1575. $object->accountancy_code_sell = $accountancy_code_sell;
  1576. }
  1577. if (!empty($accountancy_code_sell_intra)) {
  1578. $object->accountancy_code_sell_intra = $accountancy_code_sell_intra;
  1579. }
  1580. if (!empty($accountancy_code_sell_export)) {
  1581. $object->accountancy_code_sell_export = $accountancy_code_sell_export;
  1582. }
  1583. if (!empty($accountancy_code_buy)) {
  1584. $object->accountancy_code_buy = $accountancy_code_buy;
  1585. }
  1586. if (!empty($accountancy_code_buy_intra)) {
  1587. $object->accountancy_code_buy_intra = $accountancy_code_buy_intra;
  1588. }
  1589. if (!empty($accountancy_code_buy_export)) {
  1590. $object->accountancy_code_buy_export = $accountancy_code_buy_export;
  1591. }
  1592. // Accountancy_code_sell
  1593. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  1594. print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
  1595. print '</td></tr>';
  1596. // Accountancy_code_sell_intra
  1597. if ($mysoc->isInEEC()) {
  1598. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
  1599. print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_sell_intra" value="'.$object->accountancy_code_sell_intra.'">';
  1600. print '</td></tr>';
  1601. }
  1602. // Accountancy_code_sell_export
  1603. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
  1604. print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_sell_export" value="'.$object->accountancy_code_sell_export.'">';
  1605. print '</td></tr>';
  1606. // Accountancy_code_buy
  1607. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  1608. print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
  1609. print '</td></tr>';
  1610. // Accountancy_code_buy_intra
  1611. if ($mysoc->isInEEC()) {
  1612. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
  1613. print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_buy_intra" value="'.$object->accountancy_code_buy_intra.'">';
  1614. print '</td></tr>';
  1615. }
  1616. // Accountancy_code_buy_export
  1617. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
  1618. print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_buy_export" value="'.$object->accountancy_code_buy_export.'">';
  1619. print '</td></tr>';
  1620. }
  1621. }
  1622. print '</table>';
  1623. print dol_get_fiche_end();
  1624. print $form->buttonsSaveCancel("Create");
  1625. print '</form>';
  1626. } elseif ($object->id > 0) {
  1627. /*
  1628. * Product card
  1629. */
  1630. // Fiche en mode edition
  1631. if ($action == 'edit' && $usercancreate) {
  1632. //WYSIWYG Editor
  1633. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1634. if (!empty($conf->use_javascript_ajax)) {
  1635. print '<script type="text/javascript">';
  1636. print '$(document).ready(function () {
  1637. $("#selectcountry_id").change(function () {
  1638. document.formprod.action.value="edit";
  1639. document.formprod.submit();
  1640. });
  1641. });';
  1642. print '</script>'."\n";
  1643. }
  1644. // We set country_id, country_code and country for the selected country
  1645. $object->country_id = GETPOST('country_id') ? GETPOST('country_id') : $object->country_id;
  1646. if ($object->country_id) {
  1647. $tmparray = getCountry($object->country_id, 'all');
  1648. $object->country_code = $tmparray['code'];
  1649. $object->country = $tmparray['label'];
  1650. }
  1651. $type = $langs->trans('Product');
  1652. if ($object->isService()) {
  1653. $type = $langs->trans('Service');
  1654. }
  1655. // print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), "");
  1656. // Main official, simple, and not duplicated code
  1657. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST" name="formprod">'."\n";
  1658. print '<input type="hidden" name="token" value="'.newToken().'">';
  1659. print '<input type="hidden" name="action" value="update">';
  1660. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1661. print '<input type="hidden" name="canvas" value="'.$object->canvas.'">';
  1662. $head = product_prepare_head($object);
  1663. $titre = $langs->trans("CardProduct".$object->type);
  1664. $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  1665. print dol_get_fiche_head($head, 'card', $titre, 0, $picto);
  1666. print '<table class="border allwidth">';
  1667. // Ref
  1668. if (empty($conf->global->MAIN_PRODUCT_REF_NOT_EDITABLE)) {
  1669. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref') : $object->ref).'"></td></tr>';
  1670. } else {
  1671. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag($object->ref).'" readonly="true"></td></tr>';
  1672. }
  1673. // Label
  1674. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag(GETPOSTISSET('label') ? GETPOST('label') : $object->label).'"></td></tr>';
  1675. // Status To sell
  1676. print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  1677. print '<select class="flat" name="statut">';
  1678. if ((GETPOSTISSET('statut') && GETPOST('statut')) || (!GETPOSTISSET('statut') && $object->status)) {
  1679. print '<option value="1" selected>'.$langs->trans("OnSell").'</option>';
  1680. print '<option value="0">'.$langs->trans("NotOnSell").'</option>';
  1681. } else {
  1682. print '<option value="1">'.$langs->trans("OnSell").'</option>';
  1683. print '<option value="0" selected>'.$langs->trans("NotOnSell").'</option>';
  1684. }
  1685. print '</select>';
  1686. print '</td></tr>';
  1687. // Status To Buy
  1688. print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  1689. print '<select class="flat" name="statut_buy">';
  1690. if ((GETPOSTISSET('statut_buy') && GETPOST('statut_buy')) || (!GETPOSTISSET('statut_buy') && $object->status_buy)) {
  1691. print '<option value="1" selected>'.$langs->trans("ProductStatusOnBuy").'</option>';
  1692. print '<option value="0">'.$langs->trans("ProductStatusNotOnBuy").'</option>';
  1693. } else {
  1694. print '<option value="1">'.$langs->trans("ProductStatusOnBuy").'</option>';
  1695. print '<option value="0" selected>'.$langs->trans("ProductStatusNotOnBuy").'</option>';
  1696. }
  1697. print '</select>';
  1698. print '</td></tr>';
  1699. // Batch number managment
  1700. if (isModEnabled('productbatch')) {
  1701. if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  1702. print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
  1703. $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial"));
  1704. print $form->selectarray('status_batch', $statutarray, (GETPOSTISSET('status_batch') ? GETPOST('status_batch') : $object->status_batch));
  1705. print '</td></tr>';
  1706. if (!empty($object->status_batch) || !empty($conf->use_javascript_ajax)) {
  1707. $langs->load("admin");
  1708. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
  1709. $tooltip .= '<br>'.$langs->trans("GenericMaskCodes2");
  1710. $tooltip .= '<br>'.$langs->trans("GenericMaskCodes3");
  1711. $tooltip .= '<br>'.$langs->trans("GenericMaskCodes4a", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
  1712. $tooltip .= '<br>'.$langs->trans("GenericMaskCodes5");
  1713. print '<tr><td id="mask_option">'.$langs->trans("ManageLotMask").'</td>';
  1714. if ($object->status_batch == '1' && getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced') {
  1715. $mask = !empty($object->batch_mask) ? $object->batch_mask : getDolGlobalString('LOT_ADVANCED_MASK');
  1716. }
  1717. if ($object->status_batch == '2' && getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_SN_ADDON') == 'mod_sn_advanced') {
  1718. $mask = !empty($object->batch_mask) ? $object->batch_mask : getDolGlobalString('SN_ADVANCED_MASK');
  1719. }
  1720. $inherited_mask_lot = getDolGlobalString('LOT_ADVANCED_MASK');
  1721. $inherited_mask_sn = getDolGlobalString('SN_ADVANCED_MASK');
  1722. print '<td id="field_mask">';
  1723. print $form->textwithpicto('<input type="text" class="flat minwidth175" name="batch_mask" id="batch_mask_input" value="'.$mask.'">', $tooltip, 1, 1);
  1724. // Add javascript to sho/hide field for custom mask
  1725. if (!empty($conf->use_javascript_ajax)) {
  1726. print '<script type="text/javascript">
  1727. $(document).ready(function() {
  1728. $("#field_mask").parent().addClass("hideobject");
  1729. var preselect = document.getElementById("status_batch");';
  1730. if (getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS')) {
  1731. print 'if (preselect.value == "2") {
  1732. $("#field_mask").parent().removeClass("hideobject");
  1733. }';
  1734. }
  1735. if (getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS')) {
  1736. print 'if (preselect.value == "1") {
  1737. $("#field_mask").parent().removeClass("hideobject");
  1738. }';
  1739. }
  1740. print '$("#status_batch").on("change", function () {
  1741. var optionSelected = $("option:selected", this);
  1742. var valueSelected = this.value;
  1743. $("#field_mask").parent().addClass("hideobject");
  1744. ';
  1745. if (getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced') {
  1746. print '
  1747. if (this.value == 1) {
  1748. $("#field_mask").parent().removeClass("hideobject");
  1749. $("#batch_mask_input").val("'.$inherited_mask_lot.'");
  1750. }
  1751. ';
  1752. }
  1753. if (getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_SN_ADDON') == 'mod_sn_advanced') {
  1754. print '
  1755. if (this.value == 2) {
  1756. $("#field_mask").parent().removeClass("hideobject");
  1757. $("#batch_mask_input").val("'.$inherited_mask_sn.'");
  1758. }
  1759. ';
  1760. }
  1761. print '
  1762. })
  1763. })
  1764. </script>';
  1765. }
  1766. print '</td></tr>';
  1767. }
  1768. }
  1769. }
  1770. // Barcode
  1771. $showbarcode = isModEnabled('barcode');
  1772. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
  1773. $showbarcode = 0;
  1774. }
  1775. if ($showbarcode) {
  1776. print '<tr><td>'.$langs->trans('BarcodeType').'</td><td>';
  1777. if (GETPOSTISSET('fk_barcode_type')) {
  1778. $fk_barcode_type = GETPOST('fk_barcode_type');
  1779. } else {
  1780. $fk_barcode_type = $object->barcode_type;
  1781. if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) {
  1782. $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
  1783. }
  1784. }
  1785. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
  1786. $formbarcode = new FormBarCode($db);
  1787. print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
  1788. print '</td></tr>';
  1789. print '<tr><td>'.$langs->trans("BarcodeValue").'</td><td>';
  1790. $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
  1791. if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) {
  1792. $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
  1793. }
  1794. print '<input class="maxwidth150 maxwidthonsmartphone" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
  1795. print '</td></tr>';
  1796. }
  1797. // Description (used in invoice, propal...)
  1798. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  1799. // We use dolibarr_details as type of DolEditor here, because we must not accept images as description is included into PDF and not accepted by TCPDF.
  1800. $doleditor = new DolEditor('desc', GETPOSTISSET('desc') ? GETPOST('desc', 'restricthtml') : $object->description, '', 160, 'dolibarr_details', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_4, '90%');
  1801. $doleditor->Create();
  1802. print "</td></tr>";
  1803. print "\n";
  1804. // Public Url
  1805. if (empty($conf->global->PRODUCT_DISABLE_PUBLIC_URL)) {
  1806. print '<tr><td>'.$langs->trans("PublicUrl").'</td><td>';
  1807. print img_picto('', 'globe', 'class="pictofixedwidth"');
  1808. print '<input type="text" name="url" class="quatrevingtpercent" value="'.(GETPOSTISSET('url') ? GETPOST('url') : $object->url).'">';
  1809. print '</td></tr>';
  1810. }
  1811. // Stock
  1812. if ($object->isProduct() && isModEnabled('stock')) {
  1813. // Default warehouse
  1814. print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
  1815. print img_picto($langs->trans("DefaultWarehouse"), 'stock', 'class="pictofixedwidth"');
  1816. print $formproduct->selectWarehouses((GETPOSTISSET('fk_default_warehouse') ? GETPOST('fk_default_warehouse') : $object->fk_default_warehouse), 'fk_default_warehouse', 'warehouseopen', 1);
  1817. print ' <a href="'.DOL_URL_ROOT.'/product/stock/card.php?action=create&amp;backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'&type='.GETPOST('type', 'int')).'">';
  1818. print '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddWarehouse").'"></span></a>';
  1819. print '</td></tr>';
  1820. /*
  1821. print "<tr>".'<td>'.$langs->trans("StockLimit").'</td><td>';
  1822. print '<input name="seuil_stock_alerte" size="4" value="'.$object->seuil_stock_alerte.'">';
  1823. print '</td>';
  1824. print '<td>'.$langs->trans("DesiredStock").'</td><td>';
  1825. print '<input name="desiredstock" size="4" value="'.$object->desiredstock.'">';
  1826. print '</td></tr>';
  1827. */
  1828. }
  1829. if ($object->isService() && $conf->workstation->enabled) {
  1830. // Default workstation
  1831. print '<tr><td>'.$langs->trans("DefaultWorkstation").'</td><td>';
  1832. print img_picto($langs->trans("DefaultWorkstation"), 'workstation', 'class="pictofixedwidth"');
  1833. print $formproduct->selectWorkstations($object->fk_default_workstation, 'fk_default_workstation', 1);
  1834. print '</td></tr>';
  1835. }
  1836. /*
  1837. else
  1838. {
  1839. print '<input name="seuil_stock_alerte" type="hidden" value="'.$object->seuil_stock_alerte.'">';
  1840. print '<input name="desiredstock" type="hidden" value="'.$object->desiredstock.'">';
  1841. }*/
  1842. if ($object->isService()) {
  1843. // Duration
  1844. print '<tr><td>'.$langs->trans("Duration").'</td><td>';
  1845. print '<input name="duration_value" size="5" value="'.$object->duration_value.'"> ';
  1846. print $formproduct->selectMeasuringUnits("duration_unit", "time", $object->duration_unit, 0, 1);
  1847. // Mandatory period
  1848. print ' &nbsp; &nbsp; &nbsp; ';
  1849. print '<input type="checkbox" id="mandatoryperiod" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').'>';
  1850. print '<label for="mandatoryperiod">';
  1851. $htmltooltip = $langs->trans("mandatoryHelper");
  1852. print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 0);
  1853. print '</label>';
  1854. print '</td></tr>';
  1855. } else {
  1856. if (empty($conf->global->PRODUCT_DISABLE_NATURE)) {
  1857. // Nature
  1858. print '<tr><td>'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
  1859. print $formproduct->selectProductNature('finished', (GETPOSTISSET('finished') ? GETPOST('finished') : $object->finished));
  1860. print '</td></tr>';
  1861. }
  1862. }
  1863. if (!$object->isService() && isModEnabled('bom')) {
  1864. print '<tr><td>'.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc", $langs->transnoentitiesnoconv("Finished"))).'</td><td>';
  1865. $bomkey = "Bom:bom/class/bom.class.php:0:(t.status:=:1) AND (t.fk_product:=:".((int) $object->id).')';
  1866. print $form->selectForForms($bomkey, 'fk_default_bom', (GETPOSTISSET('fk_default_bom') ? GETPOST('fk_default_bom') : $object->fk_default_bom), 1);
  1867. print '</td></tr>';
  1868. }
  1869. if (!$object->isService()) {
  1870. if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) {
  1871. // Brut Weight
  1872. print '<tr><td>'.$langs->trans("Weight").'</td><td>';
  1873. print '<input name="weight" size="5" value="'.(GETPOSTISSET('weight') ? GETPOST('weight') : $object->weight).'"> ';
  1874. print $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOSTISSET('weight_units') ? GETPOST('weight_units') : $object->weight_units, 0, 2);
  1875. print '</td></tr>';
  1876. }
  1877. if (empty($conf->global->PRODUCT_DISABLE_SIZE)) {
  1878. // Brut Length
  1879. print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td>';
  1880. print '<input name="size" size="5" value="'.(GETPOSTISSET('size') ? GETPOST('size') : $object->length).'">x';
  1881. print '<input name="sizewidth" size="5" value="'.(GETPOSTISSET('sizewidth') ? GETPOST('sizewidth') : $object->width).'">x';
  1882. print '<input name="sizeheight" size="5" value="'.(GETPOSTISSET('sizeheight') ? GETPOST('sizeheight') : $object->height).'"> ';
  1883. print $formproduct->selectMeasuringUnits("size_units", "size", GETPOSTISSET('size_units') ? GETPOST('size_units') : $object->length_units, 0, 2);
  1884. print '</td></tr>';
  1885. }
  1886. if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) {
  1887. // Brut Surface
  1888. print '<tr><td>'.$langs->trans("Surface").'</td><td>';
  1889. print '<input name="surface" size="5" value="'.(GETPOSTISSET('surface') ? GETPOST('surface') : $object->surface).'"> ';
  1890. print $formproduct->selectMeasuringUnits("surface_units", "surface", GETPOSTISSET('surface_units') ? GETPOST('surface_units') : $object->surface_units, 0, 2);
  1891. print '</td></tr>';
  1892. }
  1893. if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) {
  1894. // Brut Volume
  1895. print '<tr><td>'.$langs->trans("Volume").'</td><td>';
  1896. print '<input name="volume" size="5" value="'.(GETPOSTISSET('volume') ? GETPOST('volume') : $object->volume).'"> ';
  1897. print $formproduct->selectMeasuringUnits("volume_units", "volume", GETPOSTISSET('volume_units') ? GETPOST('volume_units') : $object->volume_units, 0, 2);
  1898. print '</td></tr>';
  1899. }
  1900. if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) {
  1901. // Net Measure
  1902. print '<tr><td>'.$langs->trans("NetMeasure").'</td><td>';
  1903. print '<input name="net_measure" size="5" value="'.(GETPOSTISSET('net_measure') ? GETPOST('net_measure') : $object->net_measure).'"> ';
  1904. print $formproduct->selectMeasuringUnits("net_measure_units", "", GETPOSTISSET('net_measure_units') ? GETPOST('net_measure_units') : $object->net_measure_units, 0, 0);
  1905. print '</td></tr>';
  1906. }
  1907. }
  1908. // Units
  1909. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  1910. print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td>';
  1911. print '<td>';
  1912. print $form->selectUnits($object->fk_unit, 'units');
  1913. print '</td></tr>';
  1914. }
  1915. // Custom code
  1916. if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) {
  1917. print '<tr><td class="wordbreak">'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.(GETPOSTISSET('customcode') ? GETPOST('customcode') : $object->customcode).'"></td></tr>';
  1918. // Origin country
  1919. print '<tr><td>'.$langs->trans("CountryOrigin").'</td>';
  1920. print '<td>';
  1921. print img_picto('', 'globe-americas', 'class="paddingrightonly"');
  1922. print $form->select_country(GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : $object->country_id, 'country_id', '', 0, 'minwidth100 maxwidthonsmartphone');
  1923. if ($user->admin) {
  1924. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1925. }
  1926. print '</td></tr>';
  1927. // State
  1928. if (empty($conf->global->PRODUCT_DISABLE_STATE)) {
  1929. print '<tr>';
  1930. if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) {
  1931. print '<td>'.$form->editfieldkey('RegionStateOrigin', 'state_id', '', $object, 0).'</td><td>';
  1932. } else {
  1933. print '<td>'.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).'</td><td>';
  1934. }
  1935. print img_picto('', 'state', 'class="pictofixedwidth"');
  1936. print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOST('state_id', 'int') : $object->state_id, $object->country_code);
  1937. print '</td>';
  1938. print '</tr>';
  1939. }
  1940. }
  1941. // Quality control
  1942. if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
  1943. print '<tr><td>'.$langs->trans("LifeTime").'</td><td><input name="lifetime" class="maxwidth100onsmartphone" value="'.$object->lifetime.'"></td></tr>';
  1944. print '<tr><td>'.$langs->trans("QCFrequency").'</td><td><input name="qc_frequency" class="maxwidth100onsmartphone" value="'.$object->qc_frequency.'"></td></tr>';
  1945. }
  1946. // Other attributes
  1947. $parameters = array('colspan' => ' colspan="2"', 'cols' => 2);
  1948. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1949. print $hookmanager->resPrint;
  1950. if (empty($reshook)) {
  1951. print $object->showOptionals($extrafields, 'edit', $parameters);
  1952. }
  1953. // Tags-Categories
  1954. if (isModEnabled('categorie')) {
  1955. print '<tr><td>'.$langs->trans("Categories").'</td><td>';
  1956. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1);
  1957. $c = new Categorie($db);
  1958. $cats = $c->containing($object->id, Categorie::TYPE_PRODUCT);
  1959. $arrayselected = array();
  1960. if (is_array($cats)) {
  1961. foreach ($cats as $cat) {
  1962. $arrayselected[] = $cat->id;
  1963. }
  1964. }
  1965. if (GETPOSTISARRAY('categories')) {
  1966. foreach (GETPOST('categories', 'array') as $cat) {
  1967. $arrayselected[] = $cat;
  1968. }
  1969. }
  1970. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1971. print "</td></tr>";
  1972. }
  1973. // Note private
  1974. if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  1975. print '<tr><td class="tdtop">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>';
  1976. $doleditor = new DolEditor('note_private', $object->note_private, '', 140, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_NOTE_PRIVATE'), ROWS_4, '90%');
  1977. $doleditor->Create();
  1978. print "</td></tr>";
  1979. }
  1980. print '</table>';
  1981. print '<br>';
  1982. print '<table class="border centpercent">';
  1983. if (empty($conf->global->PRODUCT_DISABLE_ACCOUNTING)) {
  1984. if (isModEnabled('accounting')) {
  1985. // Accountancy_code_sell
  1986. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  1987. print '<td>';
  1988. print $formaccounting->select_account((GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell') : $object->accountancy_code_sell), 'accountancy_code_sell', 1, '', 1, 1, 'minwidth150 maxwidth300');
  1989. print '</td></tr>';
  1990. // Accountancy_code_sell_intra
  1991. if ($mysoc->isInEEC()) {
  1992. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
  1993. print '<td>';
  1994. print $formaccounting->select_account((GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra') : $object->accountancy_code_sell_intra), 'accountancy_code_sell_intra', 1, '', 1, 1, 'minwidth150 maxwidth300');
  1995. print '</td></tr>';
  1996. }
  1997. // Accountancy_code_sell_export
  1998. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
  1999. print '<td>';
  2000. print $formaccounting->select_account((GETPOSTISSET('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export') : $object->accountancy_code_sell_export), 'accountancy_code_sell_export', 1, '', 1, 1, 'minwidth150 maxwidth300');
  2001. print '</td></tr>';
  2002. // Accountancy_code_buy
  2003. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  2004. print '<td>';
  2005. print $formaccounting->select_account((GETPOSTISSET('accountancy_code_buy') ? GETPOST('accountancy_code_buy') : $object->accountancy_code_buy), 'accountancy_code_buy', 1, '', 1, 1, 'minwidth150 maxwidth300');
  2006. print '</td></tr>';
  2007. // Accountancy_code_buy_intra
  2008. if ($mysoc->isInEEC()) {
  2009. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
  2010. print '<td>';
  2011. print $formaccounting->select_account((GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra') : $object->accountancy_code_buy_intra), 'accountancy_code_buy_intra', 1, '', 1, 1, 'minwidth150 maxwidth300');
  2012. print '</td></tr>';
  2013. }
  2014. // Accountancy_code_buy_export
  2015. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
  2016. print '<td>';
  2017. print $formaccounting->select_account((GETPOSTISSET('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export') : $object->accountancy_code_buy_export), 'accountancy_code_buy_export', 1, '', 1, 1, 'minwidth150 maxwidth300');
  2018. print '</td></tr>';
  2019. } else {
  2020. // For external software
  2021. // Accountancy_code_sell
  2022. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  2023. print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell') : $object->accountancy_code_sell).'">';
  2024. print '</td></tr>';
  2025. // Accountancy_code_sell_intra
  2026. if ($mysoc->isInEEC()) {
  2027. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
  2028. print '<td><input name="accountancy_code_sell_intra" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra') : $object->accountancy_code_sell_intra).'">';
  2029. print '</td></tr>';
  2030. }
  2031. // Accountancy_code_sell_export
  2032. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
  2033. print '<td><input name="accountancy_code_sell_export" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export') : $object->accountancy_code_sell_export).'">';
  2034. print '</td></tr>';
  2035. // Accountancy_code_buy
  2036. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  2037. print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_buy') ? GETPOST('accountancy_code_buy') : $object->accountancy_code_buy).'">';
  2038. print '</td></tr>';
  2039. // Accountancy_code_buy_intra
  2040. if ($mysoc->isInEEC()) {
  2041. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
  2042. print '<td><input name="accountancy_code_buy_intra" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra') : $object->accountancy_code_buy_intra).'">';
  2043. print '</td></tr>';
  2044. }
  2045. // Accountancy_code_buy_export
  2046. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
  2047. print '<td><input name="accountancy_code_buy_export" class="maxwidth200" value="'.(GETPOSTISSET('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export') : $object->accountancy_code_buy_export).'">';
  2048. print '</td></tr>';
  2049. }
  2050. }
  2051. print '</table>';
  2052. print dol_get_fiche_end();
  2053. print $form->buttonsSaveCancel();
  2054. print '</form>';
  2055. } else {
  2056. // Fiche en mode visu
  2057. $showbarcode = isModEnabled('barcode');
  2058. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
  2059. $showbarcode = 0;
  2060. }
  2061. $head = product_prepare_head($object);
  2062. $titre = $langs->trans("CardProduct".$object->type);
  2063. $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  2064. print dol_get_fiche_head($head, 'card', $titre, -1, $picto);
  2065. $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1&type='.$object->type.'">'.$langs->trans("BackToList").'</a>';
  2066. $object->next_prev_filter = " fk_product_type = ".$object->type;
  2067. $shownav = 1;
  2068. if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  2069. $shownav = 0;
  2070. }
  2071. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
  2072. print '<div class="fichecenter">';
  2073. print '<div class="fichehalfleft">';
  2074. print '<div class="underbanner clearboth"></div>';
  2075. print '<table class="border tableforfield centpercent">';
  2076. // Type
  2077. if (isModEnabled("product") && isModEnabled("service")) {
  2078. $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
  2079. print '<tr><td class="titlefield">';
  2080. print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat) : $langs->trans('Type');
  2081. print '</td><td>';
  2082. print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat);
  2083. print '</td></tr>';
  2084. }
  2085. if ($showbarcode) {
  2086. // Barcode type
  2087. print '<tr><td class="nowrap">';
  2088. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  2089. print $langs->trans("BarcodeType");
  2090. print '</td>';
  2091. if (($action != 'editbarcodetype') && $usercancreate && $createbarcode) {
  2092. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbarcodetype&id='.$object->id.'&token='.newToken().'">'.img_edit($langs->trans('Edit'), 1).'</a></td>';
  2093. }
  2094. print '</tr></table>';
  2095. print '</td><td>';
  2096. if ($action == 'editbarcodetype' || $action == 'editbarcode') {
  2097. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
  2098. $formbarcode = new FormBarCode($db);
  2099. }
  2100. $fk_barcode_type = '';
  2101. if ($action == 'editbarcodetype') {
  2102. print $formbarcode->formBarcodeType($_SERVER['PHP_SELF'].'?id='.$object->id, $object->barcode_type, 'fk_barcode_type');
  2103. $fk_barcode_type = $object->barcode_type;
  2104. } else {
  2105. $object->fetch_barcode();
  2106. $fk_barcode_type = $object->barcode_type;
  2107. print $object->barcode_type_label ? $object->barcode_type_label : ($object->barcode ? '<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>' : '');
  2108. }
  2109. print '</td></tr>'."\n";
  2110. // Barcode value
  2111. print '<tr><td class="nowrap">';
  2112. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  2113. print $langs->trans("BarcodeValue");
  2114. print '</td>';
  2115. if (($action != 'editbarcode') && $usercancreate && $createbarcode) {
  2116. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbarcode&id='.$object->id.'&token='.newToken().'">'.img_edit($langs->trans('Edit'), 1).'</a></td>';
  2117. }
  2118. print '</tr></table>';
  2119. print '</td><td>';
  2120. if ($action == 'editbarcode') {
  2121. $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
  2122. if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) {
  2123. $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
  2124. }
  2125. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  2126. print '<input type="hidden" name="token" value="'.newToken().'">';
  2127. print '<input type="hidden" name="action" value="setbarcode">';
  2128. print '<input type="hidden" name="barcode_type_code" value="'.$object->barcode_type_code.'">';
  2129. print '<input class="width300" class="maxwidthonsmartphone" type="text" name="barcode" value="'.$tmpcode.'">';
  2130. print '&nbsp;<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Modify").'">';
  2131. print '</form>';
  2132. } else {
  2133. print showValueWithClipboardCPButton($object->barcode);
  2134. }
  2135. print '</td></tr>'."\n";
  2136. }
  2137. // Batch number management (to batch)
  2138. if (isModEnabled('productbatch')) {
  2139. if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  2140. print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
  2141. print $object->getLibStatut(0, 2);
  2142. print '</td></tr>';
  2143. if ((($object->status_batch == '1' && !empty($conf->global->PRODUCTBATCH_LOT_USE_PRODUCT_MASKS) && $conf->global->PRODUCTBATCH_LOT_ADDON == 'mod_lot_advanced')
  2144. || ($object->status_batch == '2' && $conf->global->PRODUCTBATCH_SN_ADDON == 'mod_sn_advanced' && !empty($conf->global->PRODUCTBATCH_SN_USE_PRODUCT_MASKS)))) {
  2145. print '<tr><td>'.$langs->trans("ManageLotMask").'</td><td>';
  2146. print $object->batch_mask;
  2147. print '</td></tr>';
  2148. }
  2149. }
  2150. }
  2151. if (empty($conf->global->PRODUCT_DISABLE_ACCOUNTING)) {
  2152. // Accountancy sell code
  2153. print '<tr><td class="nowrap">';
  2154. print $langs->trans("ProductAccountancySellCode");
  2155. print '</td><td>';
  2156. if (isModEnabled('accounting')) {
  2157. if (!empty($object->accountancy_code_sell)) {
  2158. $accountingaccount = new AccountingAccount($db);
  2159. $accountingaccount->fetch('', $object->accountancy_code_sell, 1);
  2160. print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
  2161. }
  2162. } else {
  2163. print $object->accountancy_code_sell;
  2164. }
  2165. print '</td></tr>';
  2166. // Accountancy sell code intra-community
  2167. if ($mysoc->isInEEC()) {
  2168. print '<tr><td class="nowrap">';
  2169. print $langs->trans("ProductAccountancySellIntraCode");
  2170. print '</td><td>';
  2171. if (isModEnabled('accounting')) {
  2172. if (!empty($object->accountancy_code_sell_intra)) {
  2173. $accountingaccount2 = new AccountingAccount($db);
  2174. $accountingaccount2->fetch('', $object->accountancy_code_sell_intra, 1);
  2175. print $accountingaccount2->getNomUrl(0, 1, 1, '', 1);
  2176. }
  2177. } else {
  2178. print $object->accountancy_code_sell_intra;
  2179. }
  2180. print '</td></tr>';
  2181. }
  2182. // Accountancy sell code export
  2183. print '<tr><td class="nowrap">';
  2184. print $langs->trans("ProductAccountancySellExportCode");
  2185. print '</td><td>';
  2186. if (isModEnabled('accounting')) {
  2187. if (!empty($object->accountancy_code_sell_export)) {
  2188. $accountingaccount3 = new AccountingAccount($db);
  2189. $accountingaccount3->fetch('', $object->accountancy_code_sell_export, 1);
  2190. print $accountingaccount3->getNomUrl(0, 1, 1, '', 1);
  2191. }
  2192. } else {
  2193. print $object->accountancy_code_sell_export;
  2194. }
  2195. print '</td></tr>';
  2196. // Accountancy buy code
  2197. print '<tr><td class="nowrap">';
  2198. print $langs->trans("ProductAccountancyBuyCode");
  2199. print '</td><td>';
  2200. if (isModEnabled('accounting')) {
  2201. if (!empty($object->accountancy_code_buy)) {
  2202. $accountingaccount4 = new AccountingAccount($db);
  2203. $accountingaccount4->fetch('', $object->accountancy_code_buy, 1);
  2204. print $accountingaccount4->getNomUrl(0, 1, 1, '', 1);
  2205. }
  2206. } else {
  2207. print $object->accountancy_code_buy;
  2208. }
  2209. print '</td></tr>';
  2210. // Accountancy buy code intra-community
  2211. if ($mysoc->isInEEC()) {
  2212. print '<tr><td class="nowrap">';
  2213. print $langs->trans("ProductAccountancyBuyIntraCode");
  2214. print '</td><td>';
  2215. if (isModEnabled('accounting')) {
  2216. if (!empty($object->accountancy_code_buy_intra)) {
  2217. $accountingaccount5 = new AccountingAccount($db);
  2218. $accountingaccount5->fetch('', $object->accountancy_code_buy_intra, 1);
  2219. print $accountingaccount5->getNomUrl(0, 1, 1, '', 1);
  2220. }
  2221. } else {
  2222. print $object->accountancy_code_buy_intra;
  2223. }
  2224. print '</td></tr>';
  2225. }
  2226. // Accountancy buy code export
  2227. print '<tr><td class="nowrap">';
  2228. print $langs->trans("ProductAccountancyBuyExportCode");
  2229. print '</td><td>';
  2230. if (isModEnabled('accounting')) {
  2231. if (!empty($object->accountancy_code_buy_export)) {
  2232. $accountingaccount6 = new AccountingAccount($db);
  2233. $accountingaccount6->fetch('', $object->accountancy_code_buy_export, 1);
  2234. print $accountingaccount6->getNomUrl(0, 1, 1, '', 1);
  2235. }
  2236. } else {
  2237. print $object->accountancy_code_buy_export;
  2238. }
  2239. print '</td></tr>';
  2240. }
  2241. // Description
  2242. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>'.(dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true)).'</td></tr>';
  2243. // Public URL
  2244. if (empty($conf->global->PRODUCT_DISABLE_PUBLIC_URL)) {
  2245. print '<tr><td>'.$langs->trans("PublicUrl").'</td><td>';
  2246. print dol_print_url($object->url, '_blank', 128);
  2247. print '</td></tr>';
  2248. }
  2249. // Default warehouse
  2250. if ($object->isProduct() && isModEnabled('stock')) {
  2251. $warehouse = new Entrepot($db);
  2252. $warehouse->fetch($object->fk_default_warehouse);
  2253. print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
  2254. print (!empty($warehouse->id) ? $warehouse->getNomUrl(1) : '');
  2255. print '</td>';
  2256. }
  2257. if ($object->isService() && isModEnabled('workstation')) {
  2258. $workstation = new Workstation($db);
  2259. $res = $workstation->fetch($object->fk_default_workstation);
  2260. print '<tr><td>'.$langs->trans("DefaultWorkstation").'</td><td>';
  2261. print (!empty($workstation->id) ? $workstation->getNomUrl(1) : '');
  2262. print '</td>';
  2263. }
  2264. // Parent product.
  2265. if (isModEnabled('variants') && ($object->isProduct() || $object->isService())) {
  2266. $combination = new ProductCombination($db);
  2267. if ($combination->fetchByFkProductChild($object->id) > 0) {
  2268. $prodstatic = new Product($db);
  2269. $prodstatic->fetch($combination->fk_product_parent);
  2270. // Parent product
  2271. print '<tr><td>'.$langs->trans("ParentProduct").'</td><td>';
  2272. print $prodstatic->getNomUrl(1);
  2273. print '</td></tr>';
  2274. }
  2275. }
  2276. print '</table>';
  2277. print '</div>';
  2278. print '<div class="fichehalfright">';
  2279. print '<div class="underbanner clearboth"></div>';
  2280. print '<table class="border tableforfield centpercent">';
  2281. if ($object->isService()) {
  2282. // Duration
  2283. print '<tr><td class="titlefield">'.$langs->trans("Duration").'</td><td>';
  2284. print $object->duration_value;
  2285. if ($object->duration_value > 1) {
  2286. $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
  2287. } elseif ($object->duration_value > 0) {
  2288. $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
  2289. }
  2290. print (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? "&nbsp;".$langs->trans($dur[$object->duration_unit])."&nbsp;" : '');
  2291. // Mandatory period
  2292. if ($object->duration_value > 0) {
  2293. print ' &nbsp; &nbsp; &nbsp; ';
  2294. }
  2295. $htmltooltip = $langs->trans("mandatoryHelper");
  2296. print '<input type="checkbox" class="" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').' disabled>';
  2297. print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 0);
  2298. print '</td></tr>';
  2299. } else {
  2300. if (empty($conf->global->PRODUCT_DISABLE_NATURE)) {
  2301. // Nature
  2302. print '<tr><td class="titlefield">'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
  2303. print $object->getLibFinished();
  2304. print '</td></tr>';
  2305. }
  2306. }
  2307. if (!$object->isService() && isModEnabled('bom') && $object->finished) {
  2308. print '<tr><td class="titlefield">'.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc", $langs->transnoentitiesnoconv("Finished"))).'</td><td>';
  2309. if ($object->fk_default_bom) {
  2310. $bom_static = new BOM($db);
  2311. $bom_static->fetch($object->fk_default_bom);
  2312. print $bom_static->getNomUrl(1);
  2313. }
  2314. print '</td></tr>';
  2315. }
  2316. if (!$object->isService()) {
  2317. // Brut Weight
  2318. if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) {
  2319. print '<tr><td class="titlefield">'.$langs->trans("Weight").'</td><td>';
  2320. if ($object->weight != '') {
  2321. print $object->weight." ".measuringUnitString(0, "weight", $object->weight_units);
  2322. } else {
  2323. print '&nbsp;';
  2324. }
  2325. print "</td></tr>\n";
  2326. }
  2327. if (empty($conf->global->PRODUCT_DISABLE_SIZE)) {
  2328. // Brut Length
  2329. print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td>';
  2330. if ($object->length != '' || $object->width != '' || $object->height != '') {
  2331. print $object->length;
  2332. if ($object->width) {
  2333. print " x ".$object->width;
  2334. }
  2335. if ($object->height) {
  2336. print " x ".$object->height;
  2337. }
  2338. print ' '.measuringUnitString(0, "size", $object->length_units);
  2339. } else {
  2340. print '&nbsp;';
  2341. }
  2342. print "</td></tr>\n";
  2343. }
  2344. if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) {
  2345. // Brut Surface
  2346. print '<tr><td>'.$langs->trans("Surface").'</td><td>';
  2347. if ($object->surface != '') {
  2348. print $object->surface." ".measuringUnitString(0, "surface", $object->surface_units);
  2349. } else {
  2350. print '&nbsp;';
  2351. }
  2352. print "</td></tr>\n";
  2353. }
  2354. if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) {
  2355. // Brut Volume
  2356. print '<tr><td>'.$langs->trans("Volume").'</td><td>';
  2357. if ($object->volume != '') {
  2358. print $object->volume." ".measuringUnitString(0, "volume", $object->volume_units);
  2359. } else {
  2360. print '&nbsp;';
  2361. }
  2362. print "</td></tr>\n";
  2363. }
  2364. if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) {
  2365. // Net Measure
  2366. print '<tr><td class="titlefield">'.$langs->trans("NetMeasure").'</td><td>';
  2367. if ($object->net_measure != '') {
  2368. print $object->net_measure." ".measuringUnitString($object->net_measure_units);
  2369. } else {
  2370. print '&nbsp;';
  2371. }
  2372. print '</td></tr>';
  2373. }
  2374. }
  2375. // Unit
  2376. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  2377. $unit = $object->getLabelOfUnit();
  2378. print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td><td>';
  2379. if ($unit !== '') {
  2380. print $langs->trans($unit);
  2381. }
  2382. print '</td></tr>';
  2383. }
  2384. // Custom code
  2385. if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) {
  2386. print '<tr><td>'.$langs->trans("CustomCode").'</td><td>'.$object->customcode.'</td></tr>';
  2387. // Origin country code
  2388. print '<tr><td>'.$langs->trans("Origin").'</td><td>'.getCountry($object->country_id, 0, $db);
  2389. if (!empty($object->state_id)) {
  2390. print ' - '.getState($object->state_id, 0, $db);
  2391. }
  2392. print '</td></tr>';
  2393. }
  2394. // Quality Control
  2395. if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
  2396. print '<tr><td>'.$langs->trans("LifeTime").'</td><td>'.$object->lifetime.'</td></tr>';
  2397. print '<tr><td>'.$langs->trans("QCFrequency").'</td><td>'.$object->qc_frequency.'</td></tr>';
  2398. }
  2399. // Other attributes
  2400. $parameters = array();
  2401. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  2402. // Categories
  2403. if (isModEnabled('categorie')) {
  2404. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  2405. print $form->showCategories($object->id, Categorie::TYPE_PRODUCT, 1);
  2406. print "</td></tr>";
  2407. }
  2408. // Note private
  2409. if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  2410. print '<!-- show Note --> '."\n";
  2411. print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td><td>'.(dol_textishtml($object->note_private) ? $object->note_private : dol_nl2br($object->note_private, 1, true)).'</td></tr>'."\n";
  2412. print '<!-- End show Note --> '."\n";
  2413. }
  2414. print "</table>\n";
  2415. print '</div>';
  2416. print '</div>';
  2417. print '<div class="clearboth"></div>';
  2418. print dol_get_fiche_end();
  2419. }
  2420. } elseif ($action != 'create') {
  2421. exit;
  2422. }
  2423. }
  2424. $tmpcode = '';
  2425. if (!empty($modCodeProduct->code_auto)) {
  2426. $tmpcode = $modCodeProduct->getNextValue($object, $object->type);
  2427. }
  2428. $formconfirm = '';
  2429. // Confirm delete product
  2430. if (($action == 'delete' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
  2431. || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
  2432. $formconfirm = $form->formconfirm("card.php?id=".$object->id, $langs->trans("DeleteProduct"), $langs->trans("ConfirmDeleteProduct"), "confirm_delete", '', 0, "action-delete");
  2433. }
  2434. if ($action == 'merge') {
  2435. $formquestion = array(
  2436. array(
  2437. 'name' => 'product_origin',
  2438. 'label' => $langs->trans('MergeOriginProduct'),
  2439. 'type' => 'other',
  2440. 'value' => $form->select_produits('', 'product_origin', '', 0, 0, 1, 2, '', 1, array(), 0, 1, 0, 'minwidth200', 0, '', null, 1),
  2441. )
  2442. );
  2443. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("MergeProducts"), $langs->trans("ConfirmMergeProducts"), "confirm_merge", $formquestion, 'no', 1, 250);
  2444. }
  2445. // Clone confirmation
  2446. if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
  2447. || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
  2448. // Define confirmation messages
  2449. $formquestionclone = array(
  2450. 'text' => $langs->trans("ConfirmClone"),
  2451. array('type' => 'text', 'name' => 'clone_ref', 'label' => $langs->trans("NewRefForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->ref : $tmpcode, 'morecss'=>'width150'),
  2452. array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContentProduct"), 'value' => 1),
  2453. array('type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans("CloneCategoriesProduct"), 'value' => 1),
  2454. );
  2455. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  2456. $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("CustomerPrices").')', 'value' => 0);
  2457. }
  2458. if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) {
  2459. $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1);
  2460. }
  2461. $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneProduct', $object->ref), 'confirm_clone', $formquestionclone, 'yes', 'action-clone', 350, 600);
  2462. }
  2463. // Call Hook formConfirm
  2464. $parameters = array('formConfirm' => $formconfirm, 'object' => $object);
  2465. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2466. if (empty($reshook)) {
  2467. $formconfirm .= $hookmanager->resPrint;
  2468. } elseif ($reshook > 0) {
  2469. $formconfirm = $hookmanager->resPrint;
  2470. }
  2471. // Print form confirm
  2472. print $formconfirm;
  2473. /*
  2474. * Action bar
  2475. */
  2476. if ($action != 'create' && $action != 'edit') {
  2477. $cloneProductUrl = $_SERVER["PHP_SELF"].'?action=clone&token='.newToken();
  2478. $cloneButtonId = 'action-clone-no-ajax';
  2479. print "\n".'<div class="tabsAction">'."\n";
  2480. $parameters = array();
  2481. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2482. if (empty($reshook)) {
  2483. if ($usercancreate) {
  2484. if (!isset($object->no_button_edit) || $object->no_button_edit <> 1) {
  2485. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '', $usercancreate);
  2486. }
  2487. if (!isset($object->no_button_copy) || $object->no_button_copy <> 1) {
  2488. if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) {
  2489. $cloneProductUrl = '';
  2490. $cloneButtonId = 'action-clone';
  2491. }
  2492. print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $cloneProductUrl, $cloneButtonId, $usercancreate);
  2493. }
  2494. }
  2495. $object_is_used = $object->isObjectUsed($object->id);
  2496. if ($usercandelete) {
  2497. if (empty($object_is_used) && (!isset($object->no_button_delete) || $object->no_button_delete <> 1)) {
  2498. if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) {
  2499. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', '#', 'action-delete', true);
  2500. } else {
  2501. print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
  2502. }
  2503. } else {
  2504. print dolGetButtonAction($langs->trans("ProductIsUsed"), $langs->trans('Delete'), 'delete', '#', '', false);
  2505. }
  2506. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') > 1) {
  2507. print '<a class="butActionDelete" href="card.php?action=merge&id='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("MergeProducts")).'">'.$langs->trans('Merge').'</a>'."\n";
  2508. }
  2509. } else {
  2510. print dolGetButtonAction($langs->trans("NotEnoughPermissions"), $langs->trans('Delete'), 'delete', '#', '', false);
  2511. }
  2512. }
  2513. print "\n</div>\n";
  2514. }
  2515. /*
  2516. * All the "Add to" areas if PRODUCT_ADD_FORM_ADD_TO is set
  2517. */
  2518. if (!empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == '' || $action == 'view') && $object->status) {
  2519. //Variable used to check if any text is going to be printed
  2520. $html = '';
  2521. //print '<div class="fichecenter"><div class="fichehalfleft">';
  2522. // Propals
  2523. if (isModEnabled("propal") && $user->hasRight('propal', 'creer')) {
  2524. $propal = new Propal($db);
  2525. $langs->load("propal");
  2526. $otherprop = $propal->liste_array(2, 1, 0);
  2527. if (is_array($otherprop) && count($otherprop)) {
  2528. $html .= '<tr><td style="width: 200px;">';
  2529. $html .= $langs->trans("AddToDraftProposals").'</td><td>';
  2530. $html .= $form->selectarray("propalid", $otherprop, 0, 1);
  2531. $html .= '</td></tr>';
  2532. } else {
  2533. $html .= '<tr><td style="width: 200px;">';
  2534. $html .= $langs->trans("AddToDraftProposals").'</td><td>';
  2535. $html .= $langs->trans("NoDraftProposals");
  2536. $html .= '</td></tr>';
  2537. }
  2538. }
  2539. // Commande
  2540. if (isModEnabled('commande') && $user->hasRight('commande', 'creer')) {
  2541. $commande = new Commande($db);
  2542. $langs->load("orders");
  2543. $othercom = $commande->liste_array(2, 1, null);
  2544. if (is_array($othercom) && count($othercom)) {
  2545. $html .= '<tr><td style="width: 200px;">';
  2546. $html .= $langs->trans("AddToDraftOrders").'</td><td>';
  2547. $html .= $form->selectarray("commandeid", $othercom, 0, 1);
  2548. $html .= '</td></tr>';
  2549. } else {
  2550. $html .= '<tr><td style="width: 200px;">';
  2551. $html .= $langs->trans("AddToDraftOrders").'</td><td>';
  2552. $html .= $langs->trans("NoDraftOrders");
  2553. $html .= '</td></tr>';
  2554. }
  2555. }
  2556. // Factures
  2557. if (isModEnabled('facture') && $user->hasRight('facture', 'creer')) {
  2558. $invoice = new Facture($db);
  2559. $langs->load("bills");
  2560. $otherinvoice = $invoice->liste_array(2, 1, null);
  2561. if (is_array($otherinvoice) && count($otherinvoice)) {
  2562. $html .= '<tr><td style="width: 200px;">';
  2563. $html .= $langs->trans("AddToDraftInvoices").'</td><td>';
  2564. $html .= $form->selectarray("factureid", $otherinvoice, 0, 1);
  2565. $html .= '</td></tr>';
  2566. } else {
  2567. $html .= '<tr><td style="width: 200px;">';
  2568. $html .= $langs->trans("AddToDraftInvoices").'</td><td>';
  2569. $html .= $langs->trans("NoDraftInvoices");
  2570. $html .= '</td></tr>';
  2571. }
  2572. }
  2573. //If any text is going to be printed, then we show the table
  2574. if (!empty($html)) {
  2575. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  2576. print '<input type="hidden" name="token" value="'.newToken().'">';
  2577. print '<input type="hidden" name="action" value="addin">';
  2578. print load_fiche_titre($langs->trans("AddToDraft"), '', '');
  2579. print dol_get_fiche_head('');
  2580. $html .= '<tr><td class="nowrap">'.$langs->trans("Quantity").' ';
  2581. $html .= '<input type="text" class="flat" name="qty" size="1" value="1"></td>';
  2582. $html .= '<td class="nowrap">'.$langs->trans("ReductionShort").'(%) ';
  2583. $html .= '<input type="text" class="flat" name="remise_percent" size="1" value="0">';
  2584. $html .= '</td></tr>';
  2585. print '<table width="100%" class="border">';
  2586. print $html;
  2587. print '</table>';
  2588. print '<div class="center">';
  2589. print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
  2590. print '</div>';
  2591. print dol_get_fiche_end();
  2592. print '</form>';
  2593. }
  2594. }
  2595. /*
  2596. * Generated documents
  2597. */
  2598. if ($action != 'create' && $action != 'edit' && $action != 'delete') {
  2599. print '<div class="fichecenter"><div class="fichehalfleft">';
  2600. print '<a name="builddoc"></a>'; // ancre
  2601. // Documents
  2602. $objectref = dol_sanitizeFileName($object->ref);
  2603. if (!empty($conf->product->multidir_output[$object->entity])) {
  2604. $filedir = $conf->product->multidir_output[$object->entity].'/'.$objectref; //Check repertories of current entities
  2605. } else {
  2606. $filedir = $conf->product->dir_output.'/'.$objectref;
  2607. }
  2608. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  2609. $genallowed = $usercanread;
  2610. $delallowed = $usercancreate;
  2611. print $formfile->showdocuments($modulepart, $object->ref, $filedir, $urlsource, $genallowed, $delallowed, '', 0, 0, 0, 28, 0, '', 0, '', $langs->getDefaultLang(), '', $object);
  2612. $somethingshown = $formfile->numoffiles;
  2613. print '</div><div class="fichehalfright">';
  2614. $MAXEVENT = 10;
  2615. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/product/agenda.php?id='.$object->id);
  2616. // List of actions on element
  2617. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  2618. $formactions = new FormActions($db);
  2619. $somethingshown = $formactions->showactions($object, 'product', 0, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for product
  2620. print '</div></div>';
  2621. }
  2622. // End of page
  2623. llxFooter();
  2624. $db->close();