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