card.php 126 KB

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