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