card.php 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010
  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-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  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. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 3 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. */
  32. /**
  33. * \file htdocs/product/card.php
  34. * \ingroup product
  35. * \brief Page to show product
  36. */
  37. require '../main.inc.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  46. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.php';
  48. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  49. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  50. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  51. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php';
  52. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  53. $langs->load("products");
  54. $langs->load("other");
  55. if (! empty($conf->stock->enabled)) $langs->load("stocks");
  56. if (! empty($conf->facture->enabled)) $langs->load("bills");
  57. if (! empty($conf->productbatch->enabled)) $langs->load("productbatch");
  58. $mesg=''; $error=0; $errors=array();
  59. $refalreadyexists=0;
  60. $id=GETPOST('id', 'int');
  61. $ref=GETPOST('ref', 'alpha');
  62. $type=GETPOST('type','int');
  63. $action=(GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view');
  64. $cancel=GETPOST('cancel');
  65. $confirm=GETPOST('confirm','alpha');
  66. $socid=GETPOST('socid','int');
  67. $duration_value = GETPOST('duration_value');
  68. $duration_unit = GETPOST('duration_unit');
  69. if (! empty($user->societe_id)) $socid=$user->societe_id;
  70. $object = new Product($db);
  71. $extrafields = new ExtraFields($db);
  72. // fetch optionals attributes and labels
  73. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  74. if ($id > 0 || ! empty($ref))
  75. {
  76. $result = $object->fetch($id, $ref);
  77. if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
  78. elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
  79. if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs
  80. {
  81. if (! empty($conf->product->enabled)) $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";
  82. else $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";
  83. }
  84. }
  85. $modulepart='product';
  86. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  87. $canvas = !empty($object->canvas)?$object->canvas:GETPOST("canvas");
  88. $objcanvas=null;
  89. if (! empty($canvas))
  90. {
  91. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  92. $objcanvas = new Canvas($db,$action);
  93. $objcanvas->getCanvas('product','card',$canvas);
  94. }
  95. // Security check
  96. $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
  97. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  98. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype,$objcanvas);
  99. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  100. $hookmanager->initHooks(array('productcard','globalcard'));
  101. /*
  102. * Actions
  103. */
  104. if ($cancel) $action = '';
  105. $createbarcode=empty($conf->barcode->enabled)?0:1;
  106. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->creer_advance)) $createbarcode=0;
  107. $parameters=array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
  108. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  109. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  110. if (empty($reshook))
  111. {
  112. // Type
  113. if ($action == 'setfk_product_type' && $user->rights->produit->creer)
  114. {
  115. $result = $object->setValueFrom('fk_product_type', GETPOST('fk_product_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
  116. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  117. exit;
  118. }
  119. // Actions to build doc
  120. $upload_dir = $conf->produit->dir_output;
  121. $permissioncreate = $user->rights->produit->creer;
  122. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  123. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  124. // Barcode type
  125. if ($action == 'setfk_barcode_type' && $createbarcode)
  126. {
  127. $result = $object->setValueFrom('fk_barcode_type', GETPOST('fk_barcode_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
  128. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  129. exit;
  130. }
  131. // Barcode value
  132. if ($action == 'setbarcode' && $createbarcode)
  133. {
  134. $result=$object->check_barcode(GETPOST('barcode'),GETPOST('barcode_type_code'));
  135. if ($result >= 0)
  136. {
  137. $result = $object->setValueFrom('barcode', GETPOST('barcode'));
  138. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  139. exit;
  140. }
  141. else
  142. {
  143. $langs->load("errors");
  144. if ($result == -1) $errors[] = 'ErrorBadBarCodeSyntax';
  145. else if ($result == -2) $errors[] = 'ErrorBarCodeRequired';
  146. else if ($result == -3) $errors[] = 'ErrorBarCodeAlreadyUsed';
  147. else $errors[] = 'FailedToValidateBarCode';
  148. $error++;
  149. setEventMessages($errors, null, 'errors');
  150. }
  151. }
  152. // Add a product or service
  153. if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer))
  154. {
  155. $error=0;
  156. if (! GETPOST('label'))
  157. {
  158. setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('Label')), null, 'errors');
  159. $action = "create";
  160. $error++;
  161. }
  162. if (empty($ref))
  163. {
  164. setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('Ref')), null, 'errors');
  165. $action = "create";
  166. $error++;
  167. }
  168. if (! empty($duration_value) && empty($duration_unit))
  169. {
  170. setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentities('Unit')), null, 'errors');
  171. $action = "create";
  172. $error++;
  173. }
  174. if (! $error)
  175. {
  176. $units = GETPOST('units', 'int');
  177. $object->ref = $ref;
  178. $object->label = GETPOST('label');
  179. $object->price_base_type = GETPOST('price_base_type');
  180. if ($object->price_base_type == 'TTC')
  181. $object->price_ttc = GETPOST('price');
  182. else
  183. $object->price = GETPOST('price');
  184. if ($object->price_base_type == 'TTC')
  185. $object->price_min_ttc = GETPOST('price_min');
  186. else
  187. $object->price_min = GETPOST('price_min');
  188. $object->tva_tx = str_replace('*','',GETPOST('tva_tx'));
  189. $object->tva_npr = preg_match('/\*/',GETPOST('tva_tx'))?1:0;
  190. // local taxes.
  191. $object->localtax1_tx = get_localtax($object->tva_tx,1);
  192. $object->localtax2_tx = get_localtax($object->tva_tx,2);
  193. $object->type = $type;
  194. $object->status = GETPOST('statut');
  195. $object->status_buy = GETPOST('statut_buy');
  196. $object->status_batch = GETPOST('status_batch');
  197. $object->barcode_type = GETPOST('fk_barcode_type');
  198. $object->barcode = GETPOST('barcode');
  199. // Set barcode_type_xxx from barcode_type id
  200. $stdobject=new GenericObject($db);
  201. $stdobject->element='product';
  202. $stdobject->barcode_type=GETPOST('fk_barcode_type');
  203. $result=$stdobject->fetch_barcode();
  204. if ($result < 0)
  205. {
  206. $error++;
  207. $mesg='Failed to get bar code type information ';
  208. setEventMessages($mesg.$stdobject->error, $mesg.$stdobject->errors, 'errors');
  209. }
  210. $object->barcode_type_code = $stdobject->barcode_type_code;
  211. $object->barcode_type_coder = $stdobject->barcode_type_coder;
  212. $object->barcode_type_label = $stdobject->barcode_type_label;
  213. $object->description = dol_htmlcleanlastbr(GETPOST('desc'));
  214. $object->url = GETPOST('url');
  215. $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private'));
  216. $object->note = $object->note_private; // deprecated
  217. $object->customcode = GETPOST('customcode');
  218. $object->country_id = GETPOST('country_id');
  219. $object->duration_value = $duration_value;
  220. $object->duration_unit = $duration_unit;
  221. $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte')?GETPOST('seuil_stock_alerte'):0;
  222. $object->desiredstock = GETPOST('desiredstock')?GETPOST('desiredstock'):0;
  223. $object->canvas = GETPOST('canvas');
  224. $object->weight = GETPOST('weight');
  225. $object->weight_units = GETPOST('weight_units');
  226. $object->length = GETPOST('size');
  227. $object->length_units = GETPOST('size_units');
  228. $object->width = GETPOST('sizewidth');
  229. $object->height = GETPOST('sizeheight');
  230. $object->surface = GETPOST('surface');
  231. $object->surface_units = GETPOST('surface_units');
  232. $object->volume = GETPOST('volume');
  233. $object->volume_units = GETPOST('volume_units');
  234. $object->finished = GETPOST('finished');
  235. $object->fk_unit = GETPOST('units');
  236. $accountancy_code_sell = GETPOST('accountancy_code_sell');
  237. $accountancy_code_buy = GETPOST('accountancy_code_buy');
  238. if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; }
  239. if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; }
  240. // MultiPrix
  241. if (! empty($conf->global->PRODUIT_MULTIPRICES))
  242. {
  243. for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
  244. {
  245. if (isset($_POST["price_".$i]))
  246. {
  247. $object->multiprices["$i"] = price2num($_POST["price_".$i],'MU');
  248. $object->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i];
  249. }
  250. else
  251. {
  252. $object->multiprices["$i"] = "";
  253. }
  254. }
  255. }
  256. // Fill array 'array_options' with data from add form
  257. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  258. if ($ret < 0) $error++;
  259. if (! $error)
  260. {
  261. $id = $object->create($user);
  262. }
  263. if ($id > 0)
  264. {
  265. // Category association
  266. $categories = GETPOST('categories');
  267. $object->setCategories($categories);
  268. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  269. exit;
  270. }
  271. else
  272. {
  273. if (count($object->errors)) setEventMessages($object->error, $object->errors, 'errors');
  274. else setEventMessages($langs->trans($object->error), null, 'errors');
  275. $action = "create";
  276. }
  277. }
  278. }
  279. // Update a product or service
  280. if ($action == 'update' && ($user->rights->produit->creer || $user->rights->service->creer))
  281. {
  282. if (GETPOST('cancel'))
  283. {
  284. $action = '';
  285. }
  286. else
  287. {
  288. if ($object->id > 0)
  289. {
  290. $object->oldcopy= clone $object;
  291. $object->ref = $ref;
  292. $object->label = GETPOST('label');
  293. $object->description = dol_htmlcleanlastbr(GETPOST('desc'));
  294. $object->url = GETPOST('url');
  295. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  296. {
  297. $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private'));
  298. $object->note = $object->note_private;
  299. }
  300. $object->customcode = GETPOST('customcode');
  301. $object->country_id = GETPOST('country_id');
  302. $object->status = GETPOST('statut');
  303. $object->status_buy = GETPOST('statut_buy');
  304. $object->status_batch = GETPOST('status_batch');
  305. // removed from update view so GETPOST always empty
  306. /*
  307. $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte');
  308. $object->desiredstock = GETPOST('desiredstock');
  309. */
  310. $object->duration_value = GETPOST('duration_value');
  311. $object->duration_unit = GETPOST('duration_unit');
  312. $object->canvas = GETPOST('canvas');
  313. $object->weight = GETPOST('weight');
  314. $object->weight_units = GETPOST('weight_units');
  315. $object->length = GETPOST('size');
  316. $object->length_units = GETPOST('size_units');
  317. $object->width = GETPOST('sizewidth');
  318. $object->height = GETPOST('sizeheight');
  319. $object->surface = GETPOST('surface');
  320. $object->surface_units = GETPOST('surface_units');
  321. $object->volume = GETPOST('volume');
  322. $object->volume_units = GETPOST('volume_units');
  323. $object->finished = GETPOST('finished');
  324. $units = GETPOST('units', 'int');
  325. if ($units > 0) {
  326. $object->fk_unit = $units;
  327. } else {
  328. $object->fk_unit = null;
  329. }
  330. $object->barcode_type = GETPOST('fk_barcode_type');
  331. $object->barcode = GETPOST('barcode');
  332. // Set barcode_type_xxx from barcode_type id
  333. $stdobject=new GenericObject($db);
  334. $stdobject->element='product';
  335. $stdobject->barcode_type=GETPOST('fk_barcode_type');
  336. $result=$stdobject->fetch_barcode();
  337. if ($result < 0)
  338. {
  339. $error++;
  340. $mesg='Failed to get bar code type information ';
  341. setEventMessages($mesg.$stdobject->error, $mesg.$stdobject->errors, 'errors');
  342. }
  343. $object->barcode_type_code = $stdobject->barcode_type_code;
  344. $object->barcode_type_coder = $stdobject->barcode_type_coder;
  345. $object->barcode_type_label = $stdobject->barcode_type_label;
  346. $accountancy_code_sell = GETPOST('accountancy_code_sell');
  347. $accountancy_code_buy = GETPOST('accountancy_code_buy');
  348. if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; }
  349. if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; }
  350. // Fill array 'array_options' with data from add form
  351. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  352. if ($ret < 0) $error++;
  353. if (! $error && $object->check())
  354. {
  355. if ($object->update($object->id, $user) > 0)
  356. {
  357. // Category association
  358. $categories = GETPOST('categories');
  359. $object->setCategories($categories);
  360. $action = 'view';
  361. }
  362. else
  363. {
  364. if (count($object->errors)) setEventMessages($object->error, $object->errors, 'errors');
  365. else setEventMessages($langs->trans($object->error), null, 'errors');
  366. $action = 'edit';
  367. }
  368. }
  369. else
  370. {
  371. if (count($object->errors)) setEventMessages($object->error, $object->errors, 'errors');
  372. else setEventMessages($langs->trans("ErrorProductBadRefOrLabel"), null, 'errors');
  373. $action = 'edit';
  374. }
  375. }
  376. }
  377. }
  378. // Action clone object
  379. if ($action == 'confirm_clone' && $confirm != 'yes') { $action=''; }
  380. if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer))
  381. {
  382. if (! GETPOST('clone_content') && ! GETPOST('clone_prices') )
  383. {
  384. setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
  385. }
  386. else
  387. {
  388. $db->begin();
  389. $originalId = $id;
  390. if ($object->id > 0)
  391. {
  392. $object->ref = GETPOST('clone_ref');
  393. $object->status = 0;
  394. $object->status_buy = 0;
  395. $object->id = null;
  396. $object->barcode = -1;
  397. if ($object->check())
  398. {
  399. $id = $object->create($user);
  400. if ($id > 0)
  401. {
  402. if (GETPOST('clone_composition'))
  403. {
  404. $result = $object->clone_associations($originalId, $id);
  405. if ($result < 1)
  406. {
  407. $db->rollback();
  408. setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
  409. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$originalId);
  410. exit;
  411. }
  412. }
  413. // $object->clone_fournisseurs($originalId, $id);
  414. $db->commit();
  415. $db->close();
  416. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  417. exit;
  418. }
  419. else
  420. {
  421. $id=$originalId;
  422. if ($object->error == 'ErrorProductAlreadyExists')
  423. {
  424. $db->rollback();
  425. $refalreadyexists++;
  426. $action = "";
  427. $mesg=$langs->trans("ErrorProductAlreadyExists",$object->ref);
  428. $mesg.=' <a href="'.$_SERVER["PHP_SELF"].'?ref='.$object->ref.'">'.$langs->trans("ShowCardHere").'</a>.';
  429. setEventMessages($mesg, null, 'errors');
  430. $object->fetch($id);
  431. }
  432. else
  433. {
  434. $db->rollback();
  435. if (count($object->errors))
  436. {
  437. setEventMessages($object->error, $object->errors, 'errors');
  438. dol_print_error($db,$object->errors);
  439. }
  440. else
  441. {
  442. setEventMessages($langs->trans($object->error), null, 'errors');
  443. dol_print_error($db,$object->error);
  444. }
  445. }
  446. }
  447. }
  448. }
  449. else
  450. {
  451. $db->rollback();
  452. dol_print_error($db,$object->error);
  453. }
  454. }
  455. }
  456. // Delete a product
  457. if ($action == 'confirm_delete' && $confirm != 'yes') { $action=''; }
  458. if ($action == 'confirm_delete' && $confirm == 'yes')
  459. {
  460. if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer))
  461. {
  462. $result = $object->delete(DolibarrApiAccess::$user);
  463. }
  464. if ($result > 0)
  465. {
  466. header('Location: '.DOL_URL_ROOT.'/product/list.php?type='.$object->type.'&delprod='.urlencode($object->ref));
  467. exit;
  468. }
  469. else
  470. {
  471. setEventMessages($langs->trans($object->error), null, 'errors');
  472. $reload = 0;
  473. $action='';
  474. }
  475. }
  476. // Add product into object
  477. if ($object->id > 0 && $action == 'addin')
  478. {
  479. $thirpdartyid =0 ;
  480. if (GETPOST('propalid') > 0)
  481. {
  482. $propal = new Propal($db);
  483. $result=$propal->fetch(GETPOST('propalid'));
  484. if ($result <= 0)
  485. {
  486. dol_print_error($db,$propal->error);
  487. exit;
  488. }
  489. $thirpdartyid = $propal->socid;
  490. }
  491. elseif (GETPOST('commandeid') > 0)
  492. {
  493. $commande = new Commande($db);
  494. $result=$commande->fetch(GETPOST('commandeid'));
  495. if ($result <= 0)
  496. {
  497. dol_print_error($db,$commande->error);
  498. exit;
  499. }
  500. $thirpdartyid = $commande->socid;
  501. }
  502. elseif (GETPOST('factureid') > 0)
  503. {
  504. $facture = new Facture($db);
  505. $result=$facture->fetch(GETPOST('factureid'));
  506. if ($result <= 0)
  507. {
  508. dol_print_error($db,$facture->error);
  509. exit;
  510. }
  511. $thirpdartyid = $facture->socid;
  512. }
  513. if ( $thirpdartyid > 0) {
  514. $soc = new Societe($db);
  515. $result = $soc->fetch($thirpdartyid);
  516. if ($result <= 0) {
  517. dol_print_error($db, $soc->error);
  518. exit;
  519. }
  520. $desc = $object->description;
  521. $tva_tx = get_default_tva($mysoc, $soc, $object->id);
  522. $tva_npr = get_default_npr($mysoc, $soc, $object->id);
  523. if (empty($tva_tx)) $tva_npr=0;
  524. $localtax1_tx = get_localtax($tva_tx, 1, $soc, $mysoc, $tva_npr);
  525. $localtax2_tx = get_localtax($tva_tx, 2, $soc, $mysoc, $tva_npr);
  526. $pu_ht = $object->price;
  527. $pu_ttc = $object->price_ttc;
  528. $price_base_type = $object->price_base_type;
  529. // If multiprice
  530. if ($conf->global->PRODUIT_MULTIPRICES && $soc->price_level) {
  531. $pu_ht = $object->multiprices[$soc->price_level];
  532. $pu_ttc = $object->multiprices_ttc[$soc->price_level];
  533. $price_base_type = $object->multiprices_base_type[$soc->price_level];
  534. } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
  535. require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
  536. $prodcustprice = new Productcustomerprice($db);
  537. $filter = array('t.fk_product' => $object->id, 't.fk_soc' => $soc->id);
  538. $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
  539. if ($result) {
  540. if (count($prodcustprice->lines) > 0) {
  541. $pu_ht = price($prodcustprice->lines [0]->price);
  542. $pu_ttc = price($prodcustprice->lines [0]->price_ttc);
  543. $price_base_type = $prodcustprice->lines [0]->price_base_type;
  544. $tva_tx = $prodcustprice->lines [0]->tva_tx;
  545. }
  546. }
  547. }
  548. $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
  549. $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
  550. // On reevalue prix selon taux tva car taux tva transaction peut etre different
  551. // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
  552. if ($tmpvat != $tmpprodvat) {
  553. if ($price_base_type != 'HT') {
  554. $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
  555. } else {
  556. $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
  557. }
  558. }
  559. if (GETPOST('propalid') > 0) {
  560. // Define cost price for margin calculation
  561. $buyprice=0;
  562. if (($result = $propal->defineBuyPrice($pu_ht, GETPOST('remise_percent'), $object->id)) < 0)
  563. {
  564. dol_syslog($langs->trans('FailedToGetCostPrice'));
  565. setEventMessage($langs->trans('FailedToGetCostPrice'), 'errors');
  566. }
  567. else
  568. {
  569. $buyprice = $result;
  570. }
  571. $result = $propal->addline(
  572. $desc,
  573. $pu_ht,
  574. GETPOST('qty'),
  575. $tva_tx,
  576. $localtax1_tx, // localtax1
  577. $localtax2_tx, // localtax2
  578. $object->id,
  579. GETPOST('remise_percent'),
  580. $price_base_type,
  581. $pu_ttc,
  582. 0,
  583. 0,
  584. -1,
  585. 0,
  586. 0,
  587. 0,
  588. $buyprice,
  589. '',
  590. '',
  591. '',
  592. 0,
  593. $object->fk_unit
  594. );
  595. if ($result > 0) {
  596. header("Location: " . DOL_URL_ROOT . "/comm/propal/card.php?id=" . $propal->id);
  597. return;
  598. }
  599. setEventMessages($langs->trans("ErrorUnknown") . ": $result", null, 'errors');
  600. } elseif (GETPOST('commandeid') > 0) {
  601. // Define cost price for margin calculation
  602. $buyprice=0;
  603. if (($result = $commande->defineBuyPrice($pu_ht, GETPOST('remise_percent'), $object->id)) < 0)
  604. {
  605. dol_syslog($langs->trans('FailedToGetCostPrice'));
  606. setEventMessage($langs->trans('FailedToGetCostPrice'), 'errors');
  607. }
  608. else
  609. {
  610. $buyprice = $result;
  611. }
  612. $result = $commande->addline(
  613. $desc,
  614. $pu_ht,
  615. GETPOST('qty'),
  616. $tva_tx,
  617. $localtax1_tx, // localtax1
  618. $localtax2_tx, // localtax2
  619. $object->id,
  620. GETPOST('remise_percent'),
  621. '',
  622. '',
  623. $price_base_type,
  624. $pu_ttc,
  625. '',
  626. '',
  627. 0,
  628. -1,
  629. 0,
  630. 0,
  631. null,
  632. $buyprice,
  633. '',
  634. 0,
  635. $object->fk_unit
  636. );
  637. if ($result > 0) {
  638. header("Location: " . DOL_URL_ROOT . "/commande/card.php?id=" . $commande->id);
  639. exit;
  640. }
  641. } elseif (GETPOST('factureid') > 0) {
  642. // Define cost price for margin calculation
  643. $buyprice=0;
  644. if (($result = $facture->defineBuyPrice($pu_ht, GETPOST('remise_percent'), $object->id)) < 0)
  645. {
  646. dol_syslog($langs->trans('FailedToGetCostPrice'));
  647. setEventMessage($langs->trans('FailedToGetCostPrice'), 'errors');
  648. }
  649. else
  650. {
  651. $buyprice = $result;
  652. }
  653. $result = $facture->addline(
  654. $desc,
  655. $pu_ht,
  656. GETPOST('qty'),
  657. $tva_tx,
  658. $localtax1_tx,
  659. $localtax2_tx,
  660. $object->id,
  661. GETPOST('remise_percent'),
  662. '',
  663. '',
  664. '',
  665. '',
  666. '',
  667. $price_base_type,
  668. $pu_ttc,
  669. Facture::TYPE_STANDARD,
  670. -1,
  671. 0,
  672. '',
  673. 0,
  674. 0,
  675. null,
  676. $buyprice,
  677. '',
  678. 0,
  679. 100,
  680. '',
  681. $object->fk_unit
  682. );
  683. if ($result > 0) {
  684. header("Location: " . DOL_URL_ROOT . "/compta/facture/card.php?facid=" . $facture->id);
  685. exit;
  686. }
  687. }
  688. }
  689. else {
  690. $action="";
  691. setEventMessages($langs->trans("WarningSelectOneDocument"), null, 'warnings');
  692. }
  693. }
  694. }
  695. /*
  696. * View
  697. */
  698. $title = $langs->trans('ProductServiceCard');
  699. $helpurl = '';
  700. $shortlabel = dol_trunc($object->label,16);
  701. if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT))
  702. {
  703. $title = $langs->trans('Product')." ". $shortlabel ." - ".$langs->trans('Card');
  704. $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  705. }
  706. if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE))
  707. {
  708. $title = $langs->trans('Service')." ". $shortlabel ." - ".$langs->trans('Card');
  709. $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  710. }
  711. llxHeader('', $title, $helpurl);
  712. $form = new Form($db);
  713. $formfile = new FormFile($db);
  714. $formproduct = new FormProduct($db);
  715. if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
  716. // Load object modBarCodeProduct
  717. $res=0;
  718. if (! empty($conf->barcode->enabled) && ! empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
  719. {
  720. $module=strtolower($conf->global->BARCODE_PRODUCT_ADDON_NUM);
  721. $dirbarcode=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
  722. foreach ($dirbarcode as $dirroot)
  723. {
  724. $res=dol_include_once($dirroot.$module.'.php');
  725. if ($res) break;
  726. }
  727. if ($res > 0)
  728. {
  729. $modBarCodeProduct =new $module();
  730. }
  731. }
  732. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
  733. {
  734. // -----------------------------------------
  735. // When used with CANVAS
  736. // -----------------------------------------
  737. if (empty($object->error) && $id)
  738. {
  739. $object = new Product($db);
  740. $result=$object->fetch($id);
  741. if ($result <= 0) dol_print_error('',$object->error);
  742. }
  743. $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
  744. $objcanvas->display_canvas($action); // Show template
  745. }
  746. else
  747. {
  748. // -----------------------------------------
  749. // When used in standard mode
  750. // -----------------------------------------
  751. if ($action == 'create' && ($user->rights->produit->creer || $user->rights->service->creer))
  752. {
  753. //WYSIWYG Editor
  754. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  755. // Load object modCodeProduct
  756. $module=(! empty($conf->global->PRODUCT_CODEPRODUCT_ADDON)?$conf->global->PRODUCT_CODEPRODUCT_ADDON:'mod_codeproduct_leopard');
  757. if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php')
  758. {
  759. $module = substr($module, 0, dol_strlen($module)-4);
  760. }
  761. $result=dol_include_once('/core/modules/product/'.$module.'.php');
  762. if ($result > 0)
  763. {
  764. $modCodeProduct = new $module();
  765. }
  766. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  767. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  768. print '<input type="hidden" name="action" value="add">';
  769. print '<input type="hidden" name="type" value="'.$type.'">'."\n";
  770. if (! empty($modCodeProduct->code_auto))
  771. print '<input type="hidden" name="code_auto" value="1">';
  772. if (! empty($modBarCodeProduct->code_auto))
  773. print '<input type="hidden" name="barcode_auto" value="1">';
  774. if ($type==1) $title=$langs->trans("NewService");
  775. else $title=$langs->trans("NewProduct");
  776. $linkback="";
  777. print load_fiche_titre($title,$linkback,'title_products.png');
  778. dol_fiche_head('');
  779. print '<table class="border centpercent">';
  780. print '<tr>';
  781. $tmpcode='';
  782. if (! empty($modCodeProduct->code_auto)) $tmpcode=$modCodeProduct->getNextValue($object,$type);
  783. print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOST('ref')?GETPOST('ref'):$tmpcode).'">';
  784. if ($refalreadyexists)
  785. {
  786. print $langs->trans("RefAlreadyExists");
  787. }
  788. print '</td></tr>';
  789. // Label
  790. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label')).'"></td></tr>';
  791. // On sell
  792. print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  793. $statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
  794. print $form->selectarray('statut',$statutarray,GETPOST('statut'));
  795. print '</td></tr>';
  796. // To buy
  797. print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  798. $statutarray=array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
  799. print $form->selectarray('statut_buy',$statutarray,GETPOST('statut_buy'));
  800. print '</td></tr>';
  801. // Batch number management
  802. if (! empty($conf->productbatch->enabled))
  803. {
  804. print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td colspan="3">';
  805. $statutarray=array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"));
  806. print $form->selectarray('status_batch',$statutarray,GETPOST('status_batch'));
  807. print '</td></tr>';
  808. }
  809. $showbarcode=empty($conf->barcode->enabled)?0:1;
  810. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
  811. if ($showbarcode)
  812. {
  813. print '<tr><td>'.$langs->trans('BarcodeType').'</td><td>';
  814. if (isset($_POST['fk_barcode_type']))
  815. {
  816. $fk_barcode_type=GETPOST('fk_barcode_type');
  817. }
  818. else
  819. {
  820. if (empty($fk_barcode_type) && ! empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
  821. }
  822. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
  823. $formbarcode = new FormBarCode($db);
  824. print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
  825. print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
  826. $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
  827. if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
  828. print '<input class="maxwidth100" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
  829. print '</td></tr>';
  830. }
  831. // Description (used in invoice, propal...)
  832. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td colspan="3">';
  833. $doleditor = new DolEditor('desc', GETPOST('desc'), '', 160, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_4, '90%');
  834. $doleditor->Create();
  835. print "</td></tr>";
  836. // Public URL
  837. print '<tr><td>'.$langs->trans("PublicUrl").'</td><td colspan="3">';
  838. print '<input type="text" name="url" class="quatrevingtpercent" value="'.GETPOST('url').'">';
  839. print '</td></tr>';
  840. // Stock min level
  841. if ($type != 1 && ! empty($conf->stock->enabled))
  842. {
  843. print '<tr><td>'.$langs->trans("StockLimit").'</td><td>';
  844. print '<input name="seuil_stock_alerte" class="maxwidth50" value="'.GETPOST('seuil_stock_alerte').'">';
  845. print '</td>';
  846. // Stock desired level
  847. print '<td>'.$langs->trans("DesiredStock").'</td><td>';
  848. print '<input name="desiredstock" class="maxwidth50" value="'.GETPOST('desiredstock').'">';
  849. print '</td></tr>';
  850. }
  851. else
  852. {
  853. print '<input name="seuil_stock_alerte" type="hidden" value="0">';
  854. print '<input name="desiredstock" type="hidden" value="0">';
  855. }
  856. // Nature
  857. if ($type != 1)
  858. {
  859. print '<tr><td>'.$langs->trans("Nature").'</td><td colspan="3">';
  860. $statutarray=array('1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial"));
  861. print $form->selectarray('finished',$statutarray,GETPOST('finished'),1);
  862. print '</td></tr>';
  863. }
  864. // Duration
  865. if ($type == 1)
  866. {
  867. print '<tr><td>' . $langs->trans("Duration") . '</td><td colspan="3"><input name="duration_value" size="6" maxlength="5" value="' . $duration_value . '"> &nbsp;';
  868. print '<input name="duration_unit" type="radio" value="h">'.$langs->trans("Hour").'&nbsp;';
  869. print '<input name="duration_unit" type="radio" value="d">'.$langs->trans("Day").'&nbsp;';
  870. print '<input name="duration_unit" type="radio" value="w">'.$langs->trans("Week").'&nbsp;';
  871. print '<input name="duration_unit" type="radio" value="m">'.$langs->trans("Month").'&nbsp;';
  872. print '<input name="duration_unit" type="radio" value="y">'.$langs->trans("Year").'&nbsp;';
  873. print '</td></tr>';
  874. }
  875. if ($type != 1) // Le poids et le volume ne concerne que les produits et pas les services
  876. {
  877. // Weight
  878. print '<tr><td>'.$langs->trans("Weight").'</td><td colspan="3">';
  879. print '<input name="weight" size="4" value="'.GETPOST('weight').'">';
  880. print $formproduct->select_measuring_units("weight_units","weight");
  881. print '</td></tr>';
  882. // Length
  883. if (empty($conf->global->PRODUCT_DISABLE_SIZE))
  884. {
  885. print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td colspan="3">';
  886. print '<input name="size" size="4" value="'.GETPOST('size').'"> x ';
  887. print '<input name="sizewidth" size="4" value="'.GETPOST('sizewidth').'"> x ';
  888. print '<input name="sizeheight" size="4" value="'.GETPOST('sizeheight').'">';
  889. print $formproduct->select_measuring_units("size_units","size");
  890. print '</td></tr>';
  891. }
  892. if (empty($conf->global->PRODUCT_DISABLE_SURFACE))
  893. {
  894. // Surface
  895. print '<tr><td>'.$langs->trans("Surface").'</td><td colspan="3">';
  896. print '<input name="surface" size="4" value="'.GETPOST('surface').'">';
  897. print $formproduct->select_measuring_units("surface_units","surface");
  898. print '</td></tr>';
  899. }
  900. // Volume
  901. print '<tr><td>'.$langs->trans("Volume").'</td><td colspan="3">';
  902. print '<input name="volume" size="4" value="'.GETPOST('volume').'">';
  903. print $formproduct->select_measuring_units("volume_units","volume");
  904. print '</td></tr>';
  905. }
  906. // Units
  907. if($conf->global->PRODUCT_USE_UNITS)
  908. {
  909. print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td>';
  910. print '<td colspan="3">';
  911. print $form->selectUnits('','units');
  912. print '</td></tr>';
  913. }
  914. // Custom code
  915. if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO) && empty($type))
  916. {
  917. print '<tr><td>'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.GETPOST('customcode').'"></td>';
  918. // Origin country
  919. print '<td>'.$langs->trans("CountryOrigin").'</td><td>';
  920. print $form->select_country(GETPOST('country_id','int'),'country_id');
  921. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  922. print '</td></tr>';
  923. }
  924. // Other attributes
  925. $parameters=array('colspan' => 3);
  926. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  927. if (empty($reshook) && ! empty($extrafields->attribute_label))
  928. {
  929. print $object->showOptionals($extrafields,'edit',$parameters);
  930. }
  931. // Note (private, no output on invoices, propales...)
  932. //if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) available in create mode
  933. //{
  934. print '<tr><td class="tdtop">'.$langs->trans("NoteNotVisibleOnBill").'</td><td colspan="3">';
  935. // 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.
  936. $doleditor = new DolEditor('note_private', GETPOST('note_private'), '', 140, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_8, '90%');
  937. $doleditor->Create();
  938. print "</td></tr>";
  939. //}
  940. if($conf->categorie->enabled) {
  941. // Categories
  942. print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
  943. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1);
  944. print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
  945. print "</td></tr>";
  946. }
  947. print '</table>';
  948. print '<br>';
  949. if (! empty($conf->global->PRODUIT_MULTIPRICES))
  950. {
  951. // We do no show price array on create when multiprices enabled.
  952. // We must set them on prices tab.
  953. }
  954. else
  955. {
  956. print '<table class="border" width="100%">';
  957. // Price
  958. print '<tr><td class="titlefieldcreate">'.$langs->trans("SellingPrice").'</td>';
  959. print '<td><input name="price" class="maxwidth50" value="'.$object->price.'">';
  960. print $form->selectPriceBaseType($object->price_base_type, "price_base_type");
  961. print '</td></tr>';
  962. // Min price
  963. print '<tr><td>'.$langs->trans("MinPrice").'</td>';
  964. print '<td><input name="price_min" class="maxwidth50" value="'.$object->price_min.'">';
  965. print '</td></tr>';
  966. // VAT
  967. print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
  968. print $form->load_tva("tva_tx",-1,$mysoc,'');
  969. print '</td></tr>';
  970. print '</table>';
  971. print '<br>';
  972. }
  973. // Accountancy codes
  974. print '<table class="border" width="100%">';
  975. if (! empty($conf->accounting->enabled))
  976. {
  977. // Accountancy_code_sell
  978. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  979. print '<td>';
  980. print $formaccountancy->select_account(GETPOST('accountancy_code_sell'), 'accountancy_code_sell', 1, null, 1, 1, '');
  981. print '</td></tr>';
  982. // Accountancy_code_buy
  983. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  984. print '<td>';
  985. print $formaccountancy->select_account(GETPOST('accountancy_code_buy'), 'accountancy_code_buy', 1, null, 1, 1, '');
  986. print '</td></tr>';
  987. }
  988. else // For external software
  989. {
  990. // Accountancy_code_sell
  991. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  992. print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
  993. print '</td></tr>';
  994. // Accountancy_code_buy
  995. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  996. print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
  997. print '</td></tr>';
  998. }
  999. print '</table>';
  1000. dol_fiche_end();
  1001. print '<div class="center">';
  1002. print '<input type="submit" class="button" value="' . $langs->trans("Create") . '">';
  1003. print ' &nbsp; &nbsp; ';
  1004. print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
  1005. print '</div>';
  1006. print '</form>';
  1007. }
  1008. /*
  1009. * Product card
  1010. */
  1011. else if ($object->id > 0)
  1012. {
  1013. // Fiche en mode edition
  1014. if ($action == 'edit' && ((($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer))))
  1015. {
  1016. //WYSIWYG Editor
  1017. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1018. $type = $langs->trans('Product');
  1019. if ($object->isService()) $type = $langs->trans('Service');
  1020. //print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), "");
  1021. // Main official, simple, and not duplicated code
  1022. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">'."\n";
  1023. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1024. print '<input type="hidden" name="action" value="update">';
  1025. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1026. print '<input type="hidden" name="canvas" value="'.$object->canvas.'">';
  1027. $head=product_prepare_head($object);
  1028. $titre=$langs->trans("CardProduct".$object->type);
  1029. $picto=($object->type== Product::TYPE_SERVICE?'service':'product');
  1030. dol_fiche_head($head, 'card', $titre, 0, $picto);
  1031. print '<table class="border allwidth">';
  1032. // Ref
  1033. print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag($object->ref).'"></td></tr>';
  1034. // Label
  1035. 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>';
  1036. // Status To sell
  1037. print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
  1038. print '<select class="flat" name="statut">';
  1039. if ($object->status)
  1040. {
  1041. print '<option value="1" selected>'.$langs->trans("OnSell").'</option>';
  1042. print '<option value="0">'.$langs->trans("NotOnSell").'</option>';
  1043. }
  1044. else
  1045. {
  1046. print '<option value="1">'.$langs->trans("OnSell").'</option>';
  1047. print '<option value="0" selected>'.$langs->trans("NotOnSell").'</option>';
  1048. }
  1049. print '</select>';
  1050. print '</td></tr>';
  1051. // Status To Buy
  1052. print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
  1053. print '<select class="flat" name="statut_buy">';
  1054. if ($object->status_buy)
  1055. {
  1056. print '<option value="1" selected>'.$langs->trans("ProductStatusOnBuy").'</option>';
  1057. print '<option value="0">'.$langs->trans("ProductStatusNotOnBuy").'</option>';
  1058. }
  1059. else
  1060. {
  1061. print '<option value="1">'.$langs->trans("ProductStatusOnBuy").'</option>';
  1062. print '<option value="0" selected>'.$langs->trans("ProductStatusNotOnBuy").'</option>';
  1063. }
  1064. print '</select>';
  1065. print '</td></tr>';
  1066. // Batch number managment
  1067. if ($conf->productbatch->enabled) {
  1068. print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td colspan="3">';
  1069. $statutarray=array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"));
  1070. print $form->selectarray('status_batch',$statutarray,$object->status_batch);
  1071. print '</td></tr>';
  1072. }
  1073. // Barcode
  1074. $showbarcode=empty($conf->barcode->enabled)?0:1;
  1075. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
  1076. if ($showbarcode)
  1077. {
  1078. print '<tr><td>'.$langs->trans('BarcodeType').'</td><td>';
  1079. if (isset($_POST['fk_barcode_type']))
  1080. {
  1081. $fk_barcode_type=GETPOST('fk_barcode_type');
  1082. }
  1083. else
  1084. {
  1085. $fk_barcode_type=$object->barcode_type;
  1086. if (empty($fk_barcode_type) && ! empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
  1087. }
  1088. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
  1089. $formbarcode = new FormBarCode($db);
  1090. print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
  1091. print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
  1092. $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
  1093. if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
  1094. print '<input size="40" class="maxwidthonsmartphone" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
  1095. print '</td></tr>';
  1096. }
  1097. // Description (used in invoice, propal...)
  1098. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td colspan="3">';
  1099. // 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.
  1100. $doleditor = new DolEditor('desc', $object->description, '', 160, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_4, '90%');
  1101. $doleditor->Create();
  1102. print "</td></tr>";
  1103. print "\n";
  1104. // Public Url
  1105. print '<tr><td>'.$langs->trans("PublicUrl").'</td><td colspan="3">';
  1106. print '<input type="text" name="url" class="quatrevingtpercent" value="'.$object->url.'">';
  1107. print '</td></tr>';
  1108. // Stock
  1109. /*
  1110. if ($object->isProduct() && ! empty($conf->stock->enabled))
  1111. {
  1112. print "<tr>".'<td>'.$langs->trans("StockLimit").'</td><td>';
  1113. print '<input name="seuil_stock_alerte" size="4" value="'.$object->seuil_stock_alerte.'">';
  1114. print '</td>';
  1115. print '<td>'.$langs->trans("DesiredStock").'</td><td>';
  1116. print '<input name="desiredstock" size="4" value="'.$object->desiredstock.'">';
  1117. print '</td></tr>';
  1118. }
  1119. else
  1120. {
  1121. print '<input name="seuil_stock_alerte" type="hidden" value="'.$object->seuil_stock_alerte.'">';
  1122. print '<input name="desiredstock" type="hidden" value="'.$object->desiredstock.'">';
  1123. }*/
  1124. // Nature
  1125. if($object->type!= Product::TYPE_SERVICE)
  1126. {
  1127. print '<tr><td>'.$langs->trans("Nature").'</td><td colspan="3">';
  1128. $statutarray=array('-1'=>'&nbsp;', '1' => $langs->trans("Finished"), '0' => $langs->trans("RowMaterial"));
  1129. print $form->selectarray('finished',$statutarray,$object->finished);
  1130. print '</td></tr>';
  1131. }
  1132. if ($object->isService())
  1133. {
  1134. // Duration
  1135. print '<tr><td>'.$langs->trans("Duration").'</td><td colspan="3"><input name="duration_value" size="3" maxlength="5" value="'.$object->duration_value.'">';
  1136. print '&nbsp; ';
  1137. print '<input name="duration_unit" type="radio" value="h"'.($object->duration_unit=='h'?' checked':'').'>'.$langs->trans("Hour");
  1138. print '&nbsp; ';
  1139. print '<input name="duration_unit" type="radio" value="d"'.($object->duration_unit=='d'?' checked':'').'>'.$langs->trans("Day");
  1140. print '&nbsp; ';
  1141. print '<input name="duration_unit" type="radio" value="w"'.($object->duration_unit=='w'?' checked':'').'>'.$langs->trans("Week");
  1142. print '&nbsp; ';
  1143. print '<input name="duration_unit" type="radio" value="m"'.($object->duration_unit=='m'?' checked':'').'>'.$langs->trans("Month");
  1144. print '&nbsp; ';
  1145. print '<input name="duration_unit" type="radio" value="y"'.($object->duration_unit=='y'?' checked':'').'>'.$langs->trans("Year");
  1146. print '</td></tr>';
  1147. }
  1148. else
  1149. {
  1150. // Weight
  1151. print '<tr><td>'.$langs->trans("Weight").'</td><td colspan="3">';
  1152. print '<input name="weight" size="5" value="'.$object->weight.'"> ';
  1153. print $formproduct->select_measuring_units("weight_units", "weight", $object->weight_units);
  1154. print '</td></tr>';
  1155. if (empty($conf->global->PRODUCT_DISABLE_SIZE))
  1156. {
  1157. // Length
  1158. print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td colspan="3">';
  1159. print '<input name="size" size="5" value="'.$object->length.'">x';
  1160. print '<input name="sizewidth" size="5" value="'.$object->width.'">x';
  1161. print '<input name="sizeheight" size="5" value="'.$object->height.'"> ';
  1162. print $formproduct->select_measuring_units("size_units", "size", $object->length_units);
  1163. print '</td></tr>';
  1164. }
  1165. if (empty($conf->global->PRODUCT_DISABLE_SURFACE))
  1166. {
  1167. // Surface
  1168. print '<tr><td>'.$langs->trans("Surface").'</td><td colspan="3">';
  1169. print '<input name="surface" size="5" value="'.$object->surface.'"> ';
  1170. print $formproduct->select_measuring_units("surface_units", "surface", $object->surface_units);
  1171. print '</td></tr>';
  1172. }
  1173. if (empty($conf->global->PRODUCT_DISABLE_VOLUME))
  1174. {
  1175. // Volume
  1176. print '<tr><td>'.$langs->trans("Volume").'</td><td colspan="3">';
  1177. print '<input name="volume" size="5" value="'.$object->volume.'"> ';
  1178. print $formproduct->select_measuring_units("volume_units", "volume", $object->volume_units);
  1179. print '</td></tr>';
  1180. }
  1181. }
  1182. // Units
  1183. if($conf->global->PRODUCT_USE_UNITS)
  1184. {
  1185. print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td>';
  1186. print '<td colspan="3">';
  1187. print $form->selectUnits($object->fk_unit, 'units');
  1188. print '</td></tr>';
  1189. }
  1190. // Custom code
  1191. if (! $object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO))
  1192. {
  1193. print '<tr><td>'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.$object->customcode.'"></td>';
  1194. // Origin country
  1195. print '<td>'.$langs->trans("CountryOrigin").'</td><td>';
  1196. print $form->select_country($object->country_id, 'country_id', '', 0, 'minwidth100 maxwidthonsmartphone');
  1197. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  1198. print '</td></tr>';
  1199. }
  1200. // Other attributes
  1201. $parameters=array('colspan' => ' colspan="2"');
  1202. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1203. if (empty($reshook) && ! empty($extrafields->attribute_label))
  1204. {
  1205. print $object->showOptionals($extrafields,'edit');
  1206. }
  1207. // Tags-Categories
  1208. if ($conf->categorie->enabled)
  1209. {
  1210. print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td colspan="3">';
  1211. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1);
  1212. $c = new Categorie($db);
  1213. $cats = $c->containing($object->id,Categorie::TYPE_PRODUCT);
  1214. foreach($cats as $cat) {
  1215. $arrayselected[] = $cat->id;
  1216. }
  1217. print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
  1218. print "</td></tr>";
  1219. }
  1220. // Note private
  1221. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  1222. {
  1223. print '<tr><td class="tdtop">'.$langs->trans("NoteNotVisibleOnBill").'</td><td colspan="3">';
  1224. $doleditor = new DolEditor('note_private', $object->note_private, '', 140, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_4, '90%');
  1225. $doleditor->Create();
  1226. print "</td></tr>";
  1227. }
  1228. print '</table>';
  1229. print '<br>';
  1230. print '<table class="border" width="100%">';
  1231. if (! empty($conf->accounting->enabled))
  1232. {
  1233. // Accountancy_code_sell
  1234. print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
  1235. print '<td>';
  1236. print $formaccountancy->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1);
  1237. print '</td></tr>';
  1238. // Accountancy_code_buy
  1239. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  1240. print '<td>';
  1241. print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
  1242. print '</td></tr>';
  1243. }
  1244. else // For external software
  1245. {
  1246. // Accountancy_code_sell
  1247. print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
  1248. print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
  1249. print '</td></tr>';
  1250. // Accountancy_code_buy
  1251. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  1252. print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
  1253. print '</td></tr>';
  1254. }
  1255. print '</table>';
  1256. dol_fiche_end();
  1257. print '<div class="center">';
  1258. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  1259. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1260. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  1261. print '</div>';
  1262. print '</form>';
  1263. }
  1264. // Fiche en mode visu
  1265. else
  1266. {
  1267. $showbarcode=empty($conf->barcode->enabled)?0:1;
  1268. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0;
  1269. $head=product_prepare_head($object);
  1270. $titre=$langs->trans("CardProduct".$object->type);
  1271. $picto=($object->type== Product::TYPE_SERVICE?'service':'product');
  1272. dol_fiche_head($head, 'card', $titre, -1, $picto);
  1273. $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?type='.$object->type.'">'.$langs->trans("BackToList").'</a>';
  1274. $object->next_prev_filter=" fk_product_type = ".$object->type;
  1275. dol_banner_tab($object, 'ref', $linkback, ($user->societe_id?0:1), 'ref');
  1276. print '<div class="fichecenter">';
  1277. print '<div class="fichehalfleft">';
  1278. print '<div class="underbanner clearboth"></div>';
  1279. print '<table class="border tableforfield" width="100%">';
  1280. // Type
  1281. if (! empty($conf->produit->enabled) && ! empty($conf->service->enabled))
  1282. {
  1283. // TODO change for compatibility with edit in place
  1284. $typeformat='select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
  1285. print '<tr><td class="titlefield">'.$form->editfieldkey("Type",'fk_product_type',$object->type,$object,$user->rights->produit->creer||$user->rights->service->creer,$typeformat).'</td><td colspan="2">';
  1286. print $form->editfieldval("Type",'fk_product_type',$object->type,$object,$user->rights->produit->creer||$user->rights->service->creer,$typeformat);
  1287. print '</td></tr>';
  1288. }
  1289. if ($showbarcode)
  1290. {
  1291. // Barcode type
  1292. print '<tr><td class="nowrap">';
  1293. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  1294. print $langs->trans("BarcodeType");
  1295. print '</td>';
  1296. if (($action != 'editbarcodetype') && ! empty($user->rights->produit->creer) && $createbarcode) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcodetype&amp;id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
  1297. print '</tr></table>';
  1298. print '</td><td colspan="2">';
  1299. if ($action == 'editbarcodetype' || $action == 'editbarcode')
  1300. {
  1301. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
  1302. $formbarcode = new FormBarCode($db);
  1303. }
  1304. if ($action == 'editbarcodetype')
  1305. {
  1306. $formbarcode->form_barcode_type($_SERVER['PHP_SELF'].'?id='.$object->id,$object->barcode_type,'fk_barcode_type');
  1307. }
  1308. else
  1309. {
  1310. $object->fetch_barcode();
  1311. print $object->barcode_type_label?$object->barcode_type_label:($object->barcode?'<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>':'');
  1312. }
  1313. print '</td></tr>'."\n";
  1314. // Barcode value
  1315. print '<tr><td class="nowrap">';
  1316. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  1317. print $langs->trans("BarcodeValue");
  1318. print '</td>';
  1319. if (($action != 'editbarcode') && ! empty($user->rights->produit->creer) && $createbarcode) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcode&amp;id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
  1320. print '</tr></table>';
  1321. print '</td><td colspan="2">';
  1322. if ($action == 'editbarcode')
  1323. {
  1324. $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
  1325. if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
  1326. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  1327. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1328. print '<input type="hidden" name="action" value="setbarcode">';
  1329. print '<input type="hidden" name="barcode_type_code" value="'.$object->barcode_type_code.'">';
  1330. print '<input size="40" class="maxwidthonsmartphone" type="text" name="barcode" value="'.$tmpcode.'">';
  1331. print '&nbsp;<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  1332. print '</form>';
  1333. }
  1334. else
  1335. {
  1336. print $object->barcode;
  1337. }
  1338. print '</td></tr>'."\n";
  1339. }
  1340. // Accountancy sell code
  1341. print '<tr><td class="nowrap">';
  1342. print $langs->trans("ProductAccountancySellCode");
  1343. print '</td><td colspan="2">';
  1344. if (! empty($conf->accounting->enabled))
  1345. {
  1346. $accountingaccount = new AccountingAccount($db);
  1347. $accountingaccount->fetch('',$object->accountancy_code_sell);
  1348. print $accountingaccount->getNomUrl(0,1,1,'',1);
  1349. } else {
  1350. print $object->accountancy_code_sell;
  1351. }
  1352. print '</td></tr>';
  1353. // Accountancy buy code
  1354. print '<tr><td class="nowrap">';
  1355. print $langs->trans("ProductAccountancyBuyCode");
  1356. print '</td><td colspan="2">';
  1357. if (! empty($conf->accounting->enabled))
  1358. {
  1359. $accountingaccount2 = new AccountingAccount($db);
  1360. $accountingaccount2->fetch('',$object->accountancy_code_buy);
  1361. print $accountingaccount2->getNomUrl(0,1,1,'',1);
  1362. } else {
  1363. print $object->accountancy_code_buy;
  1364. }
  1365. print '</td></tr>';
  1366. // Status (to sell)
  1367. /*
  1368. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="2">';
  1369. if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
  1370. print ajax_object_onoff($object, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
  1371. } else {
  1372. print $object->getLibStatut(2,0);
  1373. }
  1374. print '</td></tr>';
  1375. // Status (to buy)
  1376. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="2">';
  1377. if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
  1378. print ajax_object_onoff($object, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
  1379. } else {
  1380. print $object->getLibStatut(2,1);
  1381. }
  1382. print '</td></tr>';
  1383. */
  1384. // Batch number management (to batch)
  1385. if (! empty($conf->productbatch->enabled)) {
  1386. print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td colspan="2">';
  1387. if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
  1388. print ajax_object_onoff($object, 'status_batch', 'tobatch', 'ProductStatusOnBatch', 'ProductStatusNotOnBatch');
  1389. } else {
  1390. print $object->getLibStatut(0,2);
  1391. }
  1392. print '</td></tr>';
  1393. }
  1394. // Description
  1395. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td colspan="2">'.(dol_textishtml($object->description)?$object->description:dol_nl2br($object->description,1,true)).'</td></tr>';
  1396. // Public URL
  1397. print '<tr><td>'.$langs->trans("PublicUrl").'</td><td colspan="2">';
  1398. print dol_print_url($object->url);
  1399. print '</td></tr>';
  1400. //Parent product.
  1401. if (!empty($conf->variants->enabled) && $object->isProduct()) {
  1402. $combination = new ProductCombination($db);
  1403. if ($combination->fetchByFkProductChild($object->id) > 0) {
  1404. $prodstatic = new Product($db);
  1405. $prodstatic->fetch($combination->fk_product_parent);
  1406. // Parent product
  1407. print '<tr><td>'.$langs->trans("ParentProduct").'</td><td colspan="2">';
  1408. print $prodstatic->getNomUrl(1);
  1409. print '</td></tr>';
  1410. }
  1411. }
  1412. print '</table>';
  1413. print '</div>';
  1414. print '<div class="fichehalfright"><div class="ficheaddleft">';
  1415. print '<div class="underbanner clearboth"></div>';
  1416. print '<table class="border tableforfield" width="100%">';
  1417. // Nature
  1418. if($object->type!= Product::TYPE_SERVICE)
  1419. {
  1420. print '<tr><td class="titlefield">'.$langs->trans("Nature").'</td><td colspan="2">';
  1421. print $object->getLibFinished();
  1422. print '</td></tr>';
  1423. }
  1424. if ($object->isService())
  1425. {
  1426. // Duration
  1427. print '<tr><td class="titlefield">'.$langs->trans("Duration").'</td><td colspan="2">'.$object->duration_value.'&nbsp;';
  1428. if ($object->duration_value > 1)
  1429. {
  1430. $dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("Days"),"w"=>$langs->trans("Weeks"),"m"=>$langs->trans("Months"),"y"=>$langs->trans("Years"));
  1431. }
  1432. else if ($object->duration_value > 0)
  1433. {
  1434. $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year"));
  1435. }
  1436. print (! empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? $langs->trans($dur[$object->duration_unit]) : '')."&nbsp;";
  1437. print '</td></tr>';
  1438. }
  1439. else
  1440. {
  1441. // Weight
  1442. print '<tr><td class="titlefield">'.$langs->trans("Weight").'</td><td colspan="2">';
  1443. if ($object->weight != '')
  1444. {
  1445. print $object->weight." ".measuring_units_string($object->weight_units,"weight");
  1446. }
  1447. else
  1448. {
  1449. print '&nbsp;';
  1450. }
  1451. print "</td></tr>\n";
  1452. if (empty($conf->global->PRODUCT_DISABLE_SIZE))
  1453. {
  1454. // Length
  1455. print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td colspan="2">';
  1456. if ($object->length != '' || $object->width != '' || $object->height != '')
  1457. {
  1458. print $object->length;
  1459. if ($object->width) print " x ".$object->width;
  1460. if ($object->height) print " x ".$object->height;
  1461. print ' '.measuring_units_string($object->length_units,"size");
  1462. }
  1463. else
  1464. {
  1465. print '&nbsp;';
  1466. }
  1467. print "</td></tr>\n";
  1468. }
  1469. if (empty($conf->global->PRODUCT_DISABLE_SURFACE))
  1470. {
  1471. // Surface
  1472. print '<tr><td>'.$langs->trans("Surface").'</td><td colspan="2">';
  1473. if ($object->surface != '')
  1474. {
  1475. print $object->surface." ".measuring_units_string($object->surface_units,"surface");
  1476. }
  1477. else
  1478. {
  1479. print '&nbsp;';
  1480. }
  1481. print "</td></tr>\n";
  1482. }
  1483. if (empty($conf->global->PRODUCT_DISABLE_VOLUME))
  1484. {
  1485. // Volume
  1486. print '<tr><td>'.$langs->trans("Volume").'</td><td colspan="2">';
  1487. if ($object->volume != '')
  1488. {
  1489. print $object->volume." ".measuring_units_string($object->volume_units,"volume");
  1490. }
  1491. else
  1492. {
  1493. print '&nbsp;';
  1494. }
  1495. print "</td></tr>\n";
  1496. }
  1497. }
  1498. // Unit
  1499. if (! empty($conf->global->PRODUCT_USE_UNITS))
  1500. {
  1501. $unit = $object->getLabelOfUnit();
  1502. print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td><td>';
  1503. if ($unit !== '') {
  1504. print $langs->trans($unit);
  1505. }
  1506. print '</td></tr>';
  1507. }
  1508. // Custom code
  1509. if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO))
  1510. {
  1511. print '<tr><td>'.$langs->trans("CustomCode").'</td><td colspan="2">'.$object->customcode.'</td>';
  1512. // Origin country code
  1513. print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td colspan="2">'.getCountry($object->country_id,0,$db).'</td>';
  1514. }
  1515. // Other attributes
  1516. $parameters=array('colspan' => ' colspan="'.(2+(($showphoto||$showbarcode)?1:0)).'"');
  1517. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1518. if (empty($reshook) && ! empty($extrafields->attribute_label))
  1519. {
  1520. print $object->showOptionals($extrafields);
  1521. }
  1522. // Categories
  1523. if($conf->categorie->enabled) {
  1524. print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td colspan="3">';
  1525. print $form->showCategories($object->id,'product',1);
  1526. print "</td></tr>";
  1527. }
  1528. // Note private
  1529. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  1530. {
  1531. print '<!-- show Note --> '."\n";
  1532. print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td><td colspan="'.(2+(($showphoto||$showbarcode)?1:0)).'">'.(dol_textishtml($object->note_private)?$object->note_private:dol_nl2br($object->note_private,1,true)).'</td></tr>'."\n";
  1533. print '<!-- End show Note --> '."\n";
  1534. }
  1535. print "</table>\n";
  1536. print '</div>';
  1537. print '</div></div>';
  1538. print '<div style="clear:both"></div>';
  1539. dol_fiche_end();
  1540. }
  1541. }
  1542. else if ($action != 'create')
  1543. {
  1544. exit;
  1545. }
  1546. }
  1547. // Load object modCodeProduct
  1548. $module=(! empty($conf->global->PRODUCT_CODEPRODUCT_ADDON)?$conf->global->PRODUCT_CODEPRODUCT_ADDON:'mod_codeproduct_leopard');
  1549. if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php')
  1550. {
  1551. $module = substr($module, 0, dol_strlen($module)-4);
  1552. }
  1553. $result=dol_include_once('/core/modules/product/'.$module.'.php');
  1554. if ($result > 0)
  1555. {
  1556. $modCodeProduct = new $module();
  1557. }
  1558. $tmpcode='';
  1559. if (! empty($modCodeProduct->code_auto)) $tmpcode=$modCodeProduct->getNextValue($object,$object->type);
  1560. // Define confirmation messages
  1561. $formquestionclone=array(
  1562. 'text' => $langs->trans("ConfirmClone"),
  1563. array('type' => 'text', 'name' => 'clone_ref','label' => $langs->trans("NewRefForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->ref : $tmpcode, 'size'=>24),
  1564. array('type' => 'checkbox', 'name' => 'clone_content','label' => $langs->trans("CloneContentProduct"), 'value' => 1),
  1565. array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("FeatureNotYetAvailable").')', 'value' => 0, 'disabled' => true),
  1566. );
  1567. if (! empty($conf->global->PRODUIT_SOUSPRODUITS))
  1568. {
  1569. $formquestionclone[]=array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1);
  1570. }
  1571. // Confirm delete product
  1572. if (($action == 'delete' && (empty($conf->use_javascript_ajax) || ! empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
  1573. || (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) // Always output when not jmobile nor js
  1574. {
  1575. print $form->formconfirm("card.php?id=".$object->id,$langs->trans("DeleteProduct"),$langs->trans("ConfirmDeleteProduct"),"confirm_delete",'',0,"action-delete");
  1576. }
  1577. // Clone confirmation
  1578. if (($action == 'clone' && (empty($conf->use_javascript_ajax) || ! empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
  1579. || (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) // Always output when not jmobile nor js
  1580. {
  1581. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneProduct'),$langs->trans('ConfirmCloneProduct',$object->ref),'confirm_clone',$formquestionclone,'yes','action-clone',250,600);
  1582. }
  1583. /* ************************************************************************** */
  1584. /* */
  1585. /* Barre d'action */
  1586. /* */
  1587. /* ************************************************************************** */
  1588. if ($action != 'create' && $action != 'edit')
  1589. {
  1590. print "\n".'<div class="tabsAction">'."\n";
  1591. $parameters=array();
  1592. $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1593. if (empty($reshook))
  1594. {
  1595. if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer ) ||
  1596. ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer))
  1597. {
  1598. if (! isset($object->no_button_edit) || $object->no_button_edit <> 1) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("Modify").'</a></div>';
  1599. if (! isset($object->no_button_copy) || $object->no_button_copy <> 1)
  1600. {
  1601. if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))
  1602. {
  1603. print '<div class="inline-block divButAction"><span id="action-clone" class="butAction">'.$langs->trans('ToClone').'</span></div>'."\n";
  1604. }
  1605. else
  1606. {
  1607. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=clone&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a></div>';
  1608. }
  1609. }
  1610. }
  1611. $object_is_used = $object->isObjectUsed($object->id);
  1612. if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer)
  1613. || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer))
  1614. {
  1615. if (empty($object_is_used) && (! isset($object->no_button_delete) || $object->no_button_delete <> 1))
  1616. {
  1617. if (! empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))
  1618. {
  1619. print '<div class="inline-block divButAction"><span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span></div>'."\n";
  1620. }
  1621. else
  1622. {
  1623. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&amp;id='.$object->id.'">'.$langs->trans("Delete").'</a></div>';
  1624. }
  1625. }
  1626. else
  1627. {
  1628. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("ProductIsUsed").'">'.$langs->trans("Delete").'</a></div>';
  1629. }
  1630. }
  1631. else
  1632. {
  1633. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("Delete").'</a></div>';
  1634. }
  1635. }
  1636. print "\n</div>\n";
  1637. }
  1638. /*
  1639. * All the "Add to" areas
  1640. */
  1641. if (! empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == '' || $action == 'view') && $object->status)
  1642. {
  1643. //Variable used to check if any text is going to be printed
  1644. $html = '';
  1645. //print '<div class="fichecenter"><div class="fichehalfleft">';
  1646. // Propals
  1647. if (! empty($conf->propal->enabled) && $user->rights->propale->creer)
  1648. {
  1649. $propal = new Propal($db);
  1650. $langs->load("propal");
  1651. $otherprop = $propal->liste_array(2,1,0);
  1652. if (is_array($otherprop) && count($otherprop))
  1653. {
  1654. $html .= '<tr><td style="width: 200px;">';
  1655. $html .= $langs->trans("AddToDraftProposals").'</td><td>';
  1656. $html .= $form->selectarray("propalid", $otherprop, 0, 1);
  1657. $html .= '</td></tr>';
  1658. }
  1659. else
  1660. {
  1661. $html .= '<tr><td style="width: 200px;">';
  1662. $html .= $langs->trans("AddToDraftProposals").'</td><td>';
  1663. $html .= $langs->trans("NoDraftProposals");
  1664. $html .= '</td></tr>';
  1665. }
  1666. }
  1667. // Commande
  1668. if (! empty($conf->commande->enabled) && $user->rights->commande->creer)
  1669. {
  1670. $commande = new Commande($db);
  1671. $langs->load("orders");
  1672. $othercom = $commande->liste_array(2, 1, null);
  1673. if (is_array($othercom) && count($othercom))
  1674. {
  1675. $html .= '<tr><td style="width: 200px;">';
  1676. $html .= $langs->trans("AddToDraftOrders").'</td><td>';
  1677. $html .= $form->selectarray("commandeid", $othercom, 0, 1);
  1678. $html .= '</td></tr>';
  1679. }
  1680. else
  1681. {
  1682. $html .= '<tr><td style="width: 200px;">';
  1683. $html .= $langs->trans("AddToDraftOrders").'</td><td>';
  1684. $html .= $langs->trans("NoDraftOrders");
  1685. $html .= '</td></tr>';
  1686. }
  1687. }
  1688. // Factures
  1689. if (! empty($conf->facture->enabled) && $user->rights->facture->creer)
  1690. {
  1691. $invoice = new Facture($db);
  1692. $langs->load("bills");
  1693. $otherinvoice = $invoice->liste_array(2, 1, null);
  1694. if (is_array($otherinvoice) && count($otherinvoice))
  1695. {
  1696. $html .= '<tr><td style="width: 200px;">';
  1697. $html .= $langs->trans("AddToDraftInvoices").'</td><td>';
  1698. $html .= $form->selectarray("factureid", $otherinvoice, 0, 1);
  1699. $html .= '</td></tr>';
  1700. }
  1701. else
  1702. {
  1703. $html .= '<tr><td style="width: 200px;">';
  1704. $html .= $langs->trans("AddToDraftInvoices").'</td><td>';
  1705. $html .= $langs->trans("NoDraftInvoices");
  1706. $html .= '</td></tr>';
  1707. }
  1708. }
  1709. //If any text is going to be printed, then we show the table
  1710. if (!empty($html))
  1711. {
  1712. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  1713. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1714. print '<input type="hidden" name="action" value="addin">';
  1715. print load_fiche_titre($langs->trans("AddToDraft"),'','');
  1716. dol_fiche_head('');
  1717. $html .= '<tr><td class="nowrap">'.$langs->trans("Quantity").' ';
  1718. $html .= '<input type="text" class="flat" name="qty" size="1" value="1"></td>';
  1719. $html .= '<td class="nowrap">'.$langs->trans("ReductionShort").'(%) ';
  1720. $html .= '<input type="text" class="flat" name="remise_percent" size="1" value="0">';
  1721. $html .= '</td></tr>';
  1722. print '<table width="100%" class="border">';
  1723. print $html;
  1724. print '</table>';
  1725. print '<div class="center">';
  1726. print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
  1727. print '</div>';
  1728. dol_fiche_end();
  1729. print '</form>';
  1730. }
  1731. }
  1732. /*
  1733. * Documents generes
  1734. */
  1735. if ($action != 'create' && $action != 'edit' && $action != 'delete')
  1736. {
  1737. print '<div class="fichecenter"><div class="fichehalfleft">';
  1738. print '<a name="builddoc"></a>'; // ancre
  1739. // Documents
  1740. $objectref = dol_sanitizeFileName($object->ref);
  1741. $relativepath = $comref . '/' . $objectref . '.pdf';
  1742. $filedir = $conf->produit->dir_output . '/' . $objectref;
  1743. $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
  1744. $genallowed=$user->rights->produit->creer;
  1745. $delallowed=$user->rights->produit->supprimer;
  1746. print $formfile->showdocuments($modulepart,$object->ref,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang, '', $object);
  1747. $somethingshown=$formfile->numoffiles;
  1748. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  1749. print '</div></div></div>';
  1750. }
  1751. llxFooter();
  1752. $db->close();