modProduct.class.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2014 Christophe Battarel <contact@altairis.fr>
  9. * Copyright (C) 2014 Cedric Gross <c.gross@kreiz-it.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \defgroup produit Module products
  26. * \brief Module to manage catalog of predefined products
  27. * \file htdocs/core/modules/modProduct.class.php
  28. * \ingroup produit
  29. * \brief File to describe module to manage catalog of predefined products
  30. */
  31. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  32. /**
  33. * Class descriptor of Product module
  34. */
  35. class modProduct extends DolibarrModules
  36. {
  37. /**
  38. * Constructor. Define names, constants, directories, boxes, permissions
  39. *
  40. * @param DoliDB $db Database handler
  41. */
  42. function __construct($db)
  43. {
  44. global $conf, $mysoc;
  45. $this->db = $db;
  46. $this->numero = 50;
  47. $this->family = "products";
  48. $this->module_position = 20;
  49. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  50. $this->name = preg_replace('/^mod/i','',get_class($this));
  51. $this->description = "Gestion des produits";
  52. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  53. $this->version = 'dolibarr';
  54. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  55. $this->special = 0;
  56. $this->picto='product';
  57. // Data directories to create when module is enabled
  58. $this->dirs = array("/product/temp");
  59. // Dependencies
  60. $this->depends = array();
  61. $this->requiredby = array("modStock","modBarcode","modProductBatch");
  62. // Config pages
  63. $this->config_page_url = array("product.php@product");
  64. $this->langfiles = array("products","companies","stocks","bills");
  65. // Constants
  66. $this->const = array();
  67. $r=0;
  68. $this->const[$r][0] = "PRODUCT_CODEPRODUCT_ADDON";
  69. $this->const[$r][1] = "chaine";
  70. $this->const[$r][2] = "mod_codeproduct_leopard";
  71. $this->const[$r][3] = 'Module to control product codes';
  72. $this->const[$r][4] = 0;
  73. $r++;
  74. // Boxes
  75. $this->boxes = array(
  76. 0=>array('file'=>'box_produits.php','enabledbydefaulton'=>'Home'),
  77. 1=>array('file'=>'box_produits_alerte_stock.php','enabledbydefaulton'=>''),
  78. 2=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home')
  79. );
  80. // Permissions
  81. $this->rights = array();
  82. $this->rights_class = 'produit';
  83. $r=0;
  84. $this->rights[$r][0] = 31; // id de la permission
  85. $this->rights[$r][1] = 'Lire les produits'; // libelle de la permission
  86. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  87. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  88. $this->rights[$r][4] = 'lire';
  89. $r++;
  90. $this->rights[$r][0] = 32; // id de la permission
  91. $this->rights[$r][1] = 'Creer/modifier les produits'; // libelle de la permission
  92. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  93. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  94. $this->rights[$r][4] = 'creer';
  95. $r++;
  96. $this->rights[$r][0] = 34; // id de la permission
  97. $this->rights[$r][1] = 'Supprimer les produits'; // libelle de la permission
  98. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  99. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  100. $this->rights[$r][4] = 'supprimer';
  101. $r++;
  102. $this->rights[$r][0] = 38; // Must be same permission than in service module
  103. $this->rights[$r][1] = 'Exporter les produits';
  104. $this->rights[$r][2] = 'r';
  105. $this->rights[$r][3] = 0;
  106. $this->rights[$r][4] = 'export';
  107. $r++;
  108. /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
  109. $r=0;
  110. $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
  111. 'type'=>'left', // This is a Left menu entry
  112. 'titre'=>'ProductVatMassChange',
  113. 'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=admintools',
  114. 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  115. 'position'=>300,
  116. 'enabled'=>'$conf->product->enabled && $leftmenu=="admintools"', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
  117. 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
  118. 'target'=>'',
  119. 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
  120. $r++;
  121. */
  122. // Exports
  123. //--------
  124. $r=0;
  125. $r++;
  126. $this->export_code[$r]=$this->rights_class.'_'.$r;
  127. $this->export_label[$r]="Products"; // Translation key (used only if key ExportDataset_xxx_z not found)
  128. $this->export_permission[$r]=array(array("produit","export"));
  129. $this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",'p.label'=>"Label",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.customcode'=>'CustomCode','p.price_base_type'=>"PriceBase",'p.price'=>"UnitPriceHT",'p.price_ttc'=>"UnitPriceTTC",'p.tva_tx'=>'VATRate','p.tosell'=>"OnSell",'p.tobuy'=>"OnBuy",'p.datec'=>'DateCreation','p.tms'=>'DateModification');
  130. if ($mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR';
  131. if (! empty($conf->stock->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.stock'=>'Stock','p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
  132. if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
  133. if (! empty($conf->fournisseur->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('s.nom'=>'Supplier','pf.ref_fourn'=>'SupplierRef','pf.unitprice'=>'SuppliersPrices'));
  134. if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.cost_price'=>'CostPrice'));
  135. if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories'));
  136. if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('l.lang'=>'Language', 'l.label'=>'TranslatedLabel','l.description'=>'TranslatedDescription','l.note'=>'TranslatedNote'));
  137. $this->export_TypeFields_array[$r]=array('p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date');
  138. if (! empty($conf->stock->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.stock'=>'Numeric','p.seuil_stock_alerte'=>'Numeric','p.desiredstock'=>'Numeric','p.pmp'=>'Numeric','p.cost_price'=>'Numeric'));
  139. if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
  140. if (! empty($conf->fournisseur->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('s.nom'=>'Text','pf.ref_fourn'=>'Text','pf.unitprice'=>'Numeric'));
  141. if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('l.lang'=>'Text', 'l.label'=>'Text','l.description'=>'Text','l.note'=>'Text'));
  142. if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text'));
  143. $this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product",'p.label'=>"product",'p.description'=>"product",'p.url'=>"product",'p.accountancy_code_sell'=>'product','p.accountancy_code_sell'=>'product','p.note'=>"product",'p.length'=>"product",'p.surface'=>"product",'p.volume'=>"product",'p.weight'=>"product",'p.customcode'=>'product','p.price_base_type'=>"product",'p.price'=>"product",'p.price_ttc'=>"product",'p.tva_tx'=>"product",'p.tosell'=>"product",'p.tobuy'=>"product",'p.datec'=>"product",'p.tms'=>"product");
  144. if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category'));
  145. if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product'));
  146. if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product'));
  147. if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product','pf.ref_fourn'=>'product','pf.unitprice'=>'product'));
  148. if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('l.lang'=>'translation', 'l.label'=>'translation','l.description'=>'translation','l.note'=>'translation'));
  149. $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
  150. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  151. if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid');
  152. $this->export_sql_start[$r]='SELECT DISTINCT ';
  153. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p';
  154. if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cp.fk_categorie = cat.rowid';
  155. if (! empty($conf->global->MAIN_MULTILANGS)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
  156. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
  157. if (! empty($conf->fournisseur->enabled)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pf ON pf.fk_product = p.rowid LEFT JOIN '.MAIN_DB_PREFIX.'societe s ON s.rowid = pf.fk_soc';
  158. $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity("product", 1).')';
  159. if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_sql_order[$r] =' GROUP BY p.rowid'; // FIXME The group by used a generic value to say "all fields in select except function fields"
  160. if (! empty($conf->global->PRODUIT_MULTIPRICES))
  161. {
  162. // Exports product multiprice
  163. $r++;
  164. $this->export_code[$r]=$this->rights_class.'_'.$r;
  165. $this->export_label[$r]="ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found)
  166. $this->export_permission[$r]=array(array("produit","export"));
  167. $this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",
  168. 'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
  169. 'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
  170. 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
  171. 'pr.tva_tx'=>'PriceLevelVATRate',
  172. 'pr.date_price'=>'DateCreation');
  173. if ($mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR';
  174. //$this->export_TypeFields_array[$r]=array('p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text','p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",'p.datec'=>'Date','p.tms'=>'Date');
  175. $this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product",
  176. 'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product",
  177. 'pr.price_ttc'=>"product",
  178. 'pr.price_min'=>"product",'pr.price_min_ttc'=>"product",
  179. 'pr.tva_tx'=>'product',
  180. 'pr.recuperableonly'=>'product',
  181. 'pr.date_price'=>"product");
  182. $this->export_sql_start[$r]='SELECT DISTINCT ';
  183. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p';
  184. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product';
  185. $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity("product", 1).')';
  186. }
  187. // Imports
  188. //--------
  189. $r=0;
  190. $r++;
  191. $this->import_code[$r]=$this->rights_class.'_'.$r;
  192. $this->import_label[$r]="Products"; // Translation key
  193. $this->import_icon[$r]=$this->picto;
  194. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  195. $this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields');
  196. $this->import_tables_creator_array[$r]=array('p'=>'fk_user_author'); // Fields to store import user id
  197. $this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation');
  198. if (! empty($conf->stock->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.seuil_stock_alerte'=>'StockLimit','p.desiredstock'=>'DesiredStock','p.pmp'=>'PMPValue'));
  199. if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.cost_price'=>'CostPrice'));
  200. if ($mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR'));
  201. if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
  202. // Add extra fields
  203. $import_extrafield_sample=array();
  204. $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.')';
  205. $resql=$this->db->query($sql);
  206. if ($resql) // This can fail when class is used on old database (during migration for example)
  207. {
  208. while ($obj=$this->db->fetch_object($resql))
  209. {
  210. $fieldname='extra.'.$obj->name;
  211. $fieldlabel=ucfirst($obj->label);
  212. $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
  213. $import_extrafield_sample[$fieldname]=$fieldlabel;
  214. }
  215. }
  216. // End add extra fields
  217. $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
  218. $this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]$','p.tobuy'=>'^[0|1]$','p.fk_product_type'=>'^[0|1]$','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','p.recuperableonly'=>'^[0|1]$');
  219. $import_sample=array('p.ref'=>"PREF123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31','p.recuperableonly'=>'0 or 1');
  220. $this->import_examplevalues_array[$r]=array_merge($import_sample,$import_extrafield_sample);
  221. if (! empty($conf->fournisseur->enabled))
  222. {
  223. // Import suppliers prices (note: this code is duplicated into module service)
  224. $r++;
  225. $this->import_code[$r]=$this->rights_class.'_supplierprices';
  226. $this->import_label[$r]="SuppliersPricesOfProductsOrServices"; // Translation key
  227. $this->import_icon[$r]=$this->picto;
  228. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  229. $this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
  230. $this->import_tables_creator_array[$r]=array('sp'=>'fk_user');
  231. $this->import_fields_array[$r]=array('sp.fk_product'=>"ProductOrService*",
  232. 'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate',
  233. 'sp.price'=>"PriceQtyMinHT*",
  234. 'sp.unitprice'=>'UnitPriceHT*', // TODO Make this file not required and calculate it from price and qty
  235. 'sp.remise_percent'=>'DiscountQtyMin'
  236. );
  237. $this->import_convertvalue_array[$r]=array(
  238. 'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
  239. 'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
  240. );
  241. $this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456",
  242. 'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21',
  243. 'sp.price'=>"50",
  244. 'sp.unitprice'=>'50',
  245. 'sp.remise_percent'=>'0'
  246. );
  247. }
  248. if (! empty($conf->global->PRODUIT_MULTIPRICES))
  249. {
  250. // Import product multiprice
  251. $r++;
  252. $this->import_code[$r]=$this->rights_class.'_multiprice';
  253. $this->import_label[$r]="ProductsOrServiceMultiPrice"; // Translation key
  254. $this->import_icon[$r]=$this->picto;
  255. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  256. $this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price');
  257. $this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author'); // Fields to store import user id
  258. $this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*",
  259. 'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
  260. 'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
  261. 'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
  262. 'pr.tva_tx'=>'PriceLevelVATRate',
  263. 'pr.date_price'=>'DateCreation*');
  264. if ($mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR'));
  265. $this->import_regex_array[$r]=array('pr.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','pr.recuperableonly'=>'^[0|1]$');
  266. $this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1",
  267. 'pr.price_base_type'=>"HT",'pr.price_level'=>"1",
  268. 'pr.price'=>"100",'pr.price_ttc'=>"110",
  269. 'pr.price_min'=>"100",'pr.price_min_ttc'=>"110",
  270. 'pr.tva_tx'=>'20',
  271. 'pr.recuperableonly'=>'0',
  272. 'pr.date_price'=>'2013-04-10');
  273. }
  274. if (! empty($conf->global->MAIN_MULTILANGS))
  275. {
  276. $r++;
  277. /* FIXME Must be a dedicated import profil. Not working yet
  278. $this->import_code[$r]=$this->rights_class.'_multiprice';
  279. $this->import_label[$r]="ProductTranslations";
  280. $this->import_icon[$r]=$this->picto;
  281. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  282. $this->import_tables_array[$r]['l']=MAIN_DB_PREFIX.'product_lang';
  283. // multiline translation, one line per translation
  284. $this->import_fields_array[$r]['l.lang']='Language';
  285. $this->import_fields_array[$r]['l.label']='TranslatedLabel';
  286. $this->import_fields_array[$r]['l.description']='TranslatedDescription';
  287. $this->import_fields_array[$r]['l.note']='TranslatedNote';
  288. $this->import_examplevalues_array[$r]['l.lang']='en_US';
  289. */
  290. // single line translation, one column per translation
  291. /*
  292. foreach($langs as $l) {
  293. $this->import_tables_array[$r][$l] = MAIN_DB_PREFIX.'product_lang';
  294. $this->import_fields_array[$r][$l.'.label']=$l.'_label';
  295. $this->import_fields_array[$r][$l.'.description']=$l.'_description';
  296. $this->import_fields_array[$r][$l.'.note']=$l.'_note';
  297. $this->import_fieldshidden_array[$r][$l.'.lang']="'$l'";
  298. $this->import_fieldshidden_array[$r][$l.'.fk_product']='lastrowid-'.MAIN_DB_PREFIX.'product';
  299. }
  300. */
  301. }
  302. }
  303. /**
  304. * Function called when module is enabled.
  305. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  306. * It also creates data directories
  307. *
  308. * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes')
  309. * @return int 1 if OK, 0 if KO
  310. */
  311. function init($options='')
  312. {
  313. $this->remove($options);
  314. $sql = array();
  315. return $this->_init($sql,$options);
  316. }
  317. }