dolibarr  16.0.5
modProduct.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7  * Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2014 Christophe Battarel <contact@altairis.fr>
9  * Copyright (C) 2014 Cedric Gross <c.gross@kreiz-it.fr>
10  * Copyright (C) 2020-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
33 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
34 
35 
40 {
46  public function __construct($db)
47  {
48  global $conf, $mysoc;
49 
50  $this->db = $db;
51  $this->numero = 50;
52 
53  $this->family = "products";
54  $this->module_position = '26';
55  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
56  $this->name = preg_replace('/^mod/i', '', get_class($this));
57  $this->description = "Product management";
58 
59  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
60  $this->version = 'dolibarr';
61 
62  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
63  $this->picto = 'product';
64 
65  // Data directories to create when module is enabled
66  $this->dirs = array("/product/temp");
67 
68  // Dependencies
69  $this->hidden = false; // A condition to hide module
70  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
71  $this->requiredby = array("modStock", "modBarcode", "modProductBatch", "modVariants"); // List of module ids to disable if this one is disabled
72  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
73  $this->phpmin = array(5, 6); // Minimum version of PHP required by module
74 
75  // Config pages
76  $this->config_page_url = array("product.php@product");
77  $this->langfiles = array("products", "companies", "stocks", "bills");
78 
79  // Constants
80  $this->const = array();
81  $r = 0;
82 
83  $this->const[$r][0] = "PRODUCT_CODEPRODUCT_ADDON";
84  $this->const[$r][1] = "chaine";
85  $this->const[$r][2] = "mod_codeproduct_leopard";
86  $this->const[$r][3] = 'Module to control product codes';
87  $this->const[$r][4] = 0;
88  $r++;
89 
90  $this->const[$r][0] = "PRODUCT_PRICE_UNIQ";
91  $this->const[$r][1] = "chaine";
92  $this->const[$r][2] = "1";
93  $this->const[$r][3] = 'pricing rule by default';
94  $this->const[$r][4] = 0;
95  $r++;
96 
97  /*$this->const[$r][0] = "PRODUCT_ADDON_PDF";
98  $this->const[$r][1] = "chaine";
99  $this->const[$r][2] = "standard";
100  $this->const[$r][3] = 'Default module for document generation';
101  $this->const[$r][4] = 0;
102  $r++;*/
103 
104  // Boxes
105  $this->boxes = array(
106  0=>array('file'=>'box_produits.php', 'enabledbydefaulton'=>'Home'),
107  1=>array('file'=>'box_produits_alerte_stock.php', 'enabledbydefaulton'=>''),
108  2=>array('file'=>'box_graph_product_distribution.php', 'enabledbydefaulton'=>'Home')
109  );
110 
111  // Permissions
112  $this->rights = array();
113  $this->rights_class = 'produit';
114  $r = 0;
115 
116  $this->rights[$r][0] = 31; // id de la permission
117  $this->rights[$r][1] = 'Read products'; // libelle de la permission
118  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
119  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
120  $this->rights[$r][4] = 'lire';
121  $r++;
122 
123  $this->rights[$r][0] = 32; // id de la permission
124  $this->rights[$r][1] = 'Create/modify products'; // libelle de la permission
125  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
126  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
127  $this->rights[$r][4] = 'creer';
128  $r++;
129 
130  $this->rights[$r][0] = 34; // id de la permission
131  $this->rights[$r][1] = 'Delete products'; // libelle de la permission
132  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
133  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
134  $this->rights[$r][4] = 'supprimer';
135  $r++;
136 
137  $this->rights[$r][0] = 38; // Must be same permission than in service module
138  $this->rights[$r][1] = 'Export products';
139  $this->rights[$r][2] = 'r';
140  $this->rights[$r][3] = 0;
141  $this->rights[$r][4] = 'export';
142  $r++;
143 
144  $this->rights[$r][0] = 39;
145  $this->rights[$r][1] = 'Ignore minimum price';
146  $this->rights[$r][2] = 'r';
147  $this->rights[$r][3] = 0;
148  $this->rights[$r][4] = 'ignore_price_min_advance';
149  $r++;
150 
151  // Menus
152  //-------
153 
154  $this->menu = 1; // This module adds menu entries. They are coded into menu manager.
155  /* We can't enable this here because it must be enabled in both product and service module and this creates duplicate inserts
156  $r=0;
157  $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
158  'type'=>'left', // This is a Left menu entry
159  'titre'=>'ProductVatMassChange',
160  'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=admintools',
161  'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
162  'position'=>300,
163  '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.
164  'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
165  'target'=>'',
166  'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
167  $r++;
168  */
169 
170  $usenpr = 0;
171  if (is_object($mysoc)) {
172  $usenpr = $mysoc->useNPR();
173  }
174 
175  // Exports
176  //--------
177  $r = 0;
178 
179  $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p" : "ppe";
180 
181  $r++;
182  $this->export_code[$r] = $this->rights_class.'_'.$r;
183  $this->export_label[$r] = "Products"; // Translation key (used only if key ExportDataset_xxx_z not found)
184  $this->export_permission[$r] = array(array("produit", "export"));
185  $this->export_fields_array[$r] = array(
186  'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label",
187  'p.fk_product_type'=>'Type', 'p.tosell'=>"OnSell", 'p.tobuy'=>"OnBuy",
188  'p.description'=>"Description", 'p.url'=>"PublicUrl",
189  'p.customcode'=>'CustomCode', 'p.fk_country'=>'IDCountry',
190  $alias_product_perentity . '.accountancy_code_sell'=>"ProductAccountancySellCode", $alias_product_perentity . '.accountancy_code_sell_intra'=>"ProductAccountancySellIntraCode",
191  $alias_product_perentity . '.accountancy_code_sell_export'=>"ProductAccountancySellExportCode", $alias_product_perentity . '.accountancy_code_buy'=>"ProductAccountancyBuyCode",
192  $alias_product_perentity . '.accountancy_code_buy_intra'=>"ProductAccountancyBuyIntraCode", $alias_product_perentity . '.accountancy_code_buy_export'=>"ProductAccountancyBuyExportCode",
193  'p.note'=>"NotePrivate", 'p.note_public'=>'NotePublic',
194  'p.weight'=>"Weight", 'p.weight_units'=>"WeightUnits", 'p.length'=>"Length", 'p.length_units'=>"LengthUnits", 'p.width'=>"Width", 'p.width_units'=>"WidthUnits", 'p.height'=>"Height", 'p.height_units'=>"HeightUnits",
195  'p.surface'=>"Surface", 'p.surface_units'=>"SurfaceUnits", 'p.volume'=>"Volume", 'p.volume_units'=>"VolumeUnits",
196  'p.duration'=>"Duration",
197  'p.finished' => 'Nature',
198  'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC",
199  'p.price_min'=>"MinPriceHT",'p.price_min_ttc'=>"MinPriceTTC",
200  'p.tva_tx'=>'VATRate',
201  'p.datec'=>'DateCreation', 'p.tms'=>'DateModification'
202  );
203  if (is_object($mysoc) && $usenpr) {
204  $this->export_fields_array[$r]['p.recuperableonly'] = 'NPR';
205  }
206  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)) {
207  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.cost_price'=>'CostPrice'));
208  }
209  if (!empty($conf->stock->enabled)) {
210  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('e.ref'=>'DefaultWarehouse', 'p.tobatch'=>'ManageLotSerial', 'p.stock'=>'Stock', 'p.seuil_stock_alerte'=>'StockLimit', 'p.desiredstock'=>'DesiredStock', 'p.pmp'=>'PMPValue'));
211  }
212  if (!empty($conf->barcode->enabled)) {
213  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode'));
214  }
215  $keyforselect = 'product';
216  $keyforelement = 'product';
217  $keyforaliasextra = 'extra';
218  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
219  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
220  $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'));
221  }
222  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
223  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('group_concat(cat.label)'=>'Categories'));
224  }
225  if (!empty($conf->global->MAIN_MULTILANGS)) {
226  $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'));
227  }
228  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
229  $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
230  }
231  $this->export_TypeFields_array[$r] = array(
232  'p.ref'=>"Text", 'p.label'=>"Text",
233  'p.fk_product_type'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean",
234  'p.description'=>"Text", 'p.url'=>"Text",
235  $alias_product_perentity . '.accountancy_code_sell'=>"Text", $alias_product_perentity . '.accountancy_code_sell_intra'=>"Text", $alias_product_perentity . '.accountancy_code_sell_export'=>"Text",
236  $alias_product_perentity . '.accountancy_code_buy'=>"Text", $alias_product_perentity . '.accountancy_code_buy_intra'=>"Text", $alias_product_perentity . '.accountancy_code_buy_export'=>"Text",
237  'p.note'=>"Text", 'p.note_public'=>"Text",
238  'p.weight'=>"Numeric", 'p.length'=>"Numeric", 'p.width'=>"Numeric", 'p.height'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric",
239  'p.customcode'=>'Text',
240  'p.duration'=>"Text",
241  'p.finished' => 'Numeric',
242  'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric",
243  'p.price_min'=>"Numeric", 'p.price_min_ttc'=>"Numeric",
244  'p.tva_tx'=>'Numeric',
245  'p.datec'=>'Date', 'p.tms'=>'Date'
246  );
247  if (!empty($conf->stock->enabled)) {
248  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('e.ref'=>'Text', 'p.tobatch'=>'Numeric', 'p.stock'=>'Numeric', 'p.seuil_stock_alerte'=>'Numeric', 'p.desiredstock'=>'Numeric', 'p.pmp'=>'Numeric', 'p.cost_price'=>'Numeric'));
249  }
250  if (!empty($conf->barcode->enabled)) {
251  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text'));
252  }
253  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
254  $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'));
255  }
256  if (!empty($conf->global->MAIN_MULTILANGS)) {
257  $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'));
258  }
259  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
260  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array("group_concat(cat.label)"=>'Text'));
261  }
262  $this->export_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
263  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
264  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array("group_concat(cat.label)"=>'category'));
265  }
266  if (!empty($conf->stock->enabled)) {
267  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'product', 'p.pmp'=>'product'));
268  }
269  if (!empty($conf->barcode->enabled)) {
270  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'product'));
271  }
272  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
273  $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'));
274  }
275  if (!empty($conf->global->MAIN_MULTILANGS)) {
276  $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'));
277  }
278  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
279  $this->export_dependencies_array[$r] = array('category'=>'p.rowid');
280  }
281  if (!empty($conf->stock->enabled)) {
282  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock'=>'product', 'p.pmp'=>'product'));
283  }
284  if (!empty($conf->barcode->enabled)) {
285  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'product'));
286  }
287  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
288  $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'));
289  }
290  if (!empty($conf->global->MAIN_MULTILANGS)) {
291  $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'));
292  }
293  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
294  $this->export_dependencies_array[$r] = array('category'=>'p.rowid');
295  }
296  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
297  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
298  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
299  $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);
300  }
301  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
302  $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';
303  }
304  if (!empty($conf->global->MAIN_MULTILANGS)) {
305  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
306  }
307  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
308  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
309  $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';
310  }
311  if (!empty($conf->stock->enabled)) {
312  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e ON e.rowid = p.fk_default_warehouse';
313  }
314  $this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
315  if (!empty($conf->global->EXPORTTOOL_CATEGORIES)) {
316  $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"
317  }
318 
319  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
320  // Exports product multiprice
321  $r++;
322  $this->export_code[$r] = $this->rights_class.'_'.$r;
323  $this->export_label[$r] = "ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found)
324  $this->export_permission[$r] = array(array("produit", "export"));
325  $this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label",
326  'pr.price_base_type'=>"PriceBase", 'pr.price_level'=>"PriceLevel",
327  'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
328  'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
329  'pr.tva_tx'=>'PriceLevelVATRate',
330  'pr.date_price'=>'DateCreation');
331  if (is_object($mysoc) && $usenpr) {
332  $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
333  }
334  //$this->export_TypeFields_array[$r]=array(
335  // 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
336  // 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
337  // 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
338  // 'p.datec'=>'Date','p.tms'=>'Date'
339  //);
340  $this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product", 'p.label'=>"Label",
341  'pr.price_base_type'=>"product", 'pr.price_level'=>"product", 'pr.price'=>"product",
342  'pr.price_ttc'=>"product",
343  'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product",
344  'pr.tva_tx'=>'product',
345  'pr.recuperableonly'=>'product',
346  'pr.date_price'=>"product");
347  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
348  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
349  $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
350  $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
351  $this->export_sql_end[$r] .= ' AND pr.date_price = (SELECT MAX(pr2.date_price) FROM '.MAIN_DB_PREFIX.'product_price as pr2 WHERE pr2.fk_product = pr.fk_product AND pr2.entity IN ('.getEntity('product').'))'; // export only latest prices not full history
352  $this->export_sql_end[$r] .= ' ORDER BY p.ref, pr.price_level';
353  }
354 
355  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
356  // Exports product multiprice
357  $r++;
358  $this->export_code[$r] = $this->rights_class.'_'.$r;
359  $this->export_label[$r] = "ProductsPricePerCustomer"; // Translation key (used only if key ExportDataset_xxx_z not found)
360  $this->export_permission[$r] = array(array("produit", "export"));
361  $this->export_fields_array[$r] = array('p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label",
362  's.nom'=>'ThirdParty',
363  'pr.price_base_type'=>"PriceBase",
364  'pr.price'=>"PriceUnitPriceHT", 'pr.price_ttc'=>"PriceUnitPriceTTC",
365  'pr.price_min'=>"MinPriceUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceUnitPriceTTC",
366  'pr.tva_tx'=>'PriceVATRate',
367  'pr.default_vat_code'=>'PriceVATCode',
368  'pr.datec'=>'DateCreation');
369  if (is_object($mysoc) && $usenpr) {
370  $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
371  }
372  $this->export_entities_array[$r] = array('p.rowid'=>"product", 'p.ref'=>"product", 'p.label'=>"Label",
373  's.nom'=>'company',
374  'pr.price_base_type'=>"product", 'pr.price'=>"product",
375  'pr.price_ttc'=>"product",
376  'pr.price_min'=>"product", 'pr.price_min_ttc'=>"product",
377  'pr.tva_tx'=>'product',
378  'pr.default_vat_code'=>'product',
379  'pr.recuperableonly'=>'product',
380  'pr.datec'=>"product");
381  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
382  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
383  $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
384  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON pr.fk_soc = s.rowid';
385  $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
386  }
387 
388  if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) {
389  // Exports virtual products
390  $r++;
391  $this->export_code[$r] = $this->rights_class.'_'.$r;
392  $this->export_label[$r] = "AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found)
393  $this->export_permission[$r] = array(array("produit", "export"));
394  $this->export_fields_array[$r] = array(
395  'p.rowid'=>"Id", 'p.ref'=>"Ref", 'p.label'=>"Label", 'p.description'=>"Description", 'p.url'=>"PublicUrl",
396  $alias_product_perentity . '.accountancy_code_sell'=>"ProductAccountancySellCode", $alias_product_perentity . '.accountancy_code_sell_intra'=>"ProductAccountancySellIntraCode",
397  $alias_product_perentity . '.accountancy_code_sell_export'=>"ProductAccountancySellExportCode", $alias_product_perentity . '.accountancy_code_buy'=>"ProductAccountancyBuyCode",
398  $alias_product_perentity . '.accountancy_code_buy_intra'=>"ProductAccountancyBuyIntraCode", $alias_product_perentity . '.accountancy_code_buy_export'=>"ProductAccountancyBuyExportCode",
399  'p.note'=>"NotePrivate", 'p.note_public'=>'NotePublic',
400  'p.weight'=>"Weight", 'p.length'=>"Length", 'p.surface'=>"Surface", 'p.volume'=>"Volume", 'p.customcode'=>'CustomCode',
401  'p.price_base_type'=>"PriceBase", 'p.price'=>"UnitPriceHT", 'p.price_ttc'=>"UnitPriceTTC", 'p.tva_tx'=>'VATRate', 'p.tosell'=>"OnSell",
402  'p.tobuy'=>"OnBuy", 'p.datec'=>'DateCreation', 'p.tms'=>'DateModification'
403  );
404  if (!empty($conf->stock->enabled)) {
405  $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'));
406  }
407  if (!empty($conf->barcode->enabled)) {
408  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode'=>'BarCode'));
409  }
410  $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('pa.qty'=>'Qty', 'pa.incdec'=>'ComposedProductIncDecStock'));
411  $this->export_TypeFields_array[$r] = array(
412  'p.ref'=>"Text", 'p.label'=>"Text", 'p.description'=>"Text", 'p.url'=>"Text",
413  $alias_product_perentity . '.accountancy_code_sell'=>"Text", $alias_product_perentity . '.accountancy_code_sell_intra'=>"Text", $alias_product_perentity . '.accountancy_code_sell_export'=>"Text",
414  $alias_product_perentity . '.accountancy_code_buy'=>"Text", $alias_product_perentity . '.accountancy_code_buy_intra'=>"Text", $alias_product_perentity . '.accountancy_code_buy_export'=>"Text",
415  'p.note'=>"Text", 'p.note_public'=>"Text",
416  'p.weight'=>"Numeric", 'p.length'=>"Numeric", 'p.surface'=>"Numeric", 'p.volume'=>"Numeric", 'p.customcode'=>'Text',
417  'p.price_base_type'=>"Text", 'p.price'=>"Numeric", 'p.price_ttc'=>"Numeric", 'p.tva_tx'=>'Numeric', 'p.tosell'=>"Boolean", 'p.tobuy'=>"Boolean",
418  'p.datec'=>'Date', 'p.tms'=>'Date'
419  );
420  if (!empty($conf->stock->enabled)) {
421  $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'));
422  }
423  if (!empty($conf->barcode->enabled)) {
424  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode'=>'Text'));
425  }
426  $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('pa.qty'=>'Numeric'));
427  $this->export_entities_array[$r] = array(
428  'p.rowid'=>"virtualproduct", 'p.ref'=>"virtualproduct", 'p.label'=>"virtualproduct", 'p.description'=>"virtualproduct", 'p.url'=>"virtualproduct",
429  $alias_product_perentity . '.accountancy_code_sell'=>'virtualproduct', $alias_product_perentity . '.accountancy_code_sell_intra'=>'virtualproduct', $alias_product_perentity . '.accountancy_code_sell_export'=>'virtualproduct',
430  $alias_product_perentity . '.accountancy_code_buy'=>'virtualproduct', $alias_product_perentity . '.accountancy_code_buy_intra'=>'virtualproduct', $alias_product_perentity . '.accountancy_code_buy_export'=>'virtualproduct',
431  'p.note'=>"virtualproduct", 'p.length'=>"virtualproduct",
432  'p.surface'=>"virtualproduct", 'p.volume'=>"virtualproduct", 'p.weight'=>"virtualproduct", 'p.customcode'=>'virtualproduct',
433  'p.price_base_type'=>"virtualproduct", 'p.price'=>"virtualproduct", 'p.price_ttc'=>"virtualproduct", 'p.tva_tx'=>"virtualproduct",
434  'p.tosell'=>"virtualproduct", 'p.tobuy'=>"virtualproduct", 'p.datec'=>"virtualproduct", 'p.tms'=>"virtualproduct"
435  );
436  if (!empty($conf->stock->enabled)) {
437  $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'));
438  }
439  if (!empty($conf->barcode->enabled)) {
440  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode'=>'virtualproduct'));
441  }
442  $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('pa.qty'=>"subproduct", 'pa.incdec'=>'subproduct'));
443  $keyforselect = 'product';
444  $keyforelement = 'product';
445  $keyforaliasextra = 'extra';
446  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
447  $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"));
448  $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"));
449  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
450  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
451  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
452  $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);
453  }
454  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
455  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
456  $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
457  $this->export_sql_end[$r] .= ' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
458  }
459 
460  // Imports
461  //--------
462  $r = 0;
463 
464  // Import list of products
465 
466  $r++;
467  $this->import_code[$r] = $this->rights_class.'_'.$r;
468  $this->import_label[$r] = "Products"; // Translation key
469  $this->import_icon[$r] = $this->picto;
470  $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
471  $this->import_tables_array[$r] = array('p'=>MAIN_DB_PREFIX.'product', 'extra'=>MAIN_DB_PREFIX.'product_extrafields');
472  $this->import_tables_creator_array[$r] = array('p'=>'fk_user_author'); // Fields to store import user id
473  $this->import_fields_array[$r] = array(
474  'p.ref' => "Ref*",
475  'p.label' => "Label*",
476  'p.fk_product_type' => "Type*",
477  'p.tosell' => "OnSell*",
478  'p.tobuy' => "OnBuy*",
479  'p.description' => "Description",
480  'p.url' => "PublicUrl",
481  'p.customcode' => 'CustomCode',
482  'p.fk_country' => 'CountryCode',
483  'p.accountancy_code_sell' => "ProductAccountancySellCode",
484  'p.accountancy_code_sell_intra' => "ProductAccountancySellIntraCode",
485  'p.accountancy_code_sell_export' => "ProductAccountancySellExportCode",
486  'p.accountancy_code_buy' => "ProductAccountancyBuyCode",
487  'p.accountancy_code_buy_intra' => "ProductAccountancyBuyIntraCode",
488  'p.accountancy_code_buy_export' => "ProductAccountancyBuyExportCode",
489  'p.note_public' => "NotePublic",
490  'p.note' => "NotePrivate",
491  'p.weight' => "Weight",
492  'p.weight_units' => "WeightUnits",
493  'p.length' => "Length",
494  'p.length_units' => "LengthUnits",
495  'p.width' => "Width",
496  'p.width_units' => "WidthUnits",
497  'p.height' => "Height",
498  'p.height_units' => "HeightUnits",
499  'p.surface' => "Surface",
500  'p.surface_units' => "SurfaceUnits",
501  'p.volume' => "Volume",
502  'p.volume_units' => "VolumeUnits",
503  'p.duration' => "Duration", //duration of service
504  'p.finished' => 'Nature',
505  'p.price' => "SellingPriceHT", //without
506  'p.price_min' => "MinPrice",
507  'p.price_ttc' => "SellingPriceTTC", //with tax
508  'p.price_min_ttc' => "SellingMinPriceTTC",
509  'p.price_base_type' => "PriceBaseType", //price base: with-tax (TTC) or without (HT) tax. Displays accordingly in Product card
510  'p.tva_tx' => 'VATRate',
511  'p.datec' => 'DateCreation',
512  'p.cost_price' => "CostPrice",
513  );
514 
515  $this->import_convertvalue_array[$r] = array(
516  'p.weight_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' => 'weight',
522  'dict' => 'DictionaryMeasuringUnits'
523  ),
524  'p.length_units' => array(
525  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
526  'classfile' => '/core/class/cunits.class.php',
527  'class' => 'CUnits',
528  'method' => 'fetch',
529  'units' => 'size',
530  'dict' => 'DictionaryMeasuringUnits'
531  ),
532  'p.width_units' => array(
533  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
534  'classfile' => '/core/class/cunits.class.php',
535  'class' => 'CUnits',
536  'method' => 'fetch',
537  'units' => 'size',
538  'dict' => 'DictionaryMeasuringUnits'
539  ),
540  'p.height_units' => array(
541  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
542  'classfile' => '/core/class/cunits.class.php',
543  'class' => 'CUnits',
544  'method' => 'fetch',
545  'units' => 'size',
546  'dict' => 'DictionaryMeasuringUnits'
547  ),
548  'p.surface_units' => array(
549  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
550  'classfile' => '/core/class/cunits.class.php',
551  'class' => 'CUnits',
552  'method' => 'fetch',
553  'units' => 'surface',
554  'dict' => 'DictionaryMeasuringUnits'
555  ),
556  'p.volume_units' => array(
557  'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
558  'classfile' => '/core/class/cunits.class.php',
559  'class' => 'CUnits',
560  'method' => 'fetch',
561  'units' => 'volume',
562  'dict' => 'DictionaryMeasuringUnits'
563  ),
564  'p.fk_country' => array(
565  'rule' => 'fetchidfromcodeid',
566  'classfile' => '/core/class/ccountry.class.php',
567  'class' => 'Ccountry',
568  'method' => 'fetch',
569  'dict' => 'DictionaryCountry'
570  ),
571  'p.finished'=> array(
572  'rule' => 'fetchidfromcodeorlabel',
573  'classfile' => '/core/class/cproductnature.class.php',
574  'class' => 'CProductNature',
575  'method' => 'fetch',
576  'dict' => 'DictionaryProductNature'
577  ),
578  'p.accountancy_code_sell'=>array('rule'=>'accountingaccount'),
579  'p.accountancy_code_sell_intra'=>array('rule'=>'accountingaccount'),
580  'p.accountancy_code_sell_export'=>array('rule'=>'accountingaccount'),
581  'p.accountancy_code_buy'=>array('rule'=>'accountingaccount'),
582  'p.accountancy_code_buy_intra'=>array('rule'=>'accountingaccount'),
583  'p.accountancy_code_buy_export'=>array('rule'=>'accountingaccount'),
584  );
585 
586  $this->import_regex_array[$r] = array(
587  'p.ref' => '[^ ]',
588  'p.price_base_type' => '\AHT\z|\ATTC\z',
589  'p.tosell' => '^[0|1]$',
590  'p.tobuy' => '^[0|1]$',
591  'p.fk_product_type' => '^[0|1]$',
592  'p.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
593  'p.recuperableonly' => '^[0|1]$',
594  );
595 
596  if (!empty($conf->stock->enabled)) {//if Stock module enabled
597  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
598  'p.fk_default_warehouse'=>'DefaultWarehouse',
599  'p.tobatch'=>'ManageLotSerial',
600  'p.seuil_stock_alerte' => 'StockLimit', //lower limit for warning
601  'p.pmp' => 'PMPValue', //weighted average price
602  'p.desiredstock' => 'DesiredStock'//desired stock for replenishment feature
603  ));
604 
605  $this->import_regex_array[$r] = array_merge($this->import_regex_array[$r], array(
606  'p.tobatch' => '^[0|1|2]$'
607  ));
608 
609  $this->import_convertvalue_array[$r] = array_merge($this->import_convertvalue_array[$r], array(
610  'p.fk_default_warehouse' => array(
611  'rule' => 'fetchidfromref',
612  'classfile' => '/product/stock/class/entrepot.class.php',
613  'class' => 'Entrepot',
614  'method' => 'fetch',
615  'element'=> 'Warehouse'
616  )
617  ));
618  }
619 
620  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)) {
621  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.cost_price'=>'CostPrice'));
622  }
623  if (is_object($mysoc) && $usenpr) {
624  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.recuperableonly'=>'NPR'));
625  }
626  if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
627  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax1_tx'=>'LT1', 'p.localtax1_type'=>'LT1Type'));
628  }
629  if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
630  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax2_tx'=>'LT2', 'p.localtax2_type'=>'LT2Type'));
631  }
632  if (!empty($conf->barcode->enabled)) {
633  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.barcode'=>'BarCode'));
634  }
635  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
636  $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
637  }
638 
639  // Add extra fields
640  $import_extrafield_sample = array();
641  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'product' AND entity IN (0, ".$conf->entity.")";
642  $resql = $this->db->query($sql);
643  if ($resql) { // This can fail when class is used on old database (during migration for example)
644  while ($obj = $this->db->fetch_object($resql)) {
645  $fieldname = 'extra.'.$obj->name;
646  $fieldlabel = ucfirst($obj->label);
647  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
648  $import_extrafield_sample[$fieldname] = $fieldlabel;
649  }
650  }
651  // End add extra fields
652  $this->import_fieldshidden_array[$r] = array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
653 
654  // field order as per structure of table llx_product
655  $import_sample = array(
656  'p.ref' => "ref:PREF123456",
657  'p.datec' => dol_print_date(dol_now(), '%Y-%m-%d'),
658  'p.label' => "Product name in default language",
659  'p.description' => "Product description in default language",
660  'p.note_public' => "a public note (free text)",
661  'p.note' => "a private note (free text)",
662  'p.customcode' => 'customs code',
663  'p.fk_country' => 'FR',
664  'p.price' => "100",
665  'p.price_min' => "100",
666  'p.price_ttc' => "110",
667  'p.price_min_ttc' => "110",
668  'p.price_base_type' => "HT (show/use price excl. tax) / TTC (show/use price incl. tax)",
669  'p.tva_tx' => '10', // tax rate eg: 10. Must match numerically one of the tax rates defined for your country'
670  'p.tosell' => "0 (not for sale to customer, eg. raw material) / 1 (for sale)",
671  'p.tobuy' => "0 (not for purchase from supplier, eg. virtual product) / 1 (for purchase)",
672  'p.fk_product_type' => "0 (product) / 1 (service)",
673  'p.duration' => "eg. 365d/12m/1y",
674  'p.url' => 'link to product (no https)',
675  'p.accountancy_code_sell' => "",
676  'p.accountancy_code_sell_intra' => "",
677  'p.accountancy_code_sell_export' => "",
678  'p.accountancy_code_buy' => "",
679  'p.accountancy_code_buy_intra' => "",
680  'p.accountancy_code_buy_export' => "",
681  'p.weight' => "",
682  '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',
683  'p.length' => "",
684  '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',
685  'p.width' => "",
686  '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',
687  'p.height' => "",
688  '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',
689  'p.surface' => "",
690  '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',
691  'p.volume' => "",
692  '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',
693  'p.finished' => '0 (raw material) / 1 (finished goods), matches field "code" in dictionary table "'.MAIN_DB_PREFIX.'c_product_nature"'
694  );
695  //clauses copied from import_fields_array
696  if (!empty($conf->stock->enabled)) {
697  $import_sample = array_merge($import_sample, array(
698  'p.tobatch'=>"0 (don't use) / 1 (use batch) / 2 (use serial number)",
699  'p.seuil_stock_alerte' => '',
700  'p.pmp' => '0',
701  'p.desiredstock' => ''
702  ));
703  }
704  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)) {
705  $import_sample = array_merge($import_sample, array('p.cost_price'=>'90'));
706  }
707  if (is_object($mysoc) && $usenpr) {
708  $import_sample = array_merge($import_sample, array('p.recuperableonly'=>'0'));
709  }
710  if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
711  $import_sample = array_merge($import_sample, array('p.localtax1_tx'=>'', 'p.localtax1_type'=>''));
712  }
713  if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
714  $import_sample = array_merge($import_sample, array('p.localtax2_tx'=>'', 'p.localtax2_type'=>''));
715  }
716  if (!empty($conf->barcode->enabled)) {
717  $import_sample = array_merge($import_sample, array('p.barcode'=>''));
718  }
719  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
720  $import_sample = array_merge(
721  $import_sample,
722  array(
723  '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"'
724  )
725  );
726 
727  $this->import_convertvalue_array[$r] = array_merge($this->import_convertvalue_array[$r], array(
728  'p.fk_unit' => array(
729  'rule' => 'fetchidfromcodeorlabel',
730  'classfile' => '/core/class/cunits.class.php',
731  'class' => 'CUnits',
732  'method' => 'fetch',
733  'dict' => 'DictionaryUnits'
734  )
735  ));
736  }
737  $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
738  $this->import_updatekeys_array[$r] = array('p.ref'=>'Ref');
739  if (!empty($conf->barcode->enabled)) {
740  $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
741  }
742 
743  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
744  // Import suppliers prices (note: this code is duplicated in module Service)
745  $r++;
746  $this->import_code[$r] = $this->rights_class.'_supplierprices';
747  $this->import_label[$r] = "SuppliersPricesOfProductsOrServices"; // Translation key
748  $this->import_icon[$r] = $this->picto;
749  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
750  $this->import_tables_array[$r] = array('sp'=>MAIN_DB_PREFIX.'product_fournisseur_price', 'extra'=>MAIN_DB_PREFIX.'product_fournisseur_price_extrafields');
751  $this->import_tables_creator_array[$r] = array('sp'=>'fk_user');
752  $this->import_fields_array[$r] = array(//field order as per structure of table llx_product_fournisseur_price, without optional fields
753  'sp.fk_product'=>"ProductOrService*",
754  'sp.fk_soc' => "Supplier*",
755  'sp.ref_fourn' => 'SupplierRef*',
756  'sp.quantity' => "QtyMin*",
757  'sp.tva_tx' => 'VATRate',
758  'sp.default_vat_code' => 'VATCode',
759  'sp.delivery_time_days' => 'DeliveryDelay',
760  'sp.supplier_reputation' => 'SupplierReputation'
761  );
762  if (is_object($mysoc) && $usenpr) {
763  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.recuperableonly'=>'VATNPR'));
764  }
765  if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
766  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type'));
767  }
768  if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
769  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type'));
770  }
771  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
772  'sp.price'=>"PriceQtyMinHT*",
773  'sp.unitprice'=>'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty
774  'sp.remise_percent'=>'DiscountQtyMin'
775  ));
776 
777  if (!empty($conf->multicurrency->enabled)) {
778  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
779  'sp.fk_multicurrency'=>'CurrencyCodeId', //ideally this should be automatically obtained from the CurrencyCode on the next line
780  'sp.multicurrency_code'=>'CurrencyCode',
781  'sp.multicurrency_tx'=>'CurrencyRate',
782  'sp.multicurrency_unitprice'=>'CurrencyUnitPrice',
783  'sp.multicurrency_price'=>'CurrencyPrice',
784  ));
785  }
786 
787  if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
788  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.packaging' => 'PackagingForThisProduct'));
789  }
790 
791  // Add extra fields
792  $import_extrafield_sample = array();
793  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'product_fournisseur_price' AND entity IN (0, ".$conf->entity.")";
794  $resql = $this->db->query($sql);
795  if ($resql) { // This can fail when class is used on old database (during migration for example)
796  while ($obj = $this->db->fetch_object($resql)) {
797  $fieldname = 'extra.'.$obj->name;
798  $fieldlabel = ucfirst($obj->label);
799  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
800  $import_extrafield_sample[$fieldname] = $fieldlabel;
801  }
802  }
803  // End add extra fields
804  $this->import_fieldshidden_array[$r] = array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product_fournisseur_price'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
805 
806  $this->import_convertvalue_array[$r] = array(
807  'sp.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'),
808  'sp.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
809  );
810 
811  $this->import_examplevalues_array[$r] = array(
812  'sp.fk_product' => "ref:PRODUCT_REF or id:123456",
813  'sp.fk_soc' => "My Supplier",
814  'sp.ref_fourn' => "XYZ-F123456",
815  'sp.quantity' => "5",
816  'sp.tva_tx' => '10',
817  'sp.price'=>"50",
818  'sp.unitprice'=>'50',
819  'sp.remise_percent'=>'0',
820  'sp.default_vat_code' => '',
821  'sp.delivery_time_days' => '5',
822  'sp.supplier_reputation' => 'FAVORITE / NOTTHGOOD / DONOTORDER'
823  );
824  if (is_object($mysoc) && $usenpr) {
825  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.recuperableonly'=>''));
826  }
827  if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
828  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax1_tx'=>'LT1', 'sp.localtax1_type'=>'LT1Type'));
829  }
830  if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
831  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax2_tx'=>'LT2', 'sp.localtax2_type'=>'LT2Type'));
832  }
833  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
834  'sp.price' => "50.00",
835  'sp.unitprice' => '10',
836  // TODO Make this field not required and calculate it from price and qty
837  'sp.remise_percent' => '20'
838  ));
839  if (!empty($conf->multicurrency->enabled)) {
840  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
841  'sp.fk_multicurrency'=>'eg: 2, rowid for code of multicurrency currency',
842  'sp.multicurrency_code'=>'GBP',
843  'sp.multicurrency_tx'=>'1.12345',
844  'sp.multicurrency_unitprice'=>'',
845  // TODO Make this field not required and calculate it from price and qty
846  'sp.multicurrency_price'=>''
847  ));
848  }
849  if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
850  $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
851  'sp.packaging'=>'10',
852  ));
853  }
854 
855  $this->import_updatekeys_array[$r] = array('sp.fk_product'=>'ProductOrService', 'sp.ref_fourn'=>'SupplierRef', 'sp.fk_soc'=>'Supplier');
856  }
857 
858  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
859  // Import products multiprices
860  $r++;
861  $this->import_code[$r] = $this->rights_class.'_multiprice';
862  $this->import_label[$r] = "ProductsOrServiceMultiPrice"; // Translation key
863  $this->import_icon[$r] = $this->picto;
864  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
865  $this->import_tables_array[$r] = array('pr'=>MAIN_DB_PREFIX.'product_price');
866  $this->import_tables_creator_array[$r] = array('pr'=>'fk_user_author'); // Fields to store import user id
867  $this->import_fields_array[$r] = array('pr.fk_product'=>"ProductOrService*",
868  'pr.price_base_type'=>"PriceBase", 'pr.price_level'=>"PriceLevel",
869  'pr.price'=>"PriceLevelUnitPriceHT", 'pr.price_ttc'=>"PriceLevelUnitPriceTTC",
870  'pr.price_min'=>"MinPriceLevelUnitPriceHT", 'pr.price_min_ttc'=>"MinPriceLevelUnitPriceTTC",
871  'pr.date_price'=>'DateCreation*');
872  if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
873  $this->import_fields_array[$r]['pr.tva_tx'] = 'VATRate';
874  }
875  if (is_object($mysoc) && $usenpr) {
876  $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('pr.recuperableonly'=>'NPR'));
877  }
878  $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]$');
879  $this->import_convertvalue_array[$r] = array(
880  'pr.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
881  );
882  $this->import_examplevalues_array[$r] = array('pr.fk_product'=>"ref:PRODUCT_REF or id:123456",
883  'pr.price_base_type'=>"HT (for excl tax) or TTC (for inc tax)", 'pr.price_level'=>"1",
884  'pr.price'=>"100", 'pr.price_ttc'=>"110",
885  'pr.price_min'=>"100", 'pr.price_min_ttc'=>"110",
886  'pr.tva_tx'=>'20',
887  'pr.recuperableonly'=>'0',
888  'pr.date_price'=>'2020-12-31');
889  }
890 
891  if (!empty($conf->global->MAIN_MULTILANGS)) {
892  // Import translations of product names and descriptions
893  $r++;
894  $this->import_code[$r] = $this->rights_class.'_languages';
895  $this->import_label[$r] = "ProductsOrServicesTranslations";
896  $this->import_icon[$r] = $this->picto;
897  $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
898  $this->import_tables_array[$r] = array('l'=>MAIN_DB_PREFIX.'product_lang');
899  // multiline translation, one line per translation
900  $this->import_fields_array[$r] = array('l.fk_product'=>'ProductOrService*', 'l.lang'=>'Language*', 'l.label'=>'TranslatedLabel', 'l.description'=>'TranslatedDescription');
901  //$this->import_fields_array[$r]['l.note']='TranslatedNote';
902  $this->import_convertvalue_array[$r] = array(
903  'l.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
904  );
905  $this->import_examplevalues_array[$r] = array('l.fk_product'=>'ref:PRODUCT_REF or id:123456', 'l.lang'=>'en_US', 'l.label'=>'Label in en_US', 'l.description'=>'Desc in en_US');
906  $this->import_updatekeys_array[$r] = array('l.fk_product'=>'ProductOrService', 'l.lang'=>'Language');
907  }
908  }
909 
910 
919  public function init($options = '')
920  {
921  $this->remove($options);
922 
923  $sql = array();
924 
925  return $this->_init($sql, $options);
926  }
927 }
modProduct
Class descriptor of Product module.
Definition: modProduct.class.php:39
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
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
getEntity
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Definition: functions.lib.php:148
DolibarrModules\_init
_init($array_sql, $options='')
Enables a module.
Definition: DolibarrModules.class.php:383
modProduct\__construct
__construct($db)
Constructor.
Definition: modProduct.class.php:46
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
modProduct\init
init($options='')
Function called when module is enabled.
Definition: modProduct.class.php:919