dolibarr 25.0.0-alpha
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 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
12 * Copyright (C) 2025-2026 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2025 Pierre Ardoin <developpeur@lesmetiersdubatiment.fr>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
36include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
37
38
43{
49 public function __construct($db)
50 {
51 global $conf, $mysoc;
52
53 $this->db = $db;
54 $this->numero = 50;
55
56 $this->family = "products";
57 $this->module_position = '26';
58 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
59 $this->name = preg_replace('/^mod/i', '', get_class($this));
60 $this->description = "Product management";
61
62 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
63 $this->version = 'dolibarr';
64
65 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
66 $this->picto = 'product';
67
68 // Data directories to create when module is enabled
69 $this->dirs = array("/product/temp");
70
71 // Dependencies
72 $this->hidden = false; // A condition to hide module
73 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
74 $this->requiredby = array("modStock", "modBarcode", "modProductBatch", "modVariants", "modBom"); // List of module ids to disable if this one is disabled
75 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
76 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
77
78 // Config pages
79 $this->config_page_url = array("product.php@product");
80 $this->langfiles = array("products", "companies", "stocks", "bills");
81
82 // Constants
83 $this->const = [
84 [
85 "PRODUCT_CODEPRODUCT_ADDON",
86 "chaine",
87 "mod_codeproduct_leopard",
88 'Module to control product codes',
89 0,
90 ],
91 [
92
93 "PRODUCT_PRICE_UNIQ",
94 "chaine",
95 "1",
96 'pricing rule by default',
97 0,
98 ],
99 /*[
100 "PRODUCT_ADDON_PDF",
101 "chaine",
102 "standard",
103 'Default module for document generation',
104 0,
105 ],*/
106 ];
107
108 // Boxes
109 $this->boxes = array(
110 0 => array('file' => 'box_produits.php', 'enabledbydefaulton' => 'Home'),
111 1 => array('file' => 'box_produits_alerte_stock.php', 'enabledbydefaulton' => 'Home'),
112 2 => array('file' => 'box_graph_product_distribution.php', 'enabledbydefaulton' => 'Home')
113 );
114
115 // Permissions
116 $this->rights = array();
117 $this->rights_class = 'produit';
118 $r = 0;
119
120 $this->rights[$r][0] = 31; // Permission id (must not be already used)
121 $this->rights[$r][1] = 'Read products'; // Permission label
122 $this->rights[$r][2] = 'r'; // Permission type (deprecated)
123 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
124 $this->rights[$r][4] = 'lire';
125 $r++;
126
127 $this->rights[$r][0] = 32; // Permission id (must not be already used)
128 $this->rights[$r][1] = 'Create/modify products'; // Permission label
129 $this->rights[$r][2] = 'w'; // Permission type (deprecated)
130 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
131 $this->rights[$r][4] = 'creer';
132 $r++;
133
134 $this->rights[$r][0] = 33; // Permission id (must not be already used)
135 $this->rights[$r][1] = 'Read prices products'; // Permission label
136 $this->rights[$r][2] = 'w'; // Permission type (deprecated)
137 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
138 $this->rights[$r][4] = 'product_advance';
139 $this->rights[$r][5] = 'read_prices';
140 $r++;
141
142 $this->rights[$r][0] = 35; // Permission id (must not be already used)
143 $this->rights[$r][1] = 'Read supplier prices'; // Permission label
144 $this->rights[$r][2] = 'w'; // Permission type (deprecated)
145 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
146 $this->rights[$r][4] = 'product_advance';
147 $this->rights[$r][5] = 'read_supplier_prices';
148 $r++;
149
150 // EN: Advanced permission to write supplier prices
151 $this->rights[$r][0] = 36; // Permission id (must not be already used)
152 $this->rights[$r][1] = 'Write supplier prices'; // Permission label
153 $this->rights[$r][2] = 'w'; // Permission type (deprecated)
154 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
155 $this->rights[$r][4] = 'product_advance';
156 $this->rights[$r][5] = 'write_supplier_prices';
157 $r++;
158
159 $this->rights[$r][0] = 34; // Permission id (must not be already used)
160 $this->rights[$r][1] = 'Delete products'; // Permission label
161 $this->rights[$r][2] = 'd'; // Permission type (deprecated)
162 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
163 $this->rights[$r][4] = 'supprimer';
164 $r++;
165
166 $this->rights[$r][0] = 38; // Must be same permission than in service module
167 $this->rights[$r][1] = 'Export products';
168 $this->rights[$r][2] = 'r';
169 $this->rights[$r][3] = 0;
170 $this->rights[$r][4] = 'export';
171 $r++;
172
173 $this->rights[$r][0] = 39;
174 $this->rights[$r][1] = 'Ignore minimum price';
175 $this->rights[$r][2] = 'r';
176 $this->rights[$r][3] = 0;
177 $this->rights[$r][4] = 'ignore_price_min_advance';
178 $r++;
179
180 // Menus
181 //-------
182
183 $this->menu = 1; // This module adds menu entries. They are coded into menu manager.
184 /* We can't enable this here because it must be enabled in both product and service module and this creates duplicate inserts
185 $r = 0;
186 $this->menu[$r] = array(
187 // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
188 'fk_menu' => 'fk_mainmenu=home,fk_leftmenu=admintools',
189 // This is a Left menu entry
190 'type' => 'left',
191 'titre' => 'ProductVatMassChange',
192 'url' => '/product/admin/product_tools.php?mainmenu=home&leftmenu=admintools',
193 // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
194 'langs' => 'products',
195 'position' => 300,
196 // 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.
197 'enabled' => 'isModEnabled("product") && preg_match(\'/^(admintools|all)/\',$leftmenu)',
198 // Use 'perms'=>'$user->hasRight("mymodule","level1","level2")' if you want your menu with a permission rules
199 'perms' => '1',
200 'target' => '',
201 // 0=Menu for internal users, 1=external users, 2=both
202 'user' => 0
203 );
204 $r++;
205 */
206
207 $usenpr = 0;
208 if (is_object($mysoc)) {
209 $usenpr = $mysoc->useNPR();
210 }
211
212 // Exports
213 //--------
214 $r = 0;
215
216 $alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
217
218 $r++;
219 $this->export_code[$r] = $this->rights_class.'_'.$r;
220 $this->export_label[$r] = "Products"; // Translation key (used only if key ExportDataset_xxx_z not found)
221 $this->export_permission[$r] = array(array("produit", "export"));
222 $this->export_fields_array[$r] = array(
223 'p.rowid' => "Id", 'p.ref' => "Ref", 'p.label' => "Label",
224 'p.fk_product_type' => 'Type', 'p.tosell' => "OnSell", 'p.tobuy' => "OnBuy",
225 'p.description' => "Description", 'p.url' => "PublicUrl",
226 'p.customcode' => 'CustomsCode', 'p.fk_country' => 'IDCountry',
227 $alias_product_perentity . '.accountancy_code_sell' => "ProductAccountancySellCode", $alias_product_perentity . '.accountancy_code_sell_intra' => "ProductAccountancySellIntraCode",
228 $alias_product_perentity . '.accountancy_code_sell_export' => "ProductAccountancySellExportCode", $alias_product_perentity . '.accountancy_code_buy' => "ProductAccountancyBuyCode",
229 $alias_product_perentity . '.accountancy_code_buy_intra' => "ProductAccountancyBuyIntraCode", $alias_product_perentity . '.accountancy_code_buy_export' => "ProductAccountancyBuyExportCode",
230 'p.note' => "NotePrivate", 'p.note_public' => 'NotePublic',
231 '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",
232 'p.surface' => "Surface", 'p.surface_units' => "SurfaceUnits", 'p.volume' => "Volume", 'p.volume_units' => "VolumeUnits",
233 'p.duration' => "Duration",
234 'p.finished' => 'Nature',
235 'p.price_base_type' => "PriceBase", 'p.price' => "UnitPriceHT", 'p.price_ttc' => "UnitPriceTTC",
236 'p.price_min' => "MinPriceHT",'p.price_min_ttc' => "MinPriceTTC",
237 'p.tva_tx' => 'VATRate',
238 'p.datec' => 'DateCreation', 'p.tms' => 'DateModification'
239 );
240 if (is_object($mysoc) && $usenpr) {
241 $this->export_fields_array[$r]['p.recuperableonly'] = 'NPR';
242 }
243 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice") || isModEnabled('margin')) {
244 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.cost_price' => 'CostPrice'));
245 }
246 if (isModEnabled('stock')) {
247 $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'));
248 }
249 if (isModEnabled('barcode')) {
250 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode' => 'BarCode'));
251 }
252 $keyforselect = 'product';
253 $keyforelement = 'product';
254 $keyforaliasextra = 'extra';
255 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
256 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
257 $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'));
258 }
259 if (getDolGlobalString('EXPORTTOOL_CATEGORIES')) {
260 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('group_concat(cat.label)' => 'Categories'));
261 }
262 if (getDolGlobalInt('MAIN_MULTILANGS')) {
263 $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'));
264 }
265 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
266 $this->export_fields_array[$r]['p.fk_unit'] = 'Unit';
267 }
268 $this->export_TypeFields_array[$r] = array(
269 'p.ref' => "Text", 'p.label' => "Text",
270 'p.fk_product_type' => 'Numeric', 'p.tosell' => "Boolean", 'p.tobuy' => "Boolean",
271 'p.description' => "Text", 'p.url' => "Text",
272 $alias_product_perentity . '.accountancy_code_sell' => "Text", $alias_product_perentity . '.accountancy_code_sell_intra' => "Text", $alias_product_perentity . '.accountancy_code_sell_export' => "Text",
273 $alias_product_perentity . '.accountancy_code_buy' => "Text", $alias_product_perentity . '.accountancy_code_buy_intra' => "Text", $alias_product_perentity . '.accountancy_code_buy_export' => "Text",
274 'p.note' => "Text", 'p.note_public' => "Text",
275 'p.weight' => "Numeric", 'p.length' => "Numeric", 'p.width' => "Numeric", 'p.height' => "Numeric", 'p.surface' => "Numeric", 'p.volume' => "Numeric",
276 'p.customcode' => 'Text',
277 'p.duration' => "Text",
278 'p.finished' => 'Numeric',
279 'p.price_base_type' => "Text", 'p.price' => "Numeric", 'p.price_ttc' => "Numeric",
280 'p.price_min' => "Numeric", 'p.price_min_ttc' => "Numeric",
281 'p.tva_tx' => 'Numeric',
282 'p.datec' => 'Date', 'p.tms' => 'Date'
283 );
284 if (isModEnabled('stock')) {
285 $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'));
286 }
287 if (isModEnabled('barcode')) {
288 $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode' => 'Text'));
289 }
290 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
291 $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'));
292 }
293 if (getDolGlobalInt('MAIN_MULTILANGS')) {
294 $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'));
295 }
296 if (getDolGlobalString('EXPORTTOOL_CATEGORIES')) {
297 $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array("group_concat(cat.label)" => 'Text'));
298 }
299 $this->export_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
300 if (getDolGlobalString('EXPORTTOOL_CATEGORIES')) {
301 $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array("group_concat(cat.label)" => 'category'));
302 }
303 if (isModEnabled('stock')) {
304 $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock' => 'product', 'p.pmp' => 'product'));
305 }
306 if (isModEnabled('barcode')) {
307 $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode' => 'product'));
308 }
309 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
310 $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'));
311 }
312 if (getDolGlobalInt('MAIN_MULTILANGS')) {
313 $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'));
314 }
315 if (getDolGlobalString('EXPORTTOOL_CATEGORIES')) {
316 $this->export_dependencies_array[$r] = array('category' => 'p.rowid');
317 }
318 if (isModEnabled('stock')) {
319 $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.stock' => 'product', 'p.pmp' => 'product'));
320 }
321 if (isModEnabled('barcode')) {
322 $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode' => 'product'));
323 }
324 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
325 $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'));
326 }
327 if (getDolGlobalInt('MAIN_MULTILANGS')) {
328 $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'));
329 }
330 if (getDolGlobalString('EXPORTTOOL_CATEGORIES')) {
331 $this->export_dependencies_array[$r] = array('category' => 'p.rowid');
332 }
333 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
334 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
335 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
336 $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);
337 }
338 if (getDolGlobalString('EXPORTTOOL_CATEGORIES')) {
339 $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';
340 }
341 if (getDolGlobalInt('MAIN_MULTILANGS')) {
342 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lang as l ON l.fk_product = p.rowid';
343 }
344 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object';
345 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
346 $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';
347 }
348 if (isModEnabled('stock')) {
349 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e ON e.rowid = p.fk_default_warehouse';
350 }
351 $this->export_sql_end[$r] .= ' WHERE p.fk_product_type = 0 AND p.entity IN ('.getEntity('product').')';
352 if (getDolGlobalString('EXPORTTOOL_CATEGORIES')) {
353 $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"
354 }
355
356 if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
357 // Exports product multiprice
358 $r++;
359 $this->export_code[$r] = $this->rights_class.'_'.$r;
360 $this->export_label[$r] = "ProductsMultiPrice"; // Translation key (used only if key ExportDataset_xxx_z not found)
361 $this->export_permission[$r] = array(array("produit", "export"));
362 $this->export_fields_array[$r] = array(
363 'p.rowid' => "Id", 'p.ref' => "Ref", 'p.label' => "Label",
364 'pr.price_base_type' => "PriceBase", 'pr.price_level' => "PriceLevel",
365 'pr.price' => "PriceLevelUnitPriceHT", 'pr.price_ttc' => "PriceLevelUnitPriceTTC",
366 'pr.price_min' => "MinPriceLevelUnitPriceHT", 'pr.price_min_ttc' => "MinPriceLevelUnitPriceTTC",
367 'pr.tva_tx' => 'PriceLevelVATRate',
368 'pr.date_price' => 'DateCreation'
369 );
370 if (is_object($mysoc) && $usenpr) {
371 $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
372 }
373 //$this->export_TypeFields_array[$r]=array(
374 // 'p.ref'=>"Text",'p.label'=>"Text",'p.description'=>"Text",'p.url'=>"Text",'p.accountancy_code_sell'=>"Text",'p.accountancy_code_buy'=>"Text",
375 // 'p.note'=>"Text",'p.length'=>"Numeric",'p.surface'=>"Numeric",'p.volume'=>"Numeric",'p.weight'=>"Numeric",'p.customcode'=>'Text',
376 // 'p.price_base_type'=>"Text",'p.price'=>"Numeric",'p.price_ttc'=>"Numeric",'p.tva_tx'=>'Numeric','p.tosell'=>"Boolean",'p.tobuy'=>"Boolean",
377 // 'p.datec'=>'Date','p.tms'=>'Date'
378 //);
379 $this->export_entities_array[$r] = array(
380 'p.rowid' => "product", 'p.ref' => "product", 'p.label' => "Label",
381 'pr.price_base_type' => "product", 'pr.price_level' => "product", 'pr.price' => "product",
382 'pr.price_ttc' => "product",
383 'pr.price_min' => "product", 'pr.price_min_ttc' => "product",
384 'pr.tva_tx' => 'product',
385 'pr.recuperableonly' => 'product',
386 'pr.date_price' => "product"
387 );
388 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
389 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
390 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.((int) $conf->entity); // export prices only for the current entity
391 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_price_extrafields as extra ON pr.rowid = extra.fk_object';
392 $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
393 $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.price_level = pr.price_level AND pr2.entity IN ('.getEntity('product').'))'; // export only latest prices not full history
394 // $this->export_sql_end[$r] .= ' ORDER BY p.ref, pr.price_level';
395 global $keyforselect, $keyforelement, $keyforaliasextra;
396 $keyforselect = 'product_price';
397 $keyforelement = 'product';
398 $keyforaliasextra = 'extra';
399 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
400 }
401
402 if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
403 // Exports product multiprice
404 $r++;
405 $this->export_code[$r] = $this->rights_class.'_'.$r;
406 $this->export_label[$r] = "ProductsPricePerCustomer"; // Translation key (used only if key ExportDataset_xxx_z not found)
407 $this->export_permission[$r] = array(array("produit", "export"));
408 $this->export_fields_array[$r] = array('p.rowid' => "Id", 'p.ref' => "Ref", 'p.label' => "Label",
409 's.nom' => 'ThirdParty',
410 's.code_client' => 'CodeClient',
411 'pr.date_begin' => "AppliedPricesFrom",
412 'pr.date_end' => "AppliedPricesTo",
413 'pr.price_base_type' => "PriceBase",
414 'pr.price' => "PriceUnitPriceHT", 'pr.price_ttc' => "PriceUnitPriceTTC",
415 'pr.price_min' => "MinPriceUnitPriceHT", 'pr.price_min_ttc' => "MinPriceUnitPriceTTC",
416 'pr.tva_tx' => 'PriceVATRate',
417 'pr.default_vat_code' => 'PriceVATCode',
418 'pr.discount_percent' => 'Discount',
419 'pr.datec' => 'DateCreation');
420 if (is_object($mysoc) && $usenpr) {
421 $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
422 }
423 $this->export_entities_array[$r] = array('p.rowid' => "product", 'p.ref' => "product", 'p.label' => "Label",
424 's.nom' => 'company',
425 's.code_client' => 'company',
426 'pr.date_begin' => "product",
427 'pr.date_end' => "product",
428 'pr.price_base_type' => "product", 'pr.price' => "product",
429 'pr.price_ttc' => "product",
430 'pr.price_min' => "product", 'pr.price_min_ttc' => "product",
431 'pr.tva_tx' => 'product',
432 'pr.default_vat_code' => 'product',
433 'pr.discount_percent' => 'product',
434 'pr.recuperableonly' => 'product',
435 'pr.datec' => "product");
436 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
437 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
438 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_customer_price as pr ON p.rowid = pr.fk_product AND pr.entity = '.((int) $conf->entity); // export prices only for the current entity
439 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON pr.fk_soc = s.rowid';
440 $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
441 }
442
443 if (getDolGlobalString('PRODUIT_SOUSPRODUITS')) {
444 // Exports virtual products
445 $r++;
446 $this->export_code[$r] = $this->rights_class.'_'.$r;
447 $this->export_label[$r] = "AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found)
448 $this->export_permission[$r] = array(array("produit", "export"));
449 $this->export_fields_array[$r] = array(
450 'p.rowid' => "Id", 'p.ref' => "Ref", 'p.label' => "Label", 'p.description' => "Description", 'p.url' => "PublicUrl",
451 $alias_product_perentity . '.accountancy_code_sell' => "ProductAccountancySellCode", $alias_product_perentity . '.accountancy_code_sell_intra' => "ProductAccountancySellIntraCode",
452 $alias_product_perentity . '.accountancy_code_sell_export' => "ProductAccountancySellExportCode", $alias_product_perentity . '.accountancy_code_buy' => "ProductAccountancyBuyCode",
453 $alias_product_perentity . '.accountancy_code_buy_intra' => "ProductAccountancyBuyIntraCode", $alias_product_perentity . '.accountancy_code_buy_export' => "ProductAccountancyBuyExportCode",
454 'p.note' => "NotePrivate", 'p.note_public' => 'NotePublic',
455 'p.weight' => "Weight", 'p.length' => "Length", 'p.surface' => "Surface", 'p.volume' => "Volume", 'p.customcode' => 'CustomsCode',
456 'p.price_base_type' => "PriceBase", 'p.price' => "UnitPriceHT", 'p.price_ttc' => "UnitPriceTTC", 'p.tva_tx' => 'VATRate', 'p.tosell' => "OnSell",
457 'p.tobuy' => "OnBuy", 'p.datec' => 'DateCreation', 'p.tms' => 'DateModification'
458 );
459 if (isModEnabled('stock')) {
460 $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'));
461 }
462 if (isModEnabled('barcode')) {
463 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode' => 'BarCode'));
464 }
465 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('pa.qty' => 'Qty', 'pa.incdec' => 'ComposedProductIncDecStock'));
466 $this->export_TypeFields_array[$r] = array(
467 'p.ref' => "Text", 'p.label' => "Text", 'p.description' => "Text", 'p.url' => "Text",
468 $alias_product_perentity . '.accountancy_code_sell' => "Text", $alias_product_perentity . '.accountancy_code_sell_intra' => "Text", $alias_product_perentity . '.accountancy_code_sell_export' => "Text",
469 $alias_product_perentity . '.accountancy_code_buy' => "Text", $alias_product_perentity . '.accountancy_code_buy_intra' => "Text", $alias_product_perentity . '.accountancy_code_buy_export' => "Text",
470 'p.note' => "Text", 'p.note_public' => "Text",
471 'p.weight' => "Numeric", 'p.length' => "Numeric", 'p.surface' => "Numeric", 'p.volume' => "Numeric", 'p.customcode' => 'Text',
472 'p.price_base_type' => "Text", 'p.price' => "Numeric", 'p.price_ttc' => "Numeric", 'p.tva_tx' => 'Numeric', 'p.tosell' => "Boolean", 'p.tobuy' => "Boolean",
473 'p.datec' => 'Date', 'p.tms' => 'Date'
474 );
475 if (isModEnabled('stock')) {
476 $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'));
477 }
478 if (isModEnabled('barcode')) {
479 $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode' => 'Text'));
480 }
481 $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('pa.qty' => 'Numeric'));
482 $this->export_entities_array[$r] = array(
483 'p.rowid' => "virtualproduct", 'p.ref' => "virtualproduct", 'p.label' => "virtualproduct", 'p.description' => "virtualproduct", 'p.url' => "virtualproduct",
484 $alias_product_perentity . '.accountancy_code_sell' => 'virtualproduct', $alias_product_perentity . '.accountancy_code_sell_intra' => 'virtualproduct', $alias_product_perentity . '.accountancy_code_sell_export' => 'virtualproduct',
485 $alias_product_perentity . '.accountancy_code_buy' => 'virtualproduct', $alias_product_perentity . '.accountancy_code_buy_intra' => 'virtualproduct', $alias_product_perentity . '.accountancy_code_buy_export' => 'virtualproduct',
486 'p.note' => "virtualproduct", 'p.length' => "virtualproduct",
487 'p.surface' => "virtualproduct", 'p.volume' => "virtualproduct", 'p.weight' => "virtualproduct", 'p.customcode' => 'virtualproduct',
488 'p.price_base_type' => "virtualproduct", 'p.price' => "virtualproduct", 'p.price_ttc' => "virtualproduct", 'p.tva_tx' => "virtualproduct",
489 'p.tosell' => "virtualproduct", 'p.tobuy' => "virtualproduct", 'p.datec' => "virtualproduct", 'p.tms' => "virtualproduct"
490 );
491 if (isModEnabled('stock')) {
492 $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'));
493 }
494 if (isModEnabled('barcode')) {
495 $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode' => 'virtualproduct'));
496 }
497 $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('pa.qty' => "subproduct", 'pa.incdec' => 'subproduct'));
498 $keyforselect = 'product';
499 $keyforelement = 'product';
500 $keyforaliasextra = 'extra';
501 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
502 $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"));
503 $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"));
504 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
505 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
506 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
507 $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);
508 }
509 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
510 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
511 $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
512 $this->export_sql_end[$r] .= ' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
513 }
514
515 // Imports
516 //--------
517 $r = 0;
518
519 // Import list of products
520
521 $r++;
522 $this->import_code[$r] = $this->rights_class.'_'.$r;
523 $this->import_label[$r] = "Products"; // Translation key
524 $this->import_icon[$r] = $this->picto;
525 $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
526 $this->import_tables_array[$r] = array('p' => MAIN_DB_PREFIX.'product', 'extra' => MAIN_DB_PREFIX.'product_extrafields');
527 $this->import_tables_creator_array[$r] = array('p' => 'fk_user_author'); // Fields to store import user id
528 $this->import_fields_array[$r] = array(
529 'p.ref' => "Ref*",
530 'p.label' => "Label*",
531 'p.fk_product_type' => "Type*",
532 'p.tosell' => "OnSell*",
533 'p.tobuy' => "OnBuy*",
534 'p.description' => "Description",
535 'p.url' => "PublicUrl",
536 'p.customcode' => 'CustomsCode',
537 'p.fk_country' => 'CountryCode',
538 'p.accountancy_code_sell' => "ProductAccountancySellCode",
539 'p.accountancy_code_sell_intra' => "ProductAccountancySellIntraCode",
540 'p.accountancy_code_sell_export' => "ProductAccountancySellExportCode",
541 'p.accountancy_code_buy' => "ProductAccountancyBuyCode",
542 'p.accountancy_code_buy_intra' => "ProductAccountancyBuyIntraCode",
543 'p.accountancy_code_buy_export' => "ProductAccountancyBuyExportCode",
544 'p.note_public' => "NotePublic",
545 'p.note' => "NotePrivate",
546 'p.weight' => "Weight",
547 'p.weight_units' => "WeightUnits",
548 'p.length' => "Length",
549 'p.length_units' => "LengthUnits",
550 'p.width' => "Width",
551 'p.width_units' => "WidthUnits",
552 'p.height' => "Height",
553 'p.height_units' => "HeightUnits",
554 'p.surface' => "Surface",
555 'p.surface_units' => "SurfaceUnits",
556 'p.volume' => "Volume",
557 'p.volume_units' => "VolumeUnits",
558 'p.duration' => "Duration", //duration of service
559 'p.finished' => 'Nature',
560 'p.price' => "SellingPriceHT", //without
561 'p.price_min' => "MinPrice",
562 'p.price_ttc' => "SellingPriceTTC", //with tax
563 'p.price_min_ttc' => "SellingMinPriceTTC",
564 'p.price_base_type' => "PriceBaseType*", //price base: with-tax (TTC) or without (HT) tax. Displays accordingly in Product card
565 'p.tva_tx' => 'VATRate',
566 'p.default_vat_code' => 'VATCode', // to use the correct vat line when there is several lines with the same vat rate for your country
567 'p.datec' => 'DateCreation',
568 'p.cost_price' => "CostPrice"
569 );
570
571 $this->import_convertvalue_array[$r] = array(
572 'p.weight_units' => array(
573 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
574 'classfile' => '/core/class/cunits.class.php',
575 'class' => 'CUnits',
576 'method' => 'fetch',
577 'units' => 'weight',
578 'dict' => 'DictionaryMeasuringUnits'
579 ),
580 'p.length_units' => array(
581 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
582 'classfile' => '/core/class/cunits.class.php',
583 'class' => 'CUnits',
584 'method' => 'fetch',
585 'units' => 'size',
586 'dict' => 'DictionaryMeasuringUnits'
587 ),
588 'p.width_units' => array(
589 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
590 'classfile' => '/core/class/cunits.class.php',
591 'class' => 'CUnits',
592 'method' => 'fetch',
593 'units' => 'size',
594 'dict' => 'DictionaryMeasuringUnits'
595 ),
596 'p.height_units' => array(
597 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
598 'classfile' => '/core/class/cunits.class.php',
599 'class' => 'CUnits',
600 'method' => 'fetch',
601 'units' => 'size',
602 'dict' => 'DictionaryMeasuringUnits'
603 ),
604 'p.surface_units' => array(
605 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
606 'classfile' => '/core/class/cunits.class.php',
607 'class' => 'CUnits',
608 'method' => 'fetch',
609 'units' => 'surface',
610 'dict' => 'DictionaryMeasuringUnits'
611 ),
612 'p.volume_units' => array(
613 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
614 'classfile' => '/core/class/cunits.class.php',
615 'class' => 'CUnits',
616 'method' => 'fetch',
617 'units' => 'volume',
618 'dict' => 'DictionaryMeasuringUnits'
619 ),
620 'p.fk_country' => array(
621 'rule' => 'fetchidfromcodeid',
622 'classfile' => '/core/class/ccountry.class.php',
623 'class' => 'Ccountry',
624 'method' => 'fetch',
625 'dict' => 'DictionaryCountry'
626 ),
627 'p.finished' => array(
628 'rule' => 'fetchidfromcodeorlabel',
629 'classfile' => '/core/class/cproductnature.class.php',
630 'class' => 'CProductNature',
631 'method' => 'fetch',
632 'dict' => 'DictionaryProductNature'
633 ),
634 'p.accountancy_code_sell' => array('rule' => 'accountingaccount'),
635 'p.accountancy_code_sell_intra' => array('rule' => 'accountingaccount'),
636 'p.accountancy_code_sell_export' => array('rule' => 'accountingaccount'),
637 'p.accountancy_code_buy' => array('rule' => 'accountingaccount'),
638 'p.accountancy_code_buy_intra' => array('rule' => 'accountingaccount'),
639 'p.accountancy_code_buy_export' => array('rule' => 'accountingaccount'),
640 );
641
642 $this->import_regex_array[$r] = array(
643 'p.ref' => '[^ ]',
644 'p.price_base_type' => '\AHT\z|\ATTC\z',
645 'p.tosell' => '^[0|1]$',
646 'p.tobuy' => '^[0|1]$',
647 'p.fk_product_type' => '^[0|1]$',
648 'p.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
649 'p.recuperableonly' => '^[0|1]$',
650 );
651
652 // Complete if Stock module enabled
653 if (isModEnabled('stock')) {
654 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
655 'p.fk_default_warehouse' => 'DefaultWarehouse',
656 'p.tobatch' => 'ManageLotSerial',
657 'p.sell_or_eat_by_mandatory' => 'SellOrEatByMandatory',
658 'p.seuil_stock_alerte' => 'StockLimit', //lower limit for warning
659 'p.pmp' => 'PMPValue', //weighted average price
660 'p.desiredstock' => 'DesiredStock'//desired stock for replenishment feature
661 ));
662
663 $this->import_regex_array[$r] = array_merge($this->import_regex_array[$r], array(
664 'p.tobatch' => '^[0|1|2]$',
665 'p.sell_or_eat_by_mandatory' => '^[0-3]$'
666 ));
667
668 $this->import_convertvalue_array[$r] = array_merge($this->import_convertvalue_array[$r], array(
669 'p.fk_default_warehouse' => array(
670 'rule' => 'fetchidfromref',
671 'classfile' => '/product/stock/class/entrepot.class.php',
672 'class' => 'Entrepot',
673 'method' => 'fetch',
674 'element' => 'Warehouse'
675 )
676 ));
677 }
678
679 if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
680 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
681 'p.packaging' => 'PackagingForThisProductSell',
682 ));
683 }
684
685 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice") || isModEnabled('margin')) {
686 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.cost_price' => 'CostPrice'));
687 }
688 if (is_object($mysoc) && $usenpr) {
689 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.recuperableonly' => 'NPR'));
690 }
691 if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
692 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax1_tx' => 'LT1', 'p.localtax1_type' => 'LT1Type'));
693 }
694 if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
695 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax2_tx' => 'LT2', 'p.localtax2_type' => 'LT2Type'));
696 }
697 if (isModEnabled('barcode')) {
698 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.barcode' => 'BarCode'));
699 }
700 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
701 $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
702 }
703
704 // Add extra fields
705 $import_extrafield_sample = array();
706 $keyforselect = 'product';
707 $keyforelement = 'product';
708 $keyforaliasextra = 'extra';
709 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
710 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
711
712 // field order as per structure of table llx_product
713 $import_sample = array(
714 'p.ref' => "ref:PREF123456",
715 'p.datec' => dol_print_date(dol_now(), '%Y-%m-%d'),
716 'p.label' => "Product name in default language",
717 'p.description' => "Product description in default language",
718 'p.note_public' => "a public note (free text)",
719 'p.note' => "a private note (free text)",
720 'p.customcode' => 'customs code',
721 'p.fk_country' => 'FR',
722 'p.price' => "100",
723 'p.price_min' => "100",
724 'p.price_ttc' => "110",
725 'p.price_min_ttc' => "110",
726 'p.price_base_type' => "HT (show/use price excl. tax) / TTC (show/use price incl. tax)",
727 'p.tva_tx' => '10', // tax rate eg: 10. Must match numerically one of the tax rates defined for your country
728 'p.default_vat_code' => '', // to use the correct vat line when there is several lines with the same vat rate for your country
729 'p.tosell' => "0 (not for sale to customer, eg. raw material) / 1 (for sale)",
730 'p.tobuy' => "0 (not for purchase from supplier, eg. virtual product) / 1 (for purchase)",
731 'p.fk_product_type' => "0 (product) / 1 (service)",
732 'p.duration' => "eg. 365d/12m/1y",
733 'p.url' => 'link to product (no https)',
734 'p.accountancy_code_sell' => "",
735 'p.accountancy_code_sell_intra' => "",
736 'p.accountancy_code_sell_export' => "",
737 'p.accountancy_code_buy' => "",
738 'p.accountancy_code_buy_intra' => "",
739 'p.accountancy_code_buy_export' => "",
740 'p.weight' => "",
741 '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',
742 'p.length' => "",
743 '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',
744 'p.width' => "",
745 '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',
746 'p.height' => "",
747 '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',
748 'p.surface' => "",
749 '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',
750 'p.volume' => "",
751 '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',
752 'p.finished' => '0 (raw material) / 1 (finished goods), matches field "code" in dictionary table "'.MAIN_DB_PREFIX.'c_product_nature"'
753 );
754 //clauses copied from import_fields_array
755 if (isModEnabled('stock')) {
756 $import_sample = array_merge($import_sample, array(
757 'p.tobatch' => "0 (don't use) / 1 (use batch) / 2 (use serial number)",
758 'p.sell_or_eat_by_mandatory' => "0 (none) / 1 (sell-by) / 2 (eat-by) / 3 (sell+eat)",
759 'p.seuil_stock_alerte' => '',
760 'p.pmp' => '0',
761 'p.desiredstock' => ''
762 ));
763 }
764 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice") || isModEnabled('margin')) {
765 $import_sample = array_merge($import_sample, array('p.cost_price' => '90'));
766 }
767 if (is_object($mysoc) && $usenpr) {
768 $import_sample = array_merge($import_sample, array('p.recuperableonly' => '0'));
769 }
770 if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
771 $import_sample = array_merge($import_sample, array('p.localtax1_tx' => '', 'p.localtax1_type' => ''));
772 }
773 if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
774 $import_sample = array_merge($import_sample, array('p.localtax2_tx' => '', 'p.localtax2_type' => ''));
775 }
776 if (isModEnabled('barcode')) {
777 $import_sample = array_merge($import_sample, array('p.barcode' => ''));
778 }
779 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
780 $import_sample = array_merge(
781 $import_sample,
782 array(
783 '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"'
784 )
785 );
786
787 if (!is_array($this->import_convertvalue_array[$r])) {
788 $this->import_convertvalue_array[$r] = array();
789 }
790 $this->import_convertvalue_array[$r] = array_merge($this->import_convertvalue_array[$r], array(
791 'p.fk_unit' => array(
792 'rule' => 'fetchidfromcodeorlabel',
793 'classfile' => '/core/class/cunits.class.php',
794 'class' => 'CUnits',
795 'method' => 'fetch',
796 'dict' => 'DictionaryUnits'
797 )
798 ));
799 }
800
801 if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
802 $import_sample = array_merge($import_sample, array(
803 'p.packaging' => "2",
804 ));
805 }
806
807 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
808 $this->import_updatekeys_array[$r] = array('p.ref' => 'Ref');
809 if (isModEnabled('barcode')) {
810 $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
811 }
812
813 if (getDolGlobalString('STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE')) {
814 // Import products limit and desired stock by product and warehouse
815 $r++;
816 $this->import_code[$r] = $this->rights_class.'_stock_by_warehouse';
817 $this->import_label[$r] = "ProductStockWarehouse"; // Translation key
818 $this->import_icon[$r] = $this->picto;
819 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
820 $this->import_tables_array[$r] = array('pwp' => MAIN_DB_PREFIX.'product_warehouse_properties');
821 $this->import_fields_array[$r] = array('pwp.fk_product' => "Product*",
822 'pwp.fk_entrepot' => "Warehouse*", 'pwp.seuil_stock_alerte' => "StockLimit",
823 'pwp.desiredstock' => "DesiredStock");
824 $this->import_regex_array[$r] = array(
825 'pwp.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product',
826 'pwp.fk_entrepot' => 'rowid@'.MAIN_DB_PREFIX.'entrepot',
827 );
828 $this->import_convertvalue_array[$r] = array(
829 'pwp.fk_product' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product')
830 ,'pwp.fk_entrepot' => array('rule' => 'fetchidfromref', 'classfile' => '/product/stock/class/entrepot.class.php', 'class' => 'Entrepot', 'method' => 'fetch', 'element' => 'Entrepot')
831 );
832 $this->import_examplevalues_array[$r] = array('pwp.fk_product' => "ref:PRODUCT_REF or id:123456",
833 'pwp.fk_entrepot' => "ref:WAREHOUSE_REF or id:123456",
834 'pwp.seuil_stock_alerte' => "100",
835 'pwp.desiredstock' => "110"
836 );
837 $this->import_updatekeys_array[$r] = array('pwp.fk_product' => 'Product', 'pwp.fk_entrepot' => 'Warehouse');
838 }
839
840 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
841 // Import suppliers prices (note: this code is duplicated in module Service)
842 $r++;
843 $this->import_code[$r] = $this->rights_class.'_supplierprices';
844 $this->import_label[$r] = "SuppliersPricesOfProductsOrServices"; // Translation key
845 $this->import_icon[$r] = $this->picto;
846 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
847 $this->import_tables_array[$r] = array('sp' => MAIN_DB_PREFIX.'product_fournisseur_price', 'extra' => MAIN_DB_PREFIX.'product_fournisseur_price_extrafields');
848 $this->import_tables_creator_array[$r] = array('sp' => 'fk_user');
849 $this->import_fields_array[$r] = array(//field order as per structure of table llx_product_fournisseur_price, without optional fields
850 'sp.fk_product' => "ProductOrService*",
851 'sp.fk_soc' => "Supplier*",
852 'sp.ref_fourn' => 'SupplierRef*',
853 'sp.quantity' => "QtyMin*",
854 'sp.tva_tx' => 'VATRate',
855 'sp.default_vat_code' => 'VATCode',
856 'sp.delivery_time_days' => 'NbDaysToDelivery',
857 'sp.supplier_reputation' => 'SupplierReputation',
858 'sp.status' => 'Status',
859 'sp.datec' => 'DateCreation'
860 );
861 if (is_object($mysoc) && $usenpr) {
862 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.recuperableonly' => 'VATNPR'));
863 }
864 if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
865 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax1_tx' => 'LT1', 'sp.localtax1_type' => 'LT1Type'));
866 }
867 if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
868 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax2_tx' => 'LT2', 'sp.localtax2_type' => 'LT2Type'));
869 }
870 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
871 'sp.price' => "PriceQtyMinHT*",
872 'sp.unitprice' => 'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty
873 'sp.remise_percent' => 'DiscountQtyMin'
874 ));
875
876 if (isModEnabled("multicurrency")) {
877 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
878 'sp.fk_multicurrency' => 'CurrencyCodeId', //ideally this should be automatically obtained from the CurrencyCode on the next line
879 'sp.multicurrency_code' => 'CurrencyCode',
880 'sp.multicurrency_tx' => 'CurrencyRate',
881 'sp.multicurrency_unitprice' => 'CurrencyUnitPrice',
882 'sp.multicurrency_price' => 'CurrencyPrice',
883 ));
884 }
885
886 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
887 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.packaging' => 'PackagingForThisProduct'));
888 }
889
890 // Add extra fields
891 $import_extrafield_sample = array();
892 $keyforselect = 'product_fournisseur_price';
893 $keyforelement = 'product';
894 $keyforaliasextra = 'extra';
895 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
896
897 // Add some field automatically (if they are not yet provided explicitly)
898 $this->import_fieldshidden_array[$r] = array(
899 'sp.datec' => 'const-'.dol_print_date(dol_now(), 'standard'),
900 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'product_fournisseur_price'
901 ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent or 'const-xxxx')
902
903 $this->import_convertvalue_array[$r] = array(
904 'sp.fk_soc' => array('rule' => 'fetchidfromref', 'classfile' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
905 'sp.fk_product' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product')
906 );
907
908 $this->import_regex_array[$r] = array(
909 'sp.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]$'
910 );
911
912 $this->import_examplevalues_array[$r] = array(
913 'sp.fk_product' => "ref:PRODUCT_REF or id:123456",
914 'sp.fk_soc' => "My Supplier",
915 'sp.ref_fourn' => "XYZ-F123456",
916 'sp.quantity' => "5",
917 'sp.tva_tx' => '10',
918 'sp.default_vat_code' => '',
919 'sp.price' => "50",
920 'sp.unitprice' => '50',
921 'sp.remise_percent' => '0',
922 'sp.delivery_time_days' => '5',
923 'sp.supplier_reputation' => 'FAVORITE / NOTTHGOOD / DONOTORDER',
924 'sp.status' => '1',
925 'sp.datec' => dol_print_date(dol_now(), '%Y-%m-%d %H:%M:%S'),
926 );
927 if (is_object($mysoc) && $usenpr) {
928 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.recuperableonly' => ''));
929 }
930 if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
931 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax1_tx' => 'LT1', 'sp.localtax1_type' => 'LT1Type'));
932 }
933 if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
934 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax2_tx' => 'LT2', 'sp.localtax2_type' => 'LT2Type'));
935 }
936 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
937 'sp.price' => "50.00",
938 'sp.unitprice' => '10',
939 // TODO Make this field not required and calculate it from price and qty
940 'sp.remise_percent' => '20'
941 ));
942 if (isModEnabled("multicurrency")) {
943 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
944 'sp.fk_multicurrency' => 'eg: 2 = the rowid for code of multicurrency currency',
945 'sp.multicurrency_code' => 'GBP',
946 'sp.multicurrency_tx' => '1.12345',
947 'sp.multicurrency_unitprice' => '',
948 // TODO Make this field not required and calculate it from price and qty
949 'sp.multicurrency_price' => ''
950 ));
951 }
952 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
953 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
954 'sp.packaging' => '10',
955 ));
956 }
957
958 $this->import_updatekeys_array[$r] = array('sp.fk_product' => 'ProductOrService', 'sp.ref_fourn' => 'SupplierRef', 'sp.fk_soc' => 'Supplier', 'sp.quantity' => "QtyMin");
959 }
960
961 if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
962 // Import products multiprices
963 $r++;
964 $this->import_code[$r] = $this->rights_class.'_multiprice';
965 $this->import_label[$r] = "ProductsOrServiceMultiPrice"; // Translation key
966 $this->import_icon[$r] = $this->picto;
967 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
968 $this->import_tables_array[$r] = array('pr' => MAIN_DB_PREFIX.'product_price', 'extra' => MAIN_DB_PREFIX.'product_price_extrafields');
969 $this->import_tables_creator_array[$r] = array('pr' => 'fk_user_author'); // Fields to store import user id
970 $this->import_fields_array[$r] = array('pr.fk_product' => "ProductOrService*",
971 'pr.price_base_type' => "PriceBase", 'pr.price_level' => "PriceLevel",
972 'pr.price' => "PriceLevelUnitPriceHT", 'pr.price_ttc' => "PriceLevelUnitPriceTTC",
973 'pr.price_min' => "MinPriceLevelUnitPriceHT", 'pr.price_min_ttc' => "MinPriceLevelUnitPriceTTC",
974 'pr.date_price' => 'DateCreation*');
975 if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) {
976 $this->import_fields_array[$r]['pr.tva_tx'] = 'VATRate';
977 }
978 if (is_object($mysoc) && $usenpr) {
979 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('pr.recuperableonly' => 'NPR'));
980 }
981
982 // Add extra fields
983 $import_extrafield_sample = array();
984 $keyforselect = 'product_price';
985 $keyforelement = 'product';
986 $keyforaliasextra = 'extra';
987 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
988 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'product_price'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
989
990 $this->import_regex_array[$r] = array(
991 'pr.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
992 'pr.recuperableonly' => '^[0|1]$'
993 );
994
995 $this->import_convertvalue_array[$r] = array(
996 'pr.fk_product' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product')
997 );
998 $this->import_examplevalues_array[$r] = array('pr.fk_product' => "ref:PRODUCT_REF or id:123456",
999 'pr.price_base_type' => "HT (for excl tax) or TTC (for inc tax)", 'pr.price_level' => "1",
1000 'pr.price' => "100", 'pr.price_ttc' => "110",
1001 'pr.price_min' => "100", 'pr.price_min_ttc' => "110",
1002 'pr.tva_tx' => '20',
1003 'pr.recuperableonly' => '0',
1004 'pr.date_price' => '2020-12-31');
1005 }
1006
1007
1008 if (getDolGlobalInt('PRODUIT_CUSTOMER_PRICES')) {
1009 $r++;
1010 $this->import_code[$r] = $this->rights_class.'_productcustomerprice';
1011 $this->import_label[$r] = "ProductsPricePerCustomer"; // Translation key
1012 $this->import_icon[$r] = $this->picto;
1013 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
1014 $this->import_tables_array[$r] = array('sp' => $this->db->prefix().'product_customer_price', 'extra' => $this->db->prefix().'product_customer_price_extrafields');
1015 $this->import_tables_creator_array[$r] = array('sp' => 'fk_user'); // Fields to store import user id
1016 $this->import_fields_array[$r] = array(
1017 'sp.fk_product' => "Products*",
1018 'sp.fk_soc' => "Customer*",
1019 'sp.ref_customer' => "RefCustomer",
1020 'sp.date_begin' => "AppliedPricesFrom*",
1021 'sp.date_end' => "AppliedPricesTo",
1022 'sp.tva_tx' => "VATRate*",
1023 'sp.default_vat_code' => 'VATCode',
1024 'sp.discount_percent' => 'Discount',
1025 'sp.price_base_type' => "PriceBase*",
1026 'sp.price' => "SellingUnitPriceHT*",
1027 'sp.price_min' => "SellingUnitMinPriceHT",
1028 'sp.price_ttc' => "SellingUnitPriceTTC",
1029 'sp.price_min_ttc' => "SellingUnitMinPriceTTC",
1030 'sp.datec' => "DateCreation");
1031
1032 $this->import_convertvalue_array[$r] = array(
1033 'sp.fk_soc' => array('rule' => 'fetchidfromref', 'classfile' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
1034 'sp.fk_product' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product')
1035 );
1036
1037 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
1038 $this->import_examplevalues_array[$r] = array(
1039 'sp.fk_product' => "ref:PRODUCT_REF or id:123456",
1040 'sp.fk_soc' => "My Supplier",
1041 'sp.ref_customer' => "XYZ-F123456",
1042 'sp.date_begin' => "2025-06-30",
1043 'sp.date_end' => "2027-06-30",
1044 'sp.tva_tx' => '20',
1045 'sp.default_vat_code' => '5',
1046 'sp.discount_percent' => '30',
1047 'sp.price_base_type' => 'HT (for excl tax) or TTC (for inc tax)',
1048 'sp.price' => "100",
1049 'sp.price_min' => "80",
1050 'sp.price_ttc' => "120",
1051 'sp.price_min_ttc' => "96",
1052 'sp.datec' => "2025-09-30"
1053 );
1054 }
1055
1056 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1057 // Import translations of product names and descriptions
1058 $r++;
1059 $this->import_code[$r] = $this->rights_class.'_languages';
1060 $this->import_label[$r] = "ProductsOrServicesTranslations";
1061 $this->import_icon[$r] = $this->picto;
1062 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
1063 $this->import_tables_array[$r] = array('l' => MAIN_DB_PREFIX.'product_lang');
1064 // multiline translation, one line per translation
1065 $this->import_fields_array[$r] = array('l.fk_product' => 'ProductOrService*', 'l.lang' => 'Language*', 'l.label' => 'TranslatedLabel', 'l.description' => 'TranslatedDescription');
1066 //$this->import_fields_array[$r]['l.note']='TranslatedNote';
1067 $this->import_convertvalue_array[$r] = array(
1068 'l.fk_product' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product')
1069 );
1070 $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');
1071 $this->import_updatekeys_array[$r] = array('l.fk_product' => 'ProductOrService', 'l.lang' => 'Language');
1072 }
1073
1074 if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) {
1075 // Import products kit
1076 $r++;
1077 $this->import_code[$r] = $this->rights_class . '_' . $r;
1078 $this->import_label[$r] = "AssociatedProducts"; // Translation key
1079 $this->import_icon[$r] = $this->picto;
1080 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
1081 $this->import_tables_array[$r] = array('pa' => MAIN_DB_PREFIX . 'product_association');
1082 $this->import_fields_array[$r] = array('pa.fk_product_pere' => 'ParentProducts', 'pa.fk_product_fils' => 'ComposedProduct', 'pa.qty' => 'Qty', 'pa.incdec' => 'ComposedProductIncDecStock', 'pa.rang' => 'rang');
1083
1084 $this->import_convertvalue_array[$r] = array(
1085 'pa.fk_product_pere' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product'),
1086 'pa.fk_product_fils' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product')
1087 );
1088 $this->import_examplevalues_array[$r] = array(
1089 'pa.fk_product_pere' => "ref:PREF123456",
1090 'pa.fk_product_fils' => "ref:PREF123456",
1091 'pa.qty' => "100",
1092 'pa.incdec' => "0",
1093 'pa.rang' => "1");
1094 $this->import_regex_array[$r] = array('pa.fk_product_pere' => 'rowid@'.MAIN_DB_PREFIX.'product', 'pa.fk_product_fils' => 'rowid@'.MAIN_DB_PREFIX.'product');
1095 $this->import_updatekeys_array[$r] = array('pa.fk_product_pere' => 'ref parent', 'pa.fk_product_fils' => "ref enfant");
1096 }
1097 }
1098
1099
1108 public function init($options = '')
1109 {
1110 $this->remove($options);
1111
1112 $sql = array();
1113
1114 return $this->_init($sql, $options);
1115 }
1116}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class descriptor of Product module.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133