card.php 119 KB

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