card.php 126 KB

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