dolibarr  16.0.5
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-2021 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, 6); // 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)) {
139  $usenpr = $mysoc->useNPR();
140  }
141 
142  // Exports
143  //--------
144  $r = 0;
145 
146  $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p" : "ppe";
147 
148  $r++;
149  $this->export_code[$r] = $this->rights_class.'_'.$r;
150  $this->export_label[$r] = "Services"; // Translation key (used only if key ExportDataset_xxx_z not found)
151  $this->export_permission[$r] = array(array("service", "export"));
152  $this->export_fields_array[$r] = array(
153  'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label",
154  'p.fk_product_type'=>'Type', 'p.tosell'=>"OnSell", 'p.tobuy'=>"OnBuy",
155  'p.description'=>"Description", 'p.url'=>"PublicUrl",
156  'p.customcode'=>'CustomCode', 'p.fk_country'=>'IDCountry',
157  $alias_product_perentity . '.accountancy_code_sell'=>"ProductAccountancySellCode", $alias_product_perentity . '.accountancy_code_sell_intra'=>"ProductAccountancySellIntraCode",
158  $alias_product_perentity . '.accountancy_code_sell_export'=>"ProductAccountancySellExportCode", $alias_product_perentity . '.accountancy_code_buy'=>"ProductAccountancyBuyCode",
159  $alias_product_perentity . '.accountancy_code_buy_intra'=>"ProductAccountancyBuyIntraCode", $alias_product_perentity . '.accountancy_code_buy_export'=>"ProductAccountancyBuyExportCode",
160  'p.note'=>"NotePrivate", 'p.note_public'=>'NotePublic',
161  'p.weight'=>"Weight", 'p.length'=>"Length", 'p.width'=>"Width", 'p.height'=>"Height", 'p.surface'=>"Surface", 'p.volume'=>"Volume",
162  'p.duration'=>"Duration",
163  'p.finished' => 'Nature',
164  'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC",
165  'p.tva_tx'=>'VATRate',
166  'p.datec'=>'DateCreation', 'p.tms'=>'DateModification'
167  );
168  if (is_object($mysoc) && $usenpr) {
169  $this->export_fields_array[$r]['p.recuperableonly'] = 'NPR';
170  }
171  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled) || !empty($conf->margin->enabled)) {
172  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.cost_price'=>'CostPrice'));
173  }
174  if (!empty($conf->stock->enabled)) {
175  $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'));
176  }
177  if (!empty($conf->barcode->enabled)) {
178  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode'));
179  }
180  $keyforselect = 'product';
181  $keyforelement = 'product';
182  $keyforaliasextra = 'extra';
183  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
184  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
185  $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'));
186  }
187  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
188  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('group_concat(cat.label)'=>'Categories'));
189  }
190  if (!empty($conf->global->MAIN_MULTILANGS)) {
191  $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'));
192  }
193  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
194  $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
195  }
196  $this->export_TypeFields_array[$r] = array(
197  'p.ref'=>"Text", 'p.label'=>"Text",
198  'p.fk_product_type'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean",
199  'p.description'=>"Text", 'p.url'=>"Text",
200  $alias_product_perentity . '.accountancy_code_sell'=>"Text", $alias_product_perentity . '.accountancy_code_sell_intra'=>"Text", $alias_product_perentity . '.accountancy_code_sell_export'=>"Text",
201  $alias_product_perentity . '.accountancy_code_buy'=>"Text", $alias_product_perentity . '.accountancy_code_buy_intra'=>"Text", $alias_product_perentity . '.accountancy_code_buy_export'=>"Text",
202  'p.note'=>"Text", 'p.note_public'=>"Text",
203  'p.weight'=>"Numeric", 'p.length'=>"Numeric", 'p.width'=>"Numeric", 'p.height'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric",
204  'p.customcode'=>'Text',
205  'p.duration'=>"Text",
206  'p.finished' => 'Numeric',
207  'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric", 'p.tva_tx'=>'Numeric',
208  'p.datec'=>'Date', 'p.tms'=>'Date'
209  );
210  if (!empty($conf->stock->enabled)) {
211  $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'));
212  }
213  if (!empty($conf->barcode->enabled)) {
214  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text'));
215  }
216  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
217  $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'));
218  }
219  if (!empty($conf->global->MAIN_MULTILANGS)) {
220  $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'));
221  }
222  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
223  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array("group_concat(cat.label)"=>'Text'));
224  }
225  $this->export_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
226  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
227  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array("group_concat(cat.label)"=>'category'));
228  }
229  if (!empty($conf->stock->enabled)) {
230  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'product', 'p.pmp'=>'product'));
231  }
232  if (!empty($conf->barcode->enabled)) {
233  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'product'));
234  }
235  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
236  $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'));
237  }
238  if (!empty($conf->global->MAIN_MULTILANGS)) {
239  $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'));
240  }
241  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
242  $this->export_dependencies_array[$r] = array('category'=>'p.rowid');
243  }
244  if (!empty($conf->stock->enabled)) {
245  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'product', 'p.pmp'=>'product'));
246  }
247  if (!empty($conf->barcode->enabled)) {
248  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'product'));
249  }
250  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
251  $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'));
252  }
253  if (!empty($conf->global->MAIN_MULTILANGS)) {
254  $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'));
255  }
256  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
257  $this->export_dependencies_array[$r] = array('category'=>'p.rowid');
258  }
259  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
260  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
261  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
262  $this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
263  }
264  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
265  $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';
266  }
267  if (!empty($conf->global->MAIN_MULTILANGS)) {
268  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
269  }
270  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
271  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
272  $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';
273  }
274  $this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 1 AND p.entity IN ('.getEntity('product').')';
275  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
276  $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"
277  }
278 
279  if (empty($conf->product->enabled)) { // We enable next import templates only if module product not already enabled (to avoid duplicate entries)
280  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
281  // Exports product multiprice
282  $r++;
283  $this->export_code[$r] = $this->rights_class.'_'.$r;
284  $this->export_label[$r] = "ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found)
285  $this->export_permission[$r] = array(array("service", "export"));
286  $this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref",
287  'pr.price_base_type'=>"PriceBase", 'pr.price_level'=>"PriceLevel",
288  'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
289  'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
290  'pr.tva_tx'=>'PriceLevelVATRate',
291  'pr.date_price'=>'DateCreation');
292  if (is_object($mysoc) && $usenpr) {
293  $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
294  }
295  //$this->export_TypeFields_array[$r]=array(
296  // 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
297  // 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
298  // 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
299  // 'p.datec'=>'Date','p.tms'=>'Date'
300  //);
301  $this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product",
302  'pr.price_base_type'=>"product", 'pr.price_level'=>"product", 'pr.price'=>"product",
303  'pr.price_ttc'=>"product",
304  'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product",
305  'pr.tva_tx'=>'product',
306  'pr.recuperableonly'=>'product',
307  'pr.date_price'=>"product");
308  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
309  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
310  $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
311  $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
312  }
313 
314  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
315  // Exports product multiprice
316  $r++;
317  $this->export_code[$r] = $this->rights_class.'_'.$r;
318  $this->export_label[$r] = "ProductsPricePerCustomer"; // Translation key (used only if key ExportDataset_xxx_z not found)
319  $this->export_permission[$r] = array(array("service", "export"));
320  $this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref",
321  's.nom'=>'ThirdParty',
322  'pr.price_base_type'=>"PriceBase",
323  'pr.price'=>"PriceUnitPriceHT", 'pr.price_ttc'=>"PriceUnitPriceTTC",
324  'pr.price_min'=>"MinPriceUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceUnitPriceTTC",
325  'pr.tva_tx'=>'PriceVATRate',
326  'pr.default_vat_code'=>'PriceVATCode',
327  'pr.datec'=>'DateCreation');
328  if (is_object($mysoc) && $usenpr) {
329  $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
330  }
331  $this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product",
332  's.nom'=>'company',
333  'pr.price_base_type'=>"product", 'pr.price'=>"product",
334  'pr.price_ttc'=>"product",
335  'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product",
336  'pr.tva_tx'=>'product',
337  'pr.default_vat_code'=>'product',
338  'pr.recuperableonly'=>'product',
339  'pr.datec'=>"product");
340  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
341  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
342  $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
343  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON pr.fk_soc = s.rowid';
344  $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
345  }
346 
347  if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) {
348  // Exports virtual products
349  $r++;
350  $this->export_code[$r] = $this->rights_class.'_'.$r;
351  $this->export_label[$r] = "AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found)
352  $this->export_permission[$r] = array(array("service", "export"));
353  $this->export_fields_array[$r] = array(
354  'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label", 'p.description'=>"Description", 'p.url'=>"PublicUrl",
355  $alias_product_perentity . '.accountancy_code_sell'=>"ProductAccountancySellCode", $alias_product_perentity . '.accountancy_code_sell_intra'=>"ProductAccountancySellIntraCode",
356  $alias_product_perentity . '.accountancy_code_sell_export'=>"ProductAccountancySellExportCode", $alias_product_perentity . '.accountancy_code_buy'=>"ProductAccountancyBuyCode",
357  $alias_product_perentity . '.accountancy_code_buy_intra'=>"ProductAccountancyBuyIntraCode", $alias_product_perentity . '.accountancy_code_buy_export'=>"ProductAccountancyBuyExportCode",
358  'p.note'=>"NotePrivate", 'p.note_public'=>'NotePublic',
359  'p.weight'=>"Weight", 'p.length'=>"Length", 'p.surface'=>"Surface", 'p.volume'=>"Volume", 'p.customcode'=>'CustomCode',
360  'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC", 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell",
361  'p.tobuy'=>"OnBuy", 'p.datec'=>'DateCreation', 'p.tms'=>'DateModification'
362  );
363  if (!empty($conf->stock->enabled)) {
364  $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'));
365  }
366  if (!empty($conf->barcode->enabled)) {
367  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode'));
368  }
369  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('pa.qty'=>'Qty', 'pa.incdec'=>'ComposedProductIncDecStock'));
370  $this->export_TypeFields_array[$r] = array(
371  'p.ref'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.url'=>"Text",
372  $alias_product_perentity . 'p.accountancy_code_sell'=>"Text", $alias_product_perentity . '.accountancy_code_sell_intra'=>"Text", $alias_product_perentity . '.accountancy_code_sell_export'=>"Text",
373  $alias_product_perentity . 'p.accountancy_code_buy'=>"Text", $alias_product_perentity . '.accountancy_code_buy_intra'=>"Text", $alias_product_perentity . '.accountancy_code_buy_export'=>"Text",
374  'p.note'=>"Text", 'p.note_public'=>"Text",
375  'p.weight'=>"Numeric", 'p.length'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric", 'p.customcode'=>'Text',
376  'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric", 'p.tva_tx'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean",
377  'p.datec'=>'Date', 'p.tms'=>'Date'
378  );
379  if (!empty($conf->stock->enabled)) {
380  $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'));
381  }
382  if (!empty($conf->barcode->enabled)) {
383  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text'));
384  }
385  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('pa.qty'=>'Numeric'));
386  $this->export_entities_array[$r] = array(
387  'p.rowid'=>"virtualproduct", 'p.ref'=>"virtualproduct", 'p.label'=>"virtualproduct", 'p.description'=>"virtualproduct", 'p.url'=>"virtualproduct",
388  $alias_product_perentity . '.accountancy_code_sell'=>'virtualproduct', $alias_product_perentity . '.accountancy_code_sell_intra'=>'virtualproduct', $alias_product_perentity . '.accountancy_code_sell_export'=>'virtualproduct',
389  $alias_product_perentity . '.accountancy_code_buy'=>'virtualproduct', $alias_product_perentity . '.accountancy_code_buy_intra'=>'virtualproduct', $alias_product_perentity . '.accountancy_code_buy_export'=>'virtualproduct',
390  'p.note'=>"virtualproduct", 'p.length'=>"virtualproduct",
391  'p.surface'=>"virtualproduct", 'p.volume'=>"virtualproduct", 'p.weight'=>"virtualproduct", 'p.customcode'=>'virtualproduct',
392  'p.price_base_type'=>"virtualproduct", 'p.price'=>"virtualproduct", 'p.price_ttc'=>"virtualproduct", 'p.tva_tx'=>"virtualproduct",
393  'p.tosell'=>"virtualproduct", 'p.tobuy'=>"virtualproduct", 'p.datec'=>"virtualproduct", 'p.tms'=>"virtualproduct"
394  );
395  if (!empty($conf->stock->enabled)) {
396  $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'));
397  }
398  if (!empty($conf->barcode->enabled)) {
399  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'virtualproduct'));
400  }
401  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('pa.qty'=>"subproduct", 'pa.incdec'=>'subproduct'));
402  $keyforselect = 'product';
403  $keyforelement = 'product';
404  $keyforaliasextra = 'extra';
405  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
406  $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"));
407  $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"));
408  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
409  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
410  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
411  $this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as pac ON pac.fk_product = p.rowid AND pac.entity = " . ((int) $conf->entity);
412  }
413  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
414  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
415  $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
416  $this->export_sql_end[$r] .= ' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
417  }
418  }
419 
420  // Imports
421  //--------
422  $r = 0;
423 
424  // Import list of services
425 
426  $r++;
427  $this->import_code[$r] = $this->rights_class.'_'.$r;
428  $this->import_label[$r] = "Products"; // Translation key
429  $this->import_icon[$r] = $this->picto;
430  $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
431  $this->import_tables_array[$r] = array('p'=>MAIN_DB_PREFIX.'product', 'extra'=>MAIN_DB_PREFIX.'product_extrafields');
432  $this->import_tables_creator_array[$r] = array('p'=>'fk_user_author'); // Fields to store import user id
433  $this->import_fields_array[$r] = array(
434  'p.ref' => "Ref*",
435  'p.label' => "Label*",
436  'p.fk_product_type' => "Type*",
437  'p.tosell' => "OnSell*",
438  'p.tobuy' => "OnBuy*",
439  'p.description' => "Description",
440  'p.url' => "PublicUrl",
441  'p.customcode' => 'CustomCode',
442  'p.fk_country' => 'CountryCode',
443  'p.accountancy_code_sell' => "ProductAccountancySellCode",
444  'p.accountancy_code_sell_intra' => "ProductAccountancySellIntraCode",
445  'p.accountancy_code_sell_export' => "ProductAccountancySellExportCode",
446  'p.accountancy_code_buy' => "ProductAccountancyBuyCode",
447  'p.accountancy_code_buy_intra' => "ProductAccountancyBuyIntraCode",
448  'p.accountancy_code_buy_export' => "ProductAccountancyBuyExportCode",
449  'p.note_public' => "NotePublic",
450  'p.note' => "NotePrivate",
451  'p.weight' => "Weight",
452  'p.weight_units' => "WeightUnits",
453  'p.length' => "Length",
454  'p.length_units' => "LengthUnits",
455  'p.width' => "Width",
456  'p.width_units' => "WidthUnits",
457  'p.height' => "Height",
458  'p.height_units' => "HeightUnits",
459  'p.surface' => "Surface",
460  'p.surface_units' => "SurfaceUnits",
461  'p.volume' => "Volume",
462  'p.volume_units' => "VolumeUnits",
463  'p.duration' => "Duration", //duration of service
464  'p.finished' => 'Nature',
465  'p.price' => "SellingPriceHT", //without
466  'p.price_min' => "MinPrice",
467  'p.price_ttc' => "SellingPriceTTC", //with tax
468  'p.price_min_ttc' => "SellingMinPriceTTC",
469  'p.price_base_type' => "PriceBaseType", //price base: with-tax (TTC) or without (HT) tax. Displays accordingly in Product card
470  'p.tva_tx' => 'VATRate',
471  'p.datec' => 'DateCreation',
472  'p.cost_price' => "CostPrice",
473  );
474 
475  $this->import_convertvalue_array[$r] = array(
476  'p.weight_units' => array(
477  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
478  'classfile' => '/core/class/cunits.class.php',
479  'class' => 'CUnits',
480  'method' => 'fetch',
481  'units' => 'weight',
482  'dict' => 'DictionaryMeasuringUnits'
483  ),
484  'p.length_units' => array(
485  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
486  'classfile' => '/core/class/cunits.class.php',
487  'class' => 'CUnits',
488  'method' => 'fetch',
489  'units' => 'size',
490  'dict' => 'DictionaryMeasuringUnits'
491  ),
492  'p.width_units' => array(
493  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
494  'classfile' => '/core/class/cunits.class.php',
495  'class' => 'CUnits',
496  'method' => 'fetch',
497  'units' => 'size',
498  'dict' => 'DictionaryMeasuringUnits'
499  ),
500  'p.height_units' => array(
501  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
502  'classfile' => '/core/class/cunits.class.php',
503  'class' => 'CUnits',
504  'method' => 'fetch',
505  'units' => 'size',
506  'dict' => 'DictionaryMeasuringUnits'
507  ),
508  'p.surface_units' => array(
509  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
510  'classfile' => '/core/class/cunits.class.php',
511  'class' => 'CUnits',
512  'method' => 'fetch',
513  'units' => 'surface',
514  'dict' => 'DictionaryMeasuringUnits'
515  ),
516  'p.volume_units' => array(
517  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
518  'classfile' => '/core/class/cunits.class.php',
519  'class' => 'CUnits',
520  'method' => 'fetch',
521  'units' => 'volume',
522  'dict' => 'DictionaryMeasuringUnits'
523  ),
524  'p.fk_country' => array(
525  'rule' => 'fetchidfromcodeid',
526  'classfile' => '/core/class/ccountry.class.php',
527  'class' => 'Ccountry',
528  'method' => 'fetch',
529  'dict' => 'DictionaryCountry'
530  )
531  );
532 
533  $this->import_regex_array[$r] = array(
534  'p.ref' => '[^ ]',
535  'p.price_base_type' => '\AHT\z|\ATTC\z',
536  'p.tosell' => '^[0|1]$',
537  'p.tobuy' => '^[0|1]$',
538  'p.fk_product_type' => '^[0|1]$',
539  'p.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
540  'p.recuperableonly' => '^[0|1]$',
541  );
542 
543  if (!empty($conf->stock->enabled)) {//if Stock module enabled
544  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
545  'p.fk_default_warehouse'=>'DefaultWarehouse',
546  'p.tobatch'=>'ManageLotSerial',
547  'p.seuil_stock_alerte' => 'StockLimit', //lower limit for warning
548  'p.pmp' => 'PMPValue', //weighted average price
549  'p.desiredstock' => 'DesiredStock'//desired stock for replenishment feature
550  ));
551 
552  $this->import_regex_array[$r] = array_merge($this->import_regex_array[$r], array(
553  'p.tobatch' => '^[0|1|2]$'
554  ));
555 
556  $this->import_convertvalue_array[$r] = array_merge($this->import_convertvalue_array[$r], array(
557  'p.fk_default_warehouse' => array(
558  'rule' => 'fetchidfromref',
559  'classfile' => '/product/stock/class/entrepot.class.php',
560  'class' => 'Entrepot',
561  'method' => 'fetch',
562  'element'=> 'Warehouse'
563  )
564  ));
565  }
566 
567  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled) || !empty($conf->margin->enabled)) {
568  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.cost_price'=>'CostPrice'));
569  }
570  if (is_object($mysoc) && $usenpr) {
571  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.recuperableonly'=>'NPR'));
572  }
573  if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
574  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type'));
575  }
576  if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
577  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type'));
578  }
579  if (!empty($conf->barcode->enabled)) {
580  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.barcode'=>'BarCode'));
581  }
582  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
583  $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
584  }
585  // Add extra fields
586  $import_extrafield_sample = array();
587  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'product' AND entity IN (0,".$conf->entity.")";
588  $resql = $this->db->query($sql);
589  if ($resql) { // This can fail when class is used on old database (during migration for example)
590  while ($obj = $this->db->fetch_object($resql)) {
591  $fieldname = 'extra.'.$obj->name;
592  $fieldlabel = ucfirst($obj->label);
593  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
594  $import_extrafield_sample[$fieldname] = $fieldlabel;
595  }
596  }
597  // End add extra fields
598  $this->import_fieldshidden_array[$r] = array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
599  $this->import_regex_array[$r] = array(
600  'p.ref'=>'[^ ]',
601  'p.price_base_type' => 'HT|TTC',
602  'p.tosell'=>'^[0|1]$',
603  'p.tobuy'=>'^[0|1]$',
604  'p.fk_product_type'=>'^[0|1]$',
605  'p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
606  'p.recuperableonly' => '^[0|1]$',
607  'p.finished' => '^[0|1]$'
608  );
609  // field order as per structure of table llx_product
610  $import_sample = array(
611  'p.ref' => "ref:PREF123456",
612  'p.datec' => dol_print_date(dol_now(), '%Y-%m-%d'),
613  'p.label' => "Product name in default language",
614  'p.description' => "Product description in default language",
615  'p.note_public' => "a public note (free text)",
616  'p.note' => "a private note (free text)",
617  'p.customcode' => 'customs code',
618  'p.fk_country' => 'FR',
619  'p.price' => "100",
620  'p.price_min' => "100",
621  'p.price_ttc' => "110",
622  'p.price_min_ttc' => "110",
623  'p.price_base_type' => "HT (show/use price excl. tax) / TTC (show/use price incl. tax)",
624  'p.tva_tx' => '10', // tax rate eg: 10. Must match numerically one of the tax rates defined for your country'
625  'p.tosell' => "0 (not for sale to customer, eg. raw material) / 1 (for sale)",
626  'p.tobuy' => "0 (not for purchase from supplier, eg. virtual product) / 1 (for purchase)",
627  'p.fk_product_type' => "0 (product) / 1 (service)",
628  'p.duration' => "eg. 365d/12m/1y",
629  'p.url' => 'link to product (no https)',
630  'p.accountancy_code_sell' => "",
631  'p.accountancy_code_sell_intra' => "",
632  'p.accountancy_code_sell_export' => "",
633  'p.accountancy_code_buy' => "",
634  'p.accountancy_code_buy_intra' => "",
635  'p.accountancy_code_buy_export' => "",
636  'p.weight' => "",
637  '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',
638  'p.length' => "",
639  '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',
640  'p.width' => "",
641  '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',
642  'p.height' => "",
643  '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',
644  'p.surface' => "",
645  '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',
646  'p.volume' => "",
647  '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',
648  'p.finished' => '0 (raw material) / 1 (finished goods), matches field "code" in dictionary table "'.MAIN_DB_PREFIX.'c_product_nature"'
649  );
650  //clauses copied from import_fields_array
651  if (!empty($conf->stock->enabled)) {
652  $import_sample = array_merge($import_sample, array(
653  'p.seuil_stock_alerte' => '',
654  'p.pmp' => '0',
655  'p.desiredstock' => ''
656  ));
657  }
658  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled) || !empty($conf->margin->enabled)) {
659  $import_sample = array_merge($import_sample, array('p.cost_price'=>'90'));
660  }
661  if (is_object($mysoc) && $usenpr) {
662  $import_sample = array_merge($import_sample, array('p.recuperableonly'=>'0'));
663  }
664  if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
665  $import_sample = array_merge($import_sample, array('p.localtax1_tx'=>'', 'p.localtax1_type'=>''));
666  }
667  if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
668  $import_sample = array_merge($import_sample, array('p.localtax2_tx'=>'', 'p.localtax2_type'=>''));
669  }
670  if (!empty($conf->barcode->enabled)) {
671  $import_sample = array_merge($import_sample, array('p.barcode'=>''));
672  }
673  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
674  $import_sample = array_merge(
675  $import_sample,
676  array(
677  '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"'
678  )
679  );
680 
681  if (!is_array($this->import_convertvalue_array[$r])) {
682  $this->import_convertvalue_array[$r] = array();
683  }
684  $this->import_convertvalue_array[$r] = array_merge($this->import_convertvalue_array[$r], array(
685  'p.fk_unit' => array(
686  'rule' => 'fetchidfromcodeorlabel',
687  'classfile' => '/core/class/cunits.class.php',
688  'class' => 'CUnits',
689  'method' => 'fetch',
690  'dict' => 'DictionaryUnits'
691  )
692  ));
693  }
694  $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
695  $this->import_updatekeys_array[$r] = array('p.ref'=>'Ref');
696  if (!empty($conf->barcode->enabled)) {
697  $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
698  }
699 
700  if (empty($conf->product->enabled)) { // We enable next import templates only if module product not already enabled (to avoid duplicate entries)
701  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
702  // Import suppliers prices (note: this code is duplicated in module Service)
703  $r++;
704  $this->import_code[$r] = $this->rights_class.'_supplierprices';
705  $this->import_label[$r] = "SuppliersPricesOfProductsOrServices"; // Translation key
706  $this->import_icon[$r] = $this->picto;
707  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
708  $this->import_tables_array[$r] = array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price');
709  $this->import_tables_creator_array[$r] = array('sp'=>'fk_user');
710  $this->import_fields_array[$r] = array(//field order as per structure of table llx_product_fournisseur_price, without optional fields
711  'sp.fk_product'=>"ProductOrService*",
712  'sp.fk_soc' => "Supplier*",
713  'sp.ref_fourn' => 'SupplierRef*',
714  'sp.quantity' => "QtyMin*",
715  'sp.tva_tx' => 'VATRate',
716  'sp.default_vat_code' => 'VATCode',
717  'sp.delivery_time_days' => 'DeliveryDelay',
718  'sp.supplier_reputation' => 'SupplierReputation'
719  );
720  if (is_object($mysoc) && $usenpr) {
721  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.recuperableonly'=>'VATNPR'));
722  }
723  if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
724  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type'));
725  }
726  if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
727  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type'));
728  }
729  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
730  'sp.price'=>"PriceQtyMinHT*",
731  'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty
732  'sp.remise_percent'=>'DiscountQtyMin'
733  ));
734 
735  if (!empty($conf->multicurrency->enabled)) {
736  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
737  'sp.fk_multicurrency'=>'CurrencyCodeId', //ideally this should be automatically obtained from the CurrencyCode on the next line
738  'sp.multicurrency_code'=>'CurrencyCode',
739  'sp.multicurrency_tx'=>'CurrencyRate',
740  'sp.multicurrency_unitprice'=>'CurrencyUnitPrice',
741  'sp.multicurrency_price'=>'CurrencyPrice',
742  ));
743  }
744 
745  $this->import_convertvalue_array[$r] = array(
746  'sp.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'),
747  'sp.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
748  );
749  $this->import_examplevalues_array[$r] = array(
750  'sp.fk_product' => "ref:PRODUCT_REF or id:123456",
751  'sp.fk_soc' => "My Supplier",
752  'sp.ref_fourn' => "XYZ-F123456",
753  'sp.quantity' => "5",
754  'sp.tva_tx' => '10',
755  'sp.price'=>"50",
756  'sp.unitprice'=>'50',
757  'sp.remise_percent'=>'0',
758  'sp.default_vat_code' => '',
759  'sp.delivery_time_days' => '5',
760  'sp.supplier_reputation' => 'FAVORITE / NOTTHGOOD / DONOTORDER'
761  );
762  if (is_object($mysoc) && $usenpr) {
763  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.recuperableonly'=>''));
764  }
765  if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
766  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type'));
767  }
768  if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
769  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type'));
770  }
771  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
772  'sp.price' => "50.00",
773  'sp.unitprice' => '10',
774  // TODO Make this field not required and calculate it from price and qty
775  'sp.remise_percent' => '20'
776  ));
777  if (!empty($conf->multicurrency->enabled)) {
778  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
779  'sp.fk_multicurrency'=>'eg: 2, rowid for code of multicurrency currency',
780  'sp.multicurrency_code'=>'GBP',
781  'sp.multicurrency_tx'=>'1.12345',
782  'sp.multicurrency_unitprice'=>'',
783  // TODO Make this field not required and calculate it from price and qty
784  'sp.multicurrency_price'=>''
785  ));
786  }
787  if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
788  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
789  'sp.packagning'=>'10',
790  ));
791  }
792 
793  $this->import_updatekeys_array[$r] = array('sp.fk_product'=>'ProductOrService', 'sp.ref_fourn'=>'SupplierRef', 'sp.fk_soc'=>'Supplier');
794  }
795 
796  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
797  // Import products multiprices
798  $r++;
799  $this->import_code[$r] = $this->rights_class.'_multiprice';
800  $this->import_label[$r] = "ProductsOrServiceMultiPrice"; // Translation key
801  $this->import_icon[$r] = $this->picto;
802  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
803  $this->import_tables_array[$r] = array('pr'=>MAIN_DB_PREFIX.'product_price');
804  $this->import_tables_creator_array[$r] = array('pr'=>'fk_user_author'); // Fields to store import user id
805  $this->import_fields_array[$r] = array('pr.fk_product'=>"ProductOrService*",
806  'pr.price_base_type'=>"PriceBase", 'pr.price_level'=>"PriceLevel",
807  'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
808  'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
809  'pr.date_price'=>'DateCreation*');
810  if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
811  $this->import_fields_array[$r]['pr.tva_tx'] = 'VATRate';
812  }
813  if (is_object($mysoc) && $usenpr) {
814  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('pr.recuperableonly'=>'NPR'));
815  }
816  $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]$');
817  $this->import_convertvalue_array[$r] = array(
818  'pr.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
819  );
820  $this->import_examplevalues_array[$r] = array('pr.fk_product'=>"ref:SERVICE_REF or id:123456",
821  'pr.price_base_type'=>"HT (for excl tax) or TTC (for inc tax)", 'pr.price_level'=>"1",
822  'pr.price'=>"100", 'pr.price_ttc'=>"110",
823  'pr.price_min'=>"100", 'pr.price_min_ttc'=>"110",
824  'pr.tva_tx'=>'20',
825  'pr.recuperableonly'=>'0',
826  'pr.date_price'=>'2013-04-10');
827  }
828 
829  if (!empty($conf->global->MAIN_MULTILANGS)) {
830  // Import translations of product names and descriptions
831  $r++;
832  $this->import_code[$r] = $this->rights_class.'_languages';
833  $this->import_label[$r] = "ProductsOrServicesTranslations";
834  $this->import_icon[$r] = $this->picto;
835  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
836  $this->import_tables_array[$r] = array('l'=>MAIN_DB_PREFIX.'product_lang');
837  // multiline translation, one line per translation
838  $this->import_fields_array[$r] = array('l.fk_product'=>'ProductOrService*', 'l.lang'=>'Language*', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
839  //$this->import_fields_array[$r]['l.note']='TranslatedNote';
840  $this->import_convertvalue_array[$r] = array(
841  'l.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
842  );
843  $this->import_examplevalues_array[$r] = array('l.fk_product'=>'ref:SERVICE_REF or id:123456', 'l.lang'=>'en_US', 'l.label'=>'Label in en_US', 'l.description'=>'Desc in en_US');
844  $this->import_updatekeys_array[$r] = array('l.fk_product'=>'ProductOrService', 'l.lang'=>'Language');
845  }
846  }
847  }
848 
849 
858  public function init($options = '')
859  {
860  $this->remove($options);
861 
862  $sql = array();
863 
864  return $this->_init($sql, $options);
865  }
866 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
name
$conf db name
Definition: repair.php:122
modService
Class to describe and enable module Service.
Definition: modService.class.php:36
modService\__construct
__construct($db)
Constructor.
Definition: modService.class.php:44
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
modService\init
init($options='')
Function called when module is enabled.
Definition: modService.class.php:858
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:383
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
DolibarrModules
Class DolibarrModules.
Definition: DolibarrModules.class.php:37