card.php 94 KB

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