card.php 126 KB

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