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