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