card.php 121 KB

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