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