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