dolibarr  13.0.2
modService.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2014 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) 2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
30 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
31 
32 
37 {
38 
44  public function __construct($db)
45  {
46  global $conf, $mysoc;
47 
48  $this->db = $db;
49  $this->numero = 53;
50 
51  $this->family = "products";
52  $this->module_position = '29';
53  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54  $this->name = preg_replace('/^mod/i', '', get_class($this));
55  $this->description = "Service management";
56 
57  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
58  $this->version = 'dolibarr';
59 
60  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
61  $this->picto = 'service';
62 
63  // Data directories to create when module is enabled
64  $this->dirs = array("/product/temp");
65 
66  // Dependencies
67  $this->hidden = false; // A condition to hide module
68  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
69  $this->requiredby = array(); // List of module ids to disable if this one is disabled
70  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
71  $this->phpmin = array(5, 4); // Minimum version of PHP required by module
72 
73  // Config pages
74  $this->config_page_url = array("product.php@product");
75  $this->langfiles = array("products", "companies", "stocks", "bills");
76 
77  // Constants
78  $this->const = array();
79 
80  // Boxes
81  $this->boxes = array(
82  0=>array('file'=>'box_services_contracts.php', 'enabledbydefaulton'=>'Home'),
83  1=>array('file'=>'box_graph_product_distribution.php', 'enabledbydefaulton'=>'Home')
84  );
85 
86  // Permissions
87  $this->rights = array();
88  $this->rights_class = 'service';
89  $r = 0;
90 
91  $this->rights[$r][0] = 531; // id de la permission
92  $this->rights[$r][1] = 'Read services'; // libelle de la permission
93  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
94  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
95  $this->rights[$r][4] = 'lire';
96  $r++;
97 
98  $this->rights[$r][0] = 532; // id de la permission
99  $this->rights[$r][1] = 'Create/modify services'; // libelle de la permission
100  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
101  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
102  $this->rights[$r][4] = 'creer';
103  $r++;
104 
105  $this->rights[$r][0] = 534; // id de la permission
106  $this->rights[$r][1] = 'Delete les services'; // libelle de la permission
107  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
108  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
109  $this->rights[$r][4] = 'supprimer';
110  $r++;
111 
112  $this->rights[$r][0] = 538; // Must be same permission than in product module
113  $this->rights[$r][1] = 'Export services';
114  $this->rights[$r][2] = 'r';
115  $this->rights[$r][3] = 0;
116  $this->rights[$r][4] = 'export';
117  $r++;
118 
119  // Menus
120  //-------
121  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
122  /* We can't enable this here because it must be enabled in both product and service module and this creates duplicate inserts
123  $r=0;
124  $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
125  'type'=>'left', // This is a Left menu entry
126  'titre'=>'ProductVatMassChange',
127  'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=admintools',
128  'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
129  'position'=>300,
130  '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.
131  'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
132  'target'=>'',
133  'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
134  $r++;
135  */
136 
137  $usenpr = 0;
138  if (is_object($mysoc)) $usenpr = $mysoc->useNPR();
139 
140  // Exports
141  //--------
142  $r = 0;
143 
144  $r++;
145  $this->export_code[$r] = $this->rights_class.'_'.$r;
146  $this->export_label[$r] = "Services"; // Translation key (used only if key ExportDataset_xxx_z not found)
147  $this->export_permission[$r] = array(array("service", "export"));
148  $this->export_fields_array[$r] = array(
149  'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label",
150  'p.fk_product_type'=>'Type', 'p.tosell'=>"OnSell", 'p.tobuy'=>"OnBuy",
151  'p.description'=>"Description", 'p.url'=>"PublicUrl",
152  'p.customcode'=>'CustomCode', 'p.fk_country'=>'IDCountry',
153  'p.accountancy_code_sell'=>"ProductAccountancySellCode", 'p.accountancy_code_sell_intra'=>"ProductAccountancySellIntraCode",
154  'p.accountancy_code_sell_export'=>"ProductAccountancySellExportCode", 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",
155  'p.accountancy_code_buy_intra'=>"ProductAccountancyBuyIntraCode", 'p.accountancy_code_buy_export'=>"ProductAccountancyBuyExportCode",
156  'p.note'=>"NotePrivate", 'p.note_public'=>'NotePublic',
157  'p.weight'=>"Weight", 'p.length'=>"Length", 'p.width'=>"Width", 'p.height'=>"Height", 'p.surface'=>"Surface", 'p.volume'=>"Volume",
158  'p.duration'=>"Duration",
159  'p.finished' => 'Nature',
160  'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC",
161  'p.tva_tx'=>'VATRate',
162  'p.datec'=>'DateCreation', 'p.tms'=>'DateModification'
163  );
164  if (is_object($mysoc) && $usenpr) $this->export_fields_array[$r]['p.recuperableonly'] = 'NPR';
165  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'));
166  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'));
167  if (!empty($conf->barcode->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode'));
168  $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra';
169  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
170  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'));
171  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('group_concat(cat.label)'=>'Categories'));
172  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'));
173  if (!empty($conf->global->PRODUCT_USE_UNITS)) $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
174  $this->export_TypeFields_array[$r] = array(
175  'p.ref'=>"Text", 'p.label'=>"Text",
176  'p.fk_product_type'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean",
177  'p.description'=>"Text", 'p.url'=>"Text", 'p.accountancy_code_sell'=>"Text",
178  'p.accountancy_code_sell_intra'=>"Text", 'p.accountancy_code_sell_export'=>"Text", 'p.accountancy_code_buy'=>"Text",
179  'p.accountancy_code_buy_intra'=>"Text", 'p.accountancy_code_buy_export'=>"Text",
180  'p.note'=>"Text", 'p.note_public'=>"Text",
181  'p.weight'=>"Numeric", 'p.length'=>"Numeric", 'p.width'=>"Numeric", 'p.height'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric",
182  'p.customcode'=>'Text',
183  'p.duration'=>"Text",
184  'p.finished' => 'Numeric',
185  'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric", 'p.tva_tx'=>'Numeric',
186  'p.datec'=>'Date', 'p.tms'=>'Date'
187  );
188  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'));
189  if (!empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text'));
190  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'));
191  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'));
192  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array("group_concat(cat.label)"=>'Text'));
193  $this->export_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
194  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array("group_concat(cat.label)"=>'category'));
195  if (!empty($conf->stock->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'product', 'p.pmp'=>'product'));
196  if (!empty($conf->barcode->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'product'));
197  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'));
198  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'));
199  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r] = array('category'=>'p.rowid');
200  if (!empty($conf->stock->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'product', 'p.pmp'=>'product'));
201  if (!empty($conf->barcode->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'product'));
202  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'));
203  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'));
204  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) $this->export_dependencies_array[$r] = array('category'=>'p.rowid');
205  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
206  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
207  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';
208  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';
209  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
210  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';
211  $this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 1 AND p.entity IN ('.getEntity('product').')';
212  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"
213 
214  if (empty($conf->product->enabled)) // We enable next import templates only if module product not already enabled (to avoid duplicate entries)
215  {
216  if (!empty($conf->global->PRODUIT_MULTIPRICES))
217  {
218  // Exports product multiprice
219  $r++;
220  $this->export_code[$r] = $this->rights_class.'_'.$r;
221  $this->export_label[$r] = "ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found)
222  $this->export_permission[$r] = array(array("produit", "export"));
223  $this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref",
224  'pr.price_base_type'=>"PriceBase", 'pr.price_level'=>"PriceLevel",
225  'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
226  'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
227  'pr.tva_tx'=>'PriceLevelVATRate',
228  'pr.date_price'=>'DateCreation');
229  if (is_object($mysoc) && $usenpr) $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
230  //$this->export_TypeFields_array[$r]=array(
231  // 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
232  // 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
233  // 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
234  // 'p.datec'=>'Date','p.tms'=>'Date'
235  //);
236  $this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product",
237  'pr.price_base_type'=>"product", 'pr.price_level'=>"product", 'pr.price'=>"product",
238  'pr.price_ttc'=>"product",
239  'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product",
240  'pr.tva_tx'=>'product',
241  'pr.recuperableonly'=>'product',
242  'pr.date_price'=>"product");
243  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
244  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
245  $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
246  $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
247  }
248 
249  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES))
250  {
251  // Exports product multiprice
252  $r++;
253  $this->export_code[$r] = $this->rights_class.'_'.$r;
254  $this->export_label[$r] = "ProductsPricePerCustomer"; // Translation key (used only if key ExportDataset_xxx_z not found)
255  $this->export_permission[$r] = array(array("produit", "export"));
256  $this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref",
257  's.nom'=>'ThirdParty',
258  'pr.price_base_type'=>"PriceBase",
259  'pr.price'=>"PriceUnitPriceHT", 'pr.price_ttc'=>"PriceUnitPriceTTC",
260  'pr.price_min'=>"MinPriceUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceUnitPriceTTC",
261  'pr.tva_tx'=>'PriceVATRate',
262  'pr.default_vat_code'=>'PriceVATCode',
263  'pr.datec'=>'DateCreation');
264  if (is_object($mysoc) && $usenpr) $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
265  $this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product",
266  's.nom'=>'company',
267  'pr.price_base_type'=>"product", 'pr.price'=>"product",
268  'pr.price_ttc'=>"product",
269  'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product",
270  'pr.tva_tx'=>'product',
271  'pr.default_vat_code'=>'product',
272  'pr.recuperableonly'=>'product',
273  'pr.datec'=>"product");
274  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
275  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
276  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_customer_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.$conf->entity; // export prices only for the current entity
277  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON pr.fk_soc = s.rowid';
278  $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
279  }
280 
281  if (!empty($conf->global->PRODUIT_SOUSPRODUITS))
282  {
283  // Exports virtual products
284  $r++;
285  $this->export_code[$r] = $this->rights_class.'_'.$r;
286  $this->export_label[$r] = "AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found)
287  $this->export_permission[$r] = array(array("produit", "export"));
288  $this->export_fields_array[$r] = array(
289  'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label", 'p.description'=>"Description", 'p.url'=>"PublicUrl",
290  'p.accountancy_code_sell'=>"ProductAccountancySellCode", 'p.accountancy_code_sell_intra'=>"ProductAccountancySellIntraCode",
291  'p.accountancy_code_sell_export'=>"ProductAccountancySellExportCode", 'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",
292  'p.accountancy_code_buy_intra'=>"ProductAccountancyBuyIntraCode", 'p.accountancy_code_buy_export'=>"ProductAccountancyBuyExportCode",
293  'p.note'=>"NotePrivate", 'p.note_public'=>'NotePublic',
294  'p.weight'=>"Weight", 'p.length'=>"Length", 'p.surface'=>"Surface", 'p.volume'=>"Volume", 'p.customcode'=>'CustomCode',
295  'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC", 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell",
296  'p.tobuy'=>"OnBuy", 'p.datec'=>'DateCreation', 'p.tms'=>'DateModification'
297  );
298  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'));
299  if (!empty($conf->barcode->enabled)) $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode'));
300  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('pa.qty'=>'Qty', 'pa.incdec'=>'ComposedProductIncDecStock'));
301  $this->export_TypeFields_array[$r] = array(
302  'p.ref'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.url'=>"Text",
303  'p.accountancy_code_sell'=>"Text", 'p.accountancy_code_sell_intra'=>"Text", 'p.accountancy_code_sell_export'=>"Text",
304  'p.accountancy_code_buy'=>"Text", 'p.accountancy_code_buy_intra'=>"Text", 'p.accountancy_code_buy_export'=>"Text",
305  'p.note'=>"Text", 'p.note_public'=>"Text",
306  'p.weight'=>"Numeric", 'p.length'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric", 'p.customcode'=>'Text',
307  'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric", 'p.tva_tx'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean",
308  'p.datec'=>'Date', 'p.tms'=>'Date'
309  );
310  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'));
311  if (!empty($conf->barcode->enabled)) $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text'));
312  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('pa.qty'=>'Numeric'));
313  $this->export_entities_array[$r] = array(
314  'p.rowid'=>"virtualproduct", 'p.ref'=>"virtualproduct", 'p.label'=>"virtualproduct", 'p.description'=>"virtualproduct", 'p.url'=>"virtualproduct",
315  'p.accountancy_code_sell'=>'virtualproduct', 'p.accountancy_code_sell_intra'=>'virtualproduct', 'p.accountancy_code_sell_export'=>'virtualproduct',
316  'p.accountancy_code_buy'=>'virtualproduct', 'p.accountancy_code_buy_intra'=>'virtualproduct', 'p.accountancy_code_buy_export'=>'virtualproduct',
317  'p.note'=>"virtualproduct", 'p.length'=>"virtualproduct",
318  'p.surface'=>"virtualproduct", 'p.volume'=>"virtualproduct", 'p.weight'=>"virtualproduct", 'p.customcode'=>'virtualproduct',
319  'p.price_base_type'=>"virtualproduct", 'p.price'=>"virtualproduct", 'p.price_ttc'=>"virtualproduct", 'p.tva_tx'=>"virtualproduct",
320  'p.tosell'=>"virtualproduct", 'p.tobuy'=>"virtualproduct", 'p.datec'=>"virtualproduct", 'p.tms'=>"virtualproduct"
321  );
322  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'));
323  if (!empty($conf->barcode->enabled)) $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'virtualproduct'));
324  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('pa.qty'=>"subproduct", 'pa.incdec'=>'subproduct'));
325  $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra';
326  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
327  $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"));
328  $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"));
329  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
330  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
331  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
332  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
333  $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
334  $this->export_sql_end[$r] .= ' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
335  }
336  }
337 
338  // Imports
339  //--------
340  $r = 0;
341 
342  // Import list of services
343 
344  $r++;
345  $this->import_code[$r] = $this->rights_class.'_'.$r;
346  $this->import_label[$r] = "Products"; // Translation key
347  $this->import_icon[$r] = $this->picto;
348  $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
349  $this->import_tables_array[$r] = array('p'=>MAIN_DB_PREFIX.'product', 'extra'=>MAIN_DB_PREFIX.'product_extrafields');
350  $this->import_tables_creator_array[$r] = array('p'=>'fk_user_author'); // Fields to store import user id
351  $this->import_fields_array[$r] = array(
352  'p.ref' => "Ref*",
353  'p.label' => "Label*",
354  'p.fk_product_type' => "Type*",
355  'p.tosell' => "OnSell*",
356  'p.tobuy' => "OnBuy*",
357  'p.description' => "Description",
358  'p.url' => "PublicUrl",
359  'p.customcode' => 'CustomCode',
360  'p.fk_country' => 'CountryCode',
361  'p.accountancy_code_sell' => "ProductAccountancySellCode",
362  'p.accountancy_code_sell_intra' => "ProductAccountancySellIntraCode",
363  'p.accountancy_code_sell_export' => "ProductAccountancySellExportCode",
364  'p.accountancy_code_buy' => "ProductAccountancyBuyCode",
365  'p.accountancy_code_buy_intra' => "ProductAccountancyBuyIntraCode",
366  'p.accountancy_code_buy_export' => "ProductAccountancyBuyExportCode",
367  'p.note_public' => "NotePublic",
368  'p.note' => "NotePrivate",
369  'p.weight' => "Weight",
370  'p.weight_units' => "WeightUnits",
371  'p.length' => "Length",
372  'p.length_units' => "LengthUnit",
373  'p.width' => "Width",
374  'p.width_units' => "WidthUnits",
375  'p.height' => "Height",
376  'p.height_units' => "HeightUnit",
377  'p.surface' => "Surface",
378  'p.surface_units' => "SurfaceUnit",
379  'p.volume' => "Volume",
380  'p.volume_units' => "VolumeUnits",
381  'p.duration' => "Duration", //duration of service
382  'p.finished' => 'Nature',
383  'p.price' => "SellingPriceHT", //without
384  'p.price_min' => "MinPrice",
385  'p.price_ttc' => "SellingPriceTTC", //with tax
386  'p.price_min_ttc' => "SellingMinPriceTTC",
387  'p.price_base_type' => "PriceBaseType", //price base: with-tax (TTC) or without (HT) tax. Displays accordingly in Product card
388  'p.tva_tx' => 'VATRate',
389  'p.datec' => 'DateCreation',
390  'p.cost_price' => "CostPrice",
391  );
392  if (!empty($conf->stock->enabled)) {//if Stock module enabled
393  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
394  'p.seuil_stock_alerte' => 'StockLimit', //lower limit for warning
395  'p.pmp' => 'PMPValue', //weighted average price
396  'p.desiredstock' => 'DesiredStock'//desired stock for replenishment feature
397  ));
398  }
399 
400  $this->import_convertvalue_array[$r] = array(
401  'p.weight_units' => array(
402  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
403  'classfile' => '/core/class/cunits.class.php',
404  'class' => 'CUnits',
405  'method' => 'fetch',
406  'units' => 'weight',
407  'dict' => 'DictionaryMeasuringUnits'
408  ),
409  'p.length_units' => array(
410  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
411  'classfile' => '/core/class/cunits.class.php',
412  'class' => 'CUnits',
413  'method' => 'fetch',
414  'units' => 'size',
415  'dict' => 'DictionaryMeasuringUnits'
416  ),
417  'p.width_units' => array(
418  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
419  'classfile' => '/core/class/cunits.class.php',
420  'class' => 'CUnits',
421  'method' => 'fetch',
422  'units' => 'size',
423  'dict' => 'DictionaryMeasuringUnits'
424  ),
425  'p.height_units' => array(
426  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
427  'classfile' => '/core/class/cunits.class.php',
428  'class' => 'CUnits',
429  'method' => 'fetch',
430  'units' => 'size',
431  'dict' => 'DictionaryMeasuringUnits'
432  ),
433  'p.surface_units' => array(
434  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
435  'classfile' => '/core/class/cunits.class.php',
436  'class' => 'CUnits',
437  'method' => 'fetch',
438  'units' => 'surface',
439  'dict' => 'DictionaryMeasuringUnits'
440  ),
441  'p.volume_units' => array(
442  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
443  'classfile' => '/core/class/cunits.class.php',
444  'class' => 'CUnits',
445  'method' => 'fetch',
446  'units' => 'volume',
447  'dict' => 'DictionaryMeasuringUnits'
448  ),
449  'p.fk_country' => array(
450  'rule' => 'fetchidfromcodeid',
451  'classfile' => '/core/class/ccountry.class.php',
452  'class' => 'Ccountry',
453  'method' => 'fetch',
454  'dict' => 'DictionaryCountry'
455  )
456  );
457  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'));
458  if (is_object($mysoc) && $usenpr) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.recuperableonly'=>'NPR'));
459  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'));
460  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'));
461  if (!empty($conf->barcode->enabled)) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.barcode'=>'BarCode'));
462  if (!empty($conf->global->PRODUCT_USE_UNITS)) $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
463  // Add extra fields
464  $import_extrafield_sample = array();
465  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0,".$conf->entity.")";
466  $resql = $this->db->query($sql);
467  if ($resql) // This can fail when class is used on old database (during migration for example)
468  {
469  while ($obj = $this->db->fetch_object($resql))
470  {
471  $fieldname = 'extra.'.$obj->name;
472  $fieldlabel = ucfirst($obj->label);
473  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
474  $import_extrafield_sample[$fieldname] = $fieldlabel;
475  }
476  }
477  // End add extra fields
478  $this->import_fieldshidden_array[$r] = array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
479  $this->import_regex_array[$r] = array(
480  'p.ref'=>'[^ ]',
481  'p.price_base_type' => '\AHT\z|\ATTC\z',
482  'p.tosell'=>'^[0|1]$',
483  'p.tobuy'=>'^[0|1]$',
484  'p.fk_product_type'=>'^[0|1]$',
485  'p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
486  'p.recuperableonly' => '^[0|1]$',
487  'p.finished' => '^[0|1]$'
488  );
489  // field order as per structure of table llx_product
490  $import_sample = array(
491  'p.ref' => "PREF123456",
492  'p.datec' => dol_print_date(dol_now(), '%Y-%m-%d'),
493  'p.label' => "Product name in default language",
494  'p.description' => "Product description in default language",
495  'p.note_public' => "a public note (free text)",
496  'p.note' => "a private note (free text)",
497  'p.customcode' => 'customs code',
498  'p.fk_country' => 'FR',
499  'p.price' => "100",
500  'p.price_min' => "100",
501  'p.price_ttc' => "110",
502  'p.price_min_ttc' => "110",
503  'p.price_base_type' => "HT (show/use price excl. tax) / TTC (show/use price incl. tax)",
504  'p.tva_tx' => '10', // tax rate eg: 10. Must match numerically one of the tax rates defined for your country'
505  'p.tosell' => "0 (not for sale to customer, eg. raw material) / 1 (for sale)",
506  'p.tobuy' => "0 (not for purchase from supplier, eg. virtual product) / 1 (for purchase)",
507  'p.fk_product_type' => "0 (product) / 1 (service)",
508  'p.duration' => "eg. 365d/12m/1y",
509  'p.url' => 'link to product (no https)',
510  'p.accountancy_code_sell' => "",
511  'p.accountancy_code_sell_intra' => "",
512  'p.accountancy_code_sell_export' => "",
513  'p.accountancy_code_buy' => "",
514  'p.accountancy_code_buy_intra' => "",
515  'p.accountancy_code_buy_export' => "",
516  'p.weight' => "",
517  'p.weight_units' => 'kg', // Use a unit of measure from the dictionary. g/Kg/T etc....matches field "Short label" for unit type "weight" in table "' . MAIN_DB_PREFIX . 'c_units',
518  'p.length' => "",
519  'p.length_units' => 'm', // Use a unit of measure from the dictionary. m/cm/mm etc....matches field "Short label" for unit type "size" in table "' . MAIN_DB_PREFIX . 'c_units',
520  'p.width' => "",
521  'p.width_units' => 'm', // Use a unit of measure from the dictionary. m/cm/mm etc....matches field "Short label" for unit type "size" in table "' . MAIN_DB_PREFIX . 'c_units',
522  'p.height' => "",
523  'p.height_units' => 'm', // Use a unit of measure from the dictionary. m/cm/mm etc....matches field "Short label" for unit type "size" in table "' . MAIN_DB_PREFIX . 'c_units',
524  'p.surface' => "",
525  'p.surface_units' => 'm2', // Use a unit of measure from the dictionary. m2/cm2/mm2 etc....matches field "Short label" for unit type "surface" in table "' . MAIN_DB_PREFIX . 'c_units',
526  'p.volume' => "",
527  'p.volume_units' => 'm3', //Use a unit of measure from the dictionary. m3/cm3/mm3 etc....matches field "Short label" for unit type "volume" in table "' . MAIN_DB_PREFIX . 'c_units',
528  'p.finished' => '0 (raw material) / 1 (finished goods)'
529  );
530  //clauses copied from import_fields_array
531  if (!empty($conf->stock->enabled)) $import_sample = array_merge($import_sample, array(
532  'p.seuil_stock_alerte' => '',
533  'p.pmp' => '0',
534  'p.desiredstock' => ''
535  ));
536  if (!empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $import_sample = array_merge($import_sample, array('p.cost_price'=>'90'));
537  if (is_object($mysoc) && $usenpr) $import_sample = array_merge($import_sample, array('p.recuperableonly'=>'0'));
538  if (is_object($mysoc) && $mysoc->useLocalTax(1)) $import_sample = array_merge($import_sample, array('p.localtax1_tx'=>'', 'p.localtax1_type'=>''));
539  if (is_object($mysoc) && $mysoc->useLocalTax(2)) $import_sample = array_merge($import_sample, array('p.localtax2_tx'=>'', 'p.localtax2_type'=>''));
540  if (!empty($conf->barcode->enabled)) $import_sample = array_merge($import_sample, array('p.barcode'=>''));
541  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
542  $import_sample = array_merge(
543  $import_sample,
544  array(
545  'p.fk_unit' => 'use a unit of measure from the dictionary. G/KG/M2/M3 etc....matches field "code" in table "'.MAIN_DB_PREFIX.'c_units"'
546  )
547  );
548 
549  if (!is_array($this->import_convertvalue_array[$r])) $this->import_convertvalue_array[$r] = array();
550  $this->import_convertvalue_array[$r] = array_merge($this->import_convertvalue_array[$r], array(
551  'p.fk_unit' => array(
552  'rule' => 'fetchidfromcodeorlabel',
553  'classfile' => '/core/class/cunits.class.php',
554  'class' => 'CUnits',
555  'method' => 'fetch',
556  'dict' => 'DictionaryUnits'
557  )
558  ));
559  }
560  $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
561  $this->import_updatekeys_array[$r] = array('p.ref'=>'Ref');
562  if (!empty($conf->barcode->enabled)) $this->import_updatekeys_array[$r] = array_merge($this->import_updatekeys_array[$r], array('p.barcode'=>'BarCode')); //only show/allow barcode as update key if Barcode module enabled
563 
564  if (empty($conf->product->enabled)) // We enable next import templates only if module product not already enabled (to avoid duplicate entries)
565  {
566  if (!empty($conf->fournisseur->enabled))
567  {
568  // Import suppliers prices (note: this code is duplicated in module Service)
569  $r++;
570  $this->import_code[$r] = $this->rights_class.'_supplierprices';
571  $this->import_label[$r] = "SuppliersPricesOfProductsOrServices"; // Translation key
572  $this->import_icon[$r] = $this->picto;
573  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
574  $this->import_tables_array[$r] = array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
575  $this->import_tables_creator_array[$r] = array('sp'=>'fk_user');
576  $this->import_fields_array[$r] = array(//field order as per structure of table llx_product_fournisseur_price, without optional fields
577  'sp.fk_product'=>"ProductOrService*",
578  'sp.fk_soc' => "Supplier*",
579  'sp.ref_fourn' => 'SupplierRef*',
580  'sp.quantity' => "QtyMin*",
581  'sp.tva_tx' => 'VATRate',
582  'sp.default_vat_code' => 'VATCode',
583  'sp.delivery_time_days' => 'DeliveryDelay',
584  'sp.supplier_reputation' => 'SupplierReputation'
585  );
586  if (is_object($mysoc) && $usenpr) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.recuperableonly'=>'VATNPR'));
587  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'));
588  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'));
589  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
590  'sp.price'=>"PriceQtyMinHT*",
591  'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty
592  'sp.remise_percent'=>'DiscountQtyMin'
593  ));
594 
595  if (!empty($conf->multicurrency->enabled))
596  {
597  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
598  'sp.fk_multicurrency'=>'CurrencyCodeId', //ideally this should be automatically obtained from the CurrencyCode on the next line
599  'sp.multicurrency_code'=>'CurrencyCode',
600  'sp.multicurrency_tx'=>'CurrencyRate',
601  'sp.multicurrency_unitprice'=>'CurrencyUnitPrice',
602  'sp.multicurrency_price'=>'CurrencyPrice',
603  ));
604  }
605 
606  $this->import_convertvalue_array[$r] = array(
607  'sp.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'),
608  'sp.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
609  );
610  $this->import_examplevalues_array[$r] = array(
611  'sp.fk_product' => "PRODUCT_REF or id:123456",
612  'sp.fk_soc' => "My Supplier",
613  'sp.ref_fourn' => "XYZ-F123456",
614  'sp.quantity' => "5",
615  'sp.tva_tx' => '10',
616  'sp.price'=>"50",
617  'sp.unitprice'=>'50',
618  'sp.remise_percent'=>'0',
619  'sp.default_vat_code' => '',
620  'sp.delivery_time_days' => '5',
621  'sp.supplier_reputation' => 'FAVORITE / NOTTHGOOD / DONOTORDER'
622  );
623  if (is_object($mysoc) && $usenpr) $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.recuperableonly'=>''));
624  if (is_object($mysoc) && $mysoc->useLocalTax(1)) $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type'));
625  if (is_object($mysoc) && $mysoc->useLocalTax(2)) $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type'));
626  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
627  'sp.price' => "50.00",
628  'sp.unitprice' => '10',
629  // TODO Make this field not required and calculate it from price and qty
630  'sp.remise_percent' => '20'
631  ));
632  if (!empty($conf->multicurrency->enabled))
633  {
634  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
635  'sp.fk_multicurrency'=>'eg: 2, rowid for code of multicurrency currency',
636  'sp.multicurrency_code'=>'GBP',
637  'sp.multicurrency_tx'=>'1.12345',
638  'sp.multicurrency_unitprice'=>'',
639  // TODO Make this field not required and calculate it from price and qty
640  'sp.multicurrency_price'=>''
641  ));
642  }
643 
644  $this->import_updatekeys_array[$r] = array('sp.fk_product'=>'ProductOrService', 'sp.ref_fourn'=>'SupplierRef', 'sp.fk_soc'=>'Supplier');
645  }
646 
647  if (!empty($conf->global->PRODUIT_MULTIPRICES))
648  {
649  // Import products multiprices
650  $r++;
651  $this->import_code[$r] = $this->rights_class.'_multiprice';
652  $this->import_label[$r] = "ProductsOrServiceMultiPrice"; // Translation key
653  $this->import_icon[$r] = $this->picto;
654  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
655  $this->import_tables_array[$r] = array('pr'=>MAIN_DB_PREFIX.'product_price');
656  $this->import_tables_creator_array[$r] = array('pr'=>'fk_user_author'); // Fields to store import user id
657  $this->import_fields_array[$r] = array('pr.fk_product'=>"ProductOrService*",
658  'pr.price_base_type'=>"PriceBase", 'pr.price_level'=>"PriceLevel",
659  'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
660  'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
661  'pr.date_price'=>'DateCreation*');
662  if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) $this->import_fields_array[$r]['pr.tva_tx'] = 'VATRate';
663  if (is_object($mysoc) && $usenpr) $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('pr.recuperableonly'=>'NPR'));
664  $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]$');
665  $this->import_convertvalue_array[$r] = array(
666  'pr.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
667  );
668  $this->import_examplevalues_array[$r] = array('pr.fk_product'=>"SERVICE_REF or id:123456",
669  'pr.price_base_type'=>"HT (for excl tax) or TTC (for inc tax)", 'pr.price_level'=>"1",
670  'pr.price'=>"100", 'pr.price_ttc'=>"110",
671  'pr.price_min'=>"100", 'pr.price_min_ttc'=>"110",
672  'pr.tva_tx'=>'20',
673  'pr.recuperableonly'=>'0',
674  'pr.date_price'=>'2013-04-10');
675  }
676 
677  if (!empty($conf->global->MAIN_MULTILANGS))
678  {
679  // Import translations of product names and descriptions
680  $r++;
681  $this->import_code[$r] = $this->rights_class.'_languages';
682  $this->import_label[$r] = "ProductsOrServicesTranslations";
683  $this->import_icon[$r] = $this->picto;
684  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
685  $this->import_tables_array[$r] = array('l'=>MAIN_DB_PREFIX.'product_lang');
686  // multiline translation, one line per translation
687  $this->import_fields_array[$r] = array('l.fk_product'=>'ProductOrService*', 'l.lang'=>'Language*', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
688  //$this->import_fields_array[$r]['l.note']='TranslatedNote';
689  $this->import_convertvalue_array[$r] = array(
690  'l.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
691  );
692  $this->import_examplevalues_array[$r] = array('l.fk_product'=>'SERVICE_REF or id:123456', 'l.lang'=>'en_US', 'l.label'=>'Label in en_US', 'l.description'=>'Desc in en_US');
693  $this->import_updatekeys_array[$r] = array('l.fk_product'=>'ProductOrService', 'l.lang'=>'Language');
694  }
695  }
696  }
697 
698 
707  public function init($options = '')
708  {
709  $this->remove($options);
710 
711  $sql = array();
712 
713  return $this->_init($sql, $options);
714  }
715 }
Class DolibarrModules.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</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:750
dol_now($mode= 'auto')
Return date for now.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
Class to describe and enable module Service.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
_init($array_sql, $options= '')
Enables a module.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
init($options= '')
Function called when module is enabled.
__construct($db)
Constructor.