card.php 110 KB

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