dolibarr  7.0.0-beta
modProduct.class.php
Go to the documentation of this file.
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 
32 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
33 
34 
39 {
45  function __construct($db)
46  {
47  global $conf, $mysoc;
48 
49  $this->db = $db;
50  $this->numero = 50;
51 
52  $this->family = "products";
53  $this->module_position = 20;
54  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
55  $this->name = preg_replace('/^mod/i','',get_class($this));
56  $this->description = "Product management";
57 
58  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
59  $this->version = 'dolibarr';
60 
61  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
62  $this->special = 0;
63  $this->picto='product';
64 
65  // Data directories to create when module is enabled
66  $this->dirs = array("/product/temp");
67 
68  // Dependencies
69  $this->depends = array();
70  $this->requiredby = array("modStock","modBarcode","modProductBatch");
71 
72  // Config pages
73  $this->config_page_url = array("product.php@product");
74  $this->langfiles = array("products","companies","stocks","bills");
75 
76  // Constants
77  $this->const = array();
78  $r=0;
79 
80  $this->const[$r][0] = "PRODUCT_CODEPRODUCT_ADDON";
81  $this->const[$r][1] = "chaine";
82  $this->const[$r][2] = "mod_codeproduct_leopard";
83  $this->const[$r][3] = 'Module to control product codes';
84  $this->const[$r][4] = 0;
85  $r++;
86 
87  /*$this->const[$r][0] = "PRODUCT_ADDON_PDF";
88  $this->const[$r][1] = "chaine";
89  $this->const[$r][2] = "standard";
90  $this->const[$r][3] = 'Default module for document generation';
91  $this->const[$r][4] = 0;
92  $r++;*/
93 
94  // Boxes
95  $this->boxes = array(
96  0=>array('file'=>'box_produits.php','enabledbydefaulton'=>'Home'),
97  1=>array('file'=>'box_produits_alerte_stock.php','enabledbydefaulton'=>''),
98  2=>array('file'=>'box_graph_product_distribution.php','enabledbydefaulton'=>'Home')
99  );
100 
101  // Permissions
102  $this->rights = array();
103  $this->rights_class = 'produit';
104  $r=0;
105 
106  $this->rights[$r][0] = 31; // id de la permission
107  $this->rights[$r][1] = 'Lire les produits'; // libelle de la permission
108  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
109  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
110  $this->rights[$r][4] = 'lire';
111  $r++;
112 
113  $this->rights[$r][0] = 32; // id de la permission
114  $this->rights[$r][1] = 'Creer/modifier les produits'; // libelle de la permission
115  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
116  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
117  $this->rights[$r][4] = 'creer';
118  $r++;
119 
120  $this->rights[$r][0] = 34; // id de la permission
121  $this->rights[$r][1] = 'Supprimer les produits'; // libelle de la permission
122  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
123  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
124  $this->rights[$r][4] = 'supprimer';
125  $r++;
126 
127  $this->rights[$r][0] = 38; // Must be same permission than in service module
128  $this->rights[$r][1] = 'Exporter les produits';
129  $this->rights[$r][2] = 'r';
130  $this->rights[$r][3] = 0;
131  $this->rights[$r][4] = 'export';
132  $r++;
133 
134  // Menus
135  //-------
136 
137  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
138  /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
139  $r=0;
140  $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
141  'type'=>'left', // This is a Left menu entry
142  'titre'=>'ProductVatMassChange',
143  'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=admintools',
144  'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
145  'position'=>300,
146  'enabled'=>'$conf->product->enabled && ($leftmenu=="admintools" || $leftmenu=="admintools_info")', // 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.
147  'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
148  'target'=>'',
149  'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
150  $r++;
151  */
152 
153  // Exports
154  //--------
155  $r=0;
156 
157  $r++;
158  $this->export_code[$r]=$this->rights_class.'_'.$r;
159  $this->export_label[$r]="Products"; // Translation key (used only if key ExportDataset_xxx_z not found)
160  $this->export_permission[$r]=array(array("produit","export"));
161  $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.width'=>"Width",'p.height'=>"Height",'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');
162  if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['p.recuperableonly']='NPR';
163  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'));
164  if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
165  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'=>'BuyingPrice','pf.quantity'=>'QtyMin','pf.remise_percent'=>'DiscountQtyMin'));
166  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'));
167  if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('group_concat(cat.label)'=>'Categories'));
168  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'));
169  if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
170  $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.width'=>"Numeric",'p.height'=>"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');
171  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'));
172  if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
173  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','pf.quantity'=>'Numeric','pf.remise_percent'=>'Numeric'));
174  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'));
175  if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array("group_concat(cat.label)"=>'Text'));
176  $this->export_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
177  if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array("group_concat(cat.label)"=>'category'));
178  if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'product','p.pmp'=>'product'));
179  if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product'));
180  if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'company','pf.ref_fourn'=>'product','pf.unitprice'=>'product'));
181  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'));
182  $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
183  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
184  if (! empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r]=array('category'=>'p.rowid');
185  $this->export_sql_start[$r]='SELECT DISTINCT ';
186  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p';
187  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';
188  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';
189  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
190  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';
191  $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
192  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"
193 
194  if (! empty($conf->global->PRODUIT_MULTIPRICES))
195  {
196  // Exports product multiprice
197  $r++;
198  $this->export_code[$r]=$this->rights_class.'_'.$r;
199  $this->export_label[$r]="ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found)
200  $this->export_permission[$r]=array(array("produit","export"));
201  $this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",
202  'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
203  'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
204  'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
205  'pr.tva_tx'=>'PriceLevelVATRate',
206  'pr.date_price'=>'DateCreation');
207  if (is_object($mysoc) && $mysoc->useNPR()) $this->export_fields_array[$r]['pr.recuperableonly']='NPR';
208  //$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');
209  $this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product",
210  'pr.price_base_type'=>"product",'pr.price_level'=>"product",'pr.price'=>"product",
211  'pr.price_ttc'=>"product",
212  'pr.price_min'=>"product",'pr.price_min_ttc'=>"product",
213  'pr.tva_tx'=>'product',
214  'pr.recuperableonly'=>'product',
215  'pr.date_price'=>"product");
216  $this->export_sql_start[$r]='SELECT DISTINCT ';
217  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p';
218  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product';
219  $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
220  }
221 
222  if (! empty($conf->global->PRODUIT_SOUSPRODUITS))
223  {
224  $r++;
225  $this->export_code[$r]=$this->rights_class.'_'.$r;
226  $this->export_label[$r]="AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found)
227  $this->export_permission[$r]=array(array("produit","export"));
228  $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');
229  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'));
230  if (! empty($conf->barcode->enabled)) $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p.barcode'=>'BarCode'));
231  $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('pa.qty'=>'Qty','pa.incdec'=>'ComposedProductIncDecStock'));
232  $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');
233  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'));
234  if (! empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('p.barcode'=>'Text'));
235  $this->export_TypeFields_array[$r]=array_merge($this->export_TypeFields_array[$r],array('pa.qty'=>'Numeric'));
236  $this->export_entities_array[$r]=array('p.rowid'=>"virtualproduct",'p.ref'=>"virtualproduct",'p.label'=>"virtualproduct",'p.description'=>"virtualproduct",'p.url'=>"virtualproduct",'p.accountancy_code_sell'=>'virtualproduct','p.accountancy_code_buy'=>'virtualproduct','p.note'=>"virtualproduct",'p.length'=>"virtualproduct",'p.surface'=>"virtualproduct",'p.volume'=>"virtualproduct",'p.weight'=>"virtualproduct",'p.customcode'=>'virtualproduct','p.price_base_type'=>"virtualproduct",'p.price'=>"virtualproduct",'p.price_ttc'=>"virtualproduct",'p.tva_tx'=>"virtualproduct",'p.tosell'=>"virtualproduct",'p.tobuy'=>"virtualproduct",'p.datec'=>"virtualproduct",'p.tms'=>"virtualproduct");
237  if (! empty($conf->stock->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.stock'=>'virtualproduct','p.seuil_stock_alerte'=>'virtualproduct','p.desiredstock'=>'virtualproduct','p.pmp'=>'virtualproduct'));
238  if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'virtualproduct'));
239  $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('pa.qty'=>"subproduct",'pa.incdec'=>'subproduct'));
240  $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra';
241  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
242  $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r],array('p2.rowid'=>"Id",'p2.ref'=>"Ref",'p2.label'=>"Label",'p2.description'=>"Description"));
243  $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p2.rowid'=>"subproduct",'p2.ref'=>"subproduct",'p2.label'=>"subproduct",'p2.description'=>"subproduct"));
244  $this->export_sql_start[$r]='SELECT DISTINCT ';
245  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p';
246  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
247  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
248  $this->export_sql_end[$r] .=' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
249  $this->export_sql_end[$r] .=' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
250  }
251 
252  // Imports
253  //--------
254  $r=0;
255 
256  $r++;
257  $this->import_code[$r]=$this->rights_class.'_'.$r;
258  $this->import_label[$r]="Products"; // Translation key
259  $this->import_icon[$r]=$this->picto;
260  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
261  $this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product','extra'=>MAIN_DB_PREFIX.'product_extrafields');
262  $this->import_tables_creator_array[$r]=array('p'=>'fk_user_author'); // Fields to store import user id
263  $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'=>'VATRate', 'p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation');
264  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'));
265  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'));
266  if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.recuperableonly'=>'NPR'));
267  if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type'));
268  if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type'));
269  if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode'));
270  if (! empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
271  // Add extra fields
272  $import_extrafield_sample=array();
273  $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.')';
274  $resql=$this->db->query($sql);
275  if ($resql) // This can fail when class is used on old database (during migration for example)
276  {
277  while ($obj=$this->db->fetch_object($resql))
278  {
279  $fieldname='extra.'.$obj->name;
280  $fieldlabel=ucfirst($obj->label);
281  $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
282  $import_extrafield_sample[$fieldname]=$fieldlabel;
283  }
284  }
285  // End add extra fields
286  $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
287  $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]$');
288  $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');
289  $this->import_examplevalues_array[$r]=array_merge($import_sample,$import_extrafield_sample);
290  $this->import_updatekeys_array[$r]=array('p.ref'=>'Ref','p.barcode'=>'BarCode');
291 
292  if (! empty($conf->fournisseur->enabled))
293  {
294  // Import suppliers prices (note: this code is duplicated into module service)
295  $r++;
296  $this->import_code[$r]=$this->rights_class.'_supplierprices';
297  $this->import_label[$r]="SuppliersPricesOfProductsOrServices"; // Translation key
298  $this->import_icon[$r]=$this->picto;
299  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
300  $this->import_tables_array[$r]=array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
301  $this->import_tables_creator_array[$r]=array('sp'=>'fk_user');
302  $this->import_fields_array[$r]=array('sp.fk_product'=>"ProductOrService*",
303  'sp.fk_soc'=>"Supplier*", 'sp.ref_fourn'=>'SupplierRef', 'sp.quantity'=>"QtyMin*", 'sp.tva_tx'=>'VATRate',
304  'sp.price'=>"PriceQtyMinHT*",
305  'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty
306  'sp.remise_percent'=>'DiscountQtyMin'
307  );
308  if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.recuperableonly'=>'NPR'));
309  if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type'));
310  if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type'));
311  $this->import_convertvalue_array[$r]=array(
312  'sp.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
313  'sp.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
314  );
315  $this->import_examplevalues_array[$r]=array('sp.fk_product'=>"PREF123456",
316  'sp.fk_soc'=>"My Supplier",'sp.ref_fourn'=>"SupplierRef", 'sp.quantity'=>"1", 'sp.tva_tx'=>'21',
317  'sp.price'=>"50",
318  'sp.unitprice'=>'50',
319  'sp.remise_percent'=>'0'
320  );
321  $this->import_updatekeys_array[$r]=array('sp.fk_product'=>'ProductOrService','sp.ref_fourn'=>'SupplierRef');
322  }
323 
324  if (! empty($conf->global->PRODUIT_MULTIPRICES))
325  {
326  // Import product multiprice
327  $r++;
328  $this->import_code[$r]=$this->rights_class.'_multiprice';
329  $this->import_label[$r]="ProductsOrServiceMultiPrice"; // Translation key
330  $this->import_icon[$r]=$this->picto;
331  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
332  $this->import_tables_array[$r]=array('pr'=>MAIN_DB_PREFIX.'product_price');
333  $this->import_tables_creator_array[$r]=array('pr'=>'fk_user_author'); // Fields to store import user id
334  $this->import_fields_array[$r]=array('pr.fk_product'=>"ProductRowid*",
335  'pr.price_base_type'=>"PriceLevelPriceBase",'pr.price_level'=>"PriceLevel",
336  'pr.price'=>"PriceLevelUnitPriceHT",'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
337  'pr.price_min'=>"MinPriceLevelUnitPriceHT",'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
338  'pr.tva_tx'=>'PriceLevelVATRate',
339  'pr.date_price'=>'DateCreation*');
340  if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('pr.recuperableonly'=>'NPR'));
341  $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]$');
342  $this->import_examplevalues_array[$r]=array('pr.fk_product'=>"1",
343  'pr.price_base_type'=>"HT",'pr.price_level'=>"1",
344  'pr.price'=>"100",'pr.price_ttc'=>"110",
345  'pr.price_min'=>"100",'pr.price_min_ttc'=>"110",
346  'pr.tva_tx'=>'20',
347  'pr.recuperableonly'=>'0',
348  'pr.date_price'=>'2013-04-10');
349  }
350 
351  if (! empty($conf->global->MAIN_MULTILANGS))
352  {
353  $r++;
354  $this->import_code[$r]=$this->rights_class.'_languages';
355  $this->import_label[$r]="ProductsOrServicesTranslations";
356  $this->import_icon[$r]=$this->picto;
357  $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
358  $this->import_tables_array[$r]=array('l'=>MAIN_DB_PREFIX.'product_lang');
359  // multiline translation, one line per translation
360  $this->import_fields_array[$r]=array('l.fk_product'=>'Ref', 'l.lang'=>'Language', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
361  //$this->import_fields_array[$r]['l.note']='TranslatedNote';
362  $this->import_convertvalue_array[$r]=array(
363  'l.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'Product')
364  );
365  $this->import_examplevalues_array[$r]=array('l.fk_product'=>'MyProductRef','l.lang'=>'en_US','l.label'=>'Label in en_US','l.description'=>'Desc in en_US');
366  $this->import_updatekeys_array[$r]=array('l.fk_product'=>'Ref','l.lang'=>'Language');
367  }
368  }
369 
370 
379  function init($options='')
380  {
381  $this->remove($options);
382 
383  $sql = array();
384 
385  return $this->_init($sql,$options);
386  }
387 }
Class DolibarrModules.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
init($options='')
Function called when module is enabled.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
Class descriptor of Product module.
__construct($db)
Constructor.
_init($array_sql, $options='')
Enables a module.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013