dolibarr 22.0.5
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",
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",
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 }
329
330 if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
331 // Exports product multiprice
332 $r++;
333 $this->export_code[$r] = $this->rights_class.'_'.$r;
334 $this->export_label[$r] = "ProductsPricePerCustomer"; // Translation key (used only if key ExportDataset_xxx_z not found)
335 $this->export_permission[$r] = array(array("service", "export"));
336 $this->export_fields_array[$r] = array('p.rowid' => "Id", 'p.ref' => "Ref",
337 's.nom' => 'ThirdParty',
338 'pr.date_begin' => "AppliedPricesFrom",
339 'pr.date_end' => "AppliedPricesTo",
340 'pr.price_base_type' => "PriceBase",
341 'pr.price' => "PriceUnitPriceHT", 'pr.price_ttc' => "PriceUnitPriceTTC",
342 'pr.price_min' => "MinPriceUnitPriceHT", 'pr.price_min_ttc' => "MinPriceUnitPriceTTC",
343 'pr.tva_tx' => 'PriceVATRate',
344 'pr.default_vat_code' => 'PriceVATCode',
345 'pr.discount_percent' => 'Discount',
346 'pr.datec' => 'DateCreation');
347 if (is_object($mysoc) && $usenpr) {
348 $this->export_fields_array[$r]['pr.recuperableonly'] = 'NPR';
349 }
350 $this->export_entities_array[$r] = array('p.rowid' => "product", 'p.ref' => "product",
351 's.nom' => 'company',
352 'pr.date_begin' => "product",
353 'pr.date_end' => "product",
354 'pr.price_base_type' => "product", 'pr.price' => "product",
355 'pr.price_ttc' => "product",
356 'pr.price_min' => "product", 'pr.price_min_ttc' => "product",
357 'pr.tva_tx' => 'product',
358 'pr.default_vat_code' => 'product',
359 'pr.discount_percent' => 'product',
360 'pr.recuperableonly' => 'product',
361 'pr.datec' => "product");
362 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
363 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
364 $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
365 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON pr.fk_soc = s.rowid';
366 $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
367 }
368
369 if (getDolGlobalString('PRODUIT_SOUSPRODUITS')) {
370 // Exports virtual products
371 $r++;
372 $this->export_code[$r] = $this->rights_class.'_'.$r;
373 $this->export_label[$r] = "AssociatedProducts"; // Translation key (used only if key ExportDataset_xxx_z not found)
374 $this->export_permission[$r] = array(array("service", "export"));
375 $this->export_fields_array[$r] = array(
376 'p.rowid' => "Id", 'p.ref' => "Ref", 'p.label' => "Label", 'p.description' => "Description", 'p.url' => "PublicUrl",
377 $alias_product_perentity . '.accountancy_code_sell' => "ProductAccountancySellCode", $alias_product_perentity . '.accountancy_code_sell_intra' => "ProductAccountancySellIntraCode",
378 $alias_product_perentity . '.accountancy_code_sell_export' => "ProductAccountancySellExportCode", $alias_product_perentity . '.accountancy_code_buy' => "ProductAccountancyBuyCode",
379 $alias_product_perentity . '.accountancy_code_buy_intra' => "ProductAccountancyBuyIntraCode", $alias_product_perentity . '.accountancy_code_buy_export' => "ProductAccountancyBuyExportCode",
380 'p.note' => "NotePrivate", 'p.note_public' => 'NotePublic',
381 'p.weight' => "Weight", 'p.length' => "Length", 'p.surface' => "Surface", 'p.volume' => "Volume", 'p.customcode' => 'CustomsCode',
382 'p.price_base_type' => "PriceBase", 'p.price' => "UnitPriceHT", 'p.price_ttc' => "UnitPriceTTC", 'p.tva_tx' => 'VATRate', 'p.tosell' => "OnSell",
383 'p.tobuy' => "OnBuy", 'p.datec' => 'DateCreation', 'p.tms' => 'DateModification'
384 );
385 if (isModEnabled('stock')) {
386 $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'));
387 }
388 if (isModEnabled('barcode')) {
389 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('p.barcode' => 'BarCode'));
390 }
391 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array('pa.qty' => 'Qty', 'pa.incdec' => 'ComposedProductIncDecStock'));
392 $this->export_TypeFields_array[$r] = array(
393 'p.ref' => "Text", 'p.label' => "Text", 'p.description' => "Text", 'p.url' => "Text",
394 $alias_product_perentity . 'p.accountancy_code_sell' => "Text", $alias_product_perentity . '.accountancy_code_sell_intra' => "Text", $alias_product_perentity . '.accountancy_code_sell_export' => "Text",
395 $alias_product_perentity . 'p.accountancy_code_buy' => "Text", $alias_product_perentity . '.accountancy_code_buy_intra' => "Text", $alias_product_perentity . '.accountancy_code_buy_export' => "Text",
396 'p.note' => "Text", 'p.note_public' => "Text",
397 'p.weight' => "Numeric", 'p.length' => "Numeric", 'p.surface' => "Numeric", 'p.volume' => "Numeric", 'p.customcode' => 'Text',
398 'p.price_base_type' => "Text", 'p.price' => "Numeric", 'p.price_ttc' => "Numeric", 'p.tva_tx' => 'Numeric', 'p.tosell' => "Boolean", 'p.tobuy' => "Boolean",
399 'p.datec' => 'Date', 'p.tms' => 'Date'
400 );
401 if (isModEnabled('stock')) {
402 $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'));
403 }
404 if (isModEnabled('barcode')) {
405 $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('p.barcode' => 'Text'));
406 }
407 $this->export_TypeFields_array[$r] = array_merge($this->export_TypeFields_array[$r], array('pa.qty' => 'Numeric'));
408 $this->export_entities_array[$r] = array(
409 'p.rowid' => "virtualproduct", 'p.ref' => "virtualproduct", 'p.label' => "virtualproduct", 'p.description' => "virtualproduct", 'p.url' => "virtualproduct",
410 $alias_product_perentity . '.accountancy_code_sell' => 'virtualproduct', $alias_product_perentity . '.accountancy_code_sell_intra' => 'virtualproduct', $alias_product_perentity . '.accountancy_code_sell_export' => 'virtualproduct',
411 $alias_product_perentity . '.accountancy_code_buy' => 'virtualproduct', $alias_product_perentity . '.accountancy_code_buy_intra' => 'virtualproduct', $alias_product_perentity . '.accountancy_code_buy_export' => 'virtualproduct',
412 'p.note' => "virtualproduct", 'p.length' => "virtualproduct",
413 'p.surface' => "virtualproduct", 'p.volume' => "virtualproduct", 'p.weight' => "virtualproduct", 'p.customcode' => 'virtualproduct',
414 'p.price_base_type' => "virtualproduct", 'p.price' => "virtualproduct", 'p.price_ttc' => "virtualproduct", 'p.tva_tx' => "virtualproduct",
415 'p.tosell' => "virtualproduct", 'p.tobuy' => "virtualproduct", 'p.datec' => "virtualproduct", 'p.tms' => "virtualproduct"
416 );
417 if (isModEnabled('stock')) {
418 $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'));
419 }
420 if (isModEnabled('barcode')) {
421 $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('p.barcode' => 'virtualproduct'));
422 }
423 $this->export_entities_array[$r] = array_merge($this->export_entities_array[$r], array('pa.qty' => "subproduct", 'pa.incdec' => 'subproduct'));
424 $keyforselect = 'product';
425 $keyforelement = 'product';
426 $keyforaliasextra = 'extra';
427 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
428 $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"));
429 $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"));
430 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
431 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'product as p';
432 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
433 $this->export_sql_end[$r] .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as pac ON pac.fk_product = p.rowid AND pac.entity = " . ((int) $conf->entity);
434 }
435 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra ON p.rowid = extra.fk_object,';
436 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'product_association as pa, '.MAIN_DB_PREFIX.'product as p2';
437 $this->export_sql_end[$r] .= ' WHERE p.entity IN ('.getEntity('product').')'; // For product and service profile
438 $this->export_sql_end[$r] .= ' AND p.rowid = pa.fk_product_pere AND p2.rowid = pa.fk_product_fils';
439 }
440 }
441
442 // Imports
443 //--------
444 $r = 0;
445
446 // Import list of services
447
448 $r++;
449 $this->import_code[$r] = $this->rights_class.'_'.$r;
450 $this->import_label[$r] = "Products"; // Translation key
451 $this->import_icon[$r] = $this->picto;
452 $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
453 $this->import_tables_array[$r] = array('p' => MAIN_DB_PREFIX.'product', 'extra' => MAIN_DB_PREFIX.'product_extrafields');
454 $this->import_tables_creator_array[$r] = array('p' => 'fk_user_author'); // Fields to store import user id
455 $this->import_fields_array[$r] = array(
456 'p.ref' => "Ref*",
457 'p.label' => "Label*",
458 'p.fk_product_type' => "Type*",
459 'p.tosell' => "OnSell*",
460 'p.tobuy' => "OnBuy*",
461 'p.description' => "Description",
462 'p.url' => "PublicUrl",
463 'p.customcode' => 'CustomsCode',
464 'p.fk_country' => 'CountryCode',
465 'p.accountancy_code_sell' => "ProductAccountancySellCode",
466 'p.accountancy_code_sell_intra' => "ProductAccountancySellIntraCode",
467 'p.accountancy_code_sell_export' => "ProductAccountancySellExportCode",
468 'p.accountancy_code_buy' => "ProductAccountancyBuyCode",
469 'p.accountancy_code_buy_intra' => "ProductAccountancyBuyIntraCode",
470 'p.accountancy_code_buy_export' => "ProductAccountancyBuyExportCode",
471 'p.note_public' => "NotePublic",
472 'p.note' => "NotePrivate",
473 'p.weight' => "Weight",
474 'p.weight_units' => "WeightUnits",
475 'p.length' => "Length",
476 'p.length_units' => "LengthUnits",
477 'p.width' => "Width",
478 'p.width_units' => "WidthUnits",
479 'p.height' => "Height",
480 'p.height_units' => "HeightUnits",
481 'p.surface' => "Surface",
482 'p.surface_units' => "SurfaceUnits",
483 'p.volume' => "Volume",
484 'p.volume_units' => "VolumeUnits",
485 'p.duration' => "Duration", //duration of service
486 'p.finished' => 'Nature',
487 'p.price' => "SellingPriceHT", //without
488 'p.price_min' => "MinPrice",
489 'p.price_ttc' => "SellingPriceTTC", //with tax
490 'p.price_min_ttc' => "SellingMinPriceTTC",
491 'p.price_base_type' => "PriceBaseType", //price base: with-tax (TTC) or without (HT) tax. Displays accordingly in Product card
492 'p.tva_tx' => 'VATRate',
493 'p.datec' => 'DateCreation',
494 'p.cost_price' => "CostPrice",
495 );
496
497 $this->import_convertvalue_array[$r] = array(
498 'p.weight_units' => array(
499 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
500 'classfile' => '/core/class/cunits.class.php',
501 'class' => 'CUnits',
502 'method' => 'fetch',
503 'units' => 'weight',
504 'dict' => 'DictionaryMeasuringUnits'
505 ),
506 'p.length_units' => array(
507 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
508 'classfile' => '/core/class/cunits.class.php',
509 'class' => 'CUnits',
510 'method' => 'fetch',
511 'units' => 'size',
512 'dict' => 'DictionaryMeasuringUnits'
513 ),
514 'p.width_units' => array(
515 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
516 'classfile' => '/core/class/cunits.class.php',
517 'class' => 'CUnits',
518 'method' => 'fetch',
519 'units' => 'size',
520 'dict' => 'DictionaryMeasuringUnits'
521 ),
522 'p.height_units' => array(
523 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
524 'classfile' => '/core/class/cunits.class.php',
525 'class' => 'CUnits',
526 'method' => 'fetch',
527 'units' => 'size',
528 'dict' => 'DictionaryMeasuringUnits'
529 ),
530 'p.surface_units' => array(
531 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
532 'classfile' => '/core/class/cunits.class.php',
533 'class' => 'CUnits',
534 'method' => 'fetch',
535 'units' => 'surface',
536 'dict' => 'DictionaryMeasuringUnits'
537 ),
538 'p.volume_units' => array(
539 'rule' => 'fetchscalefromcodeunits', // Switch this to fetchidfromcodeunits when we will store id instead of scale in product table
540 'classfile' => '/core/class/cunits.class.php',
541 'class' => 'CUnits',
542 'method' => 'fetch',
543 'units' => 'volume',
544 'dict' => 'DictionaryMeasuringUnits'
545 ),
546 'p.fk_country' => array(
547 'rule' => 'fetchidfromcodeid',
548 'classfile' => '/core/class/ccountry.class.php',
549 'class' => 'Ccountry',
550 'method' => 'fetch',
551 'dict' => 'DictionaryCountry'
552 )
553 );
554
555 $this->import_regex_array[$r] = array(
556 'p.ref' => '[^ ]',
557 'p.price_base_type' => '\AHT\z|\ATTC\z',
558 'p.tosell' => '^[0|1]$',
559 'p.tobuy' => '^[0|1]$',
560 'p.fk_product_type' => '^[0|1]$',
561 'p.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
562 'p.recuperableonly' => '^[0|1]$',
563 );
564
565 if (isModEnabled('stock')) {//if Stock module enabled
566 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
567 'p.fk_default_warehouse' => 'DefaultWarehouse',
568 'p.tobatch' => 'ManageLotSerial',
569 'p.seuil_stock_alerte' => 'StockLimit', //lower limit for warning
570 'p.pmp' => 'PMPValue', //weighted average price
571 'p.desiredstock' => 'DesiredStock'//desired stock for replenishment feature
572 ));
573
574 $this->import_regex_array[$r] = array_merge($this->import_regex_array[$r], array(
575 'p.tobatch' => '^[0|1|2]$'
576 ));
577
578 $this->import_convertvalue_array[$r] = array_merge($this->import_convertvalue_array[$r], array(
579 'p.fk_default_warehouse' => array(
580 'rule' => 'fetchidfromref',
581 'classfile' => '/product/stock/class/entrepot.class.php',
582 'class' => 'Entrepot',
583 'method' => 'fetch',
584 'element' => 'Warehouse'
585 )
586 ));
587 }
588
589 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice") || isModEnabled('margin')) {
590 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.cost_price' => 'CostPrice'));
591 }
592 if (is_object($mysoc) && $usenpr) {
593 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.recuperableonly' => 'NPR'));
594 }
595 if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
596 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax1_tx' => 'LT1', 'p.localtax1_type' => 'LT1Type'));
597 }
598 if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
599 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.localtax2_tx' => 'LT2', 'p.localtax2_type' => 'LT2Type'));
600 }
601 if (isModEnabled('barcode')) {
602 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.barcode' => 'BarCode'));
603 }
604 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
605 $this->import_fields_array[$r]['p.fk_unit'] = 'Unit';
606 }
607 // Add extra fields
608 $import_extrafield_sample = array();
609 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'product' AND entity IN (0,".$conf->entity.")";
610 $resql = $this->db->query($sql);
611 if ($resql) { // This can fail when class is used on old database (during migration for example)
612 while ($obj = $this->db->fetch_object($resql)) {
613 $fieldname = 'extra.'.$obj->name;
614 $fieldlabel = ucfirst($obj->label);
615 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
616 $import_extrafield_sample[$fieldname] = $fieldlabel;
617 }
618 }
619 // End add extra fields
620 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
621 $this->import_regex_array[$r] = array(
622 'p.ref' => '[^ ]',
623 'p.price_base_type' => 'HT|TTC',
624 'p.tosell' => '^[0|1]$',
625 'p.tobuy' => '^[0|1]$',
626 'p.fk_product_type' => '^[0|1]$',
627 'p.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
628 'p.recuperableonly' => '^[0|1]$',
629 'p.finished' => '^[0|1]$'
630 );
631 // field order as per structure of table llx_product
632 $import_sample = array(
633 'p.ref' => "ref:PREF123456",
634 'p.datec' => dol_print_date(dol_now(), '%Y-%m-%d'),
635 'p.label' => "Product name in default language",
636 'p.description' => "Product description in default language",
637 'p.note_public' => "a public note (free text)",
638 'p.note' => "a private note (free text)",
639 'p.customcode' => 'customs code',
640 'p.fk_country' => 'FR',
641 'p.price' => "100",
642 'p.price_min' => "100",
643 'p.price_ttc' => "110",
644 'p.price_min_ttc' => "110",
645 'p.price_base_type' => "HT (show/use price excl. tax) / TTC (show/use price incl. tax)",
646 'p.tva_tx' => '10', // tax rate eg: 10. Must match numerically one of the tax rates defined for your country'
647 'p.tosell' => "0 (not for sale to customer, eg. raw material) / 1 (for sale)",
648 'p.tobuy' => "0 (not for purchase from supplier, eg. virtual product) / 1 (for purchase)",
649 'p.fk_product_type' => "0 (product) / 1 (service)",
650 'p.duration' => "eg. 365d/12m/1y",
651 'p.url' => 'link to product (no https)',
652 'p.accountancy_code_sell' => "",
653 'p.accountancy_code_sell_intra' => "",
654 'p.accountancy_code_sell_export' => "",
655 'p.accountancy_code_buy' => "",
656 'p.accountancy_code_buy_intra' => "",
657 'p.accountancy_code_buy_export' => "",
658 'p.weight' => "",
659 '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',
660 'p.length' => "",
661 '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',
662 'p.width' => "",
663 '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',
664 'p.height' => "",
665 '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',
666 'p.surface' => "",
667 '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',
668 'p.volume' => "",
669 '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',
670 'p.finished' => '0 (raw material) / 1 (finished goods), matches field "code" in dictionary table "'.MAIN_DB_PREFIX.'c_product_nature"'
671 );
672 //clauses copied from import_fields_array
673 if (isModEnabled('stock')) {
674 $import_sample = array_merge($import_sample, array(
675 'p.seuil_stock_alerte' => '',
676 'p.pmp' => '0',
677 'p.desiredstock' => ''
678 ));
679 }
680 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice") || isModEnabled('margin')) {
681 $import_sample = array_merge($import_sample, array('p.cost_price' => '90'));
682 }
683 if (is_object($mysoc) && $usenpr) {
684 $import_sample = array_merge($import_sample, array('p.recuperableonly' => '0'));
685 }
686 if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
687 $import_sample = array_merge($import_sample, array('p.localtax1_tx' => '', 'p.localtax1_type' => ''));
688 }
689 if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
690 $import_sample = array_merge($import_sample, array('p.localtax2_tx' => '', 'p.localtax2_type' => ''));
691 }
692 if (isModEnabled('barcode')) {
693 $import_sample = array_merge($import_sample, array('p.barcode' => ''));
694 }
695 if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
696 $import_sample = array_merge(
697 $import_sample,
698 array(
699 '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"'
700 )
701 );
702
703 if (!is_array($this->import_convertvalue_array[$r])) {
704 $this->import_convertvalue_array[$r] = array();
705 }
706 $this->import_convertvalue_array[$r] = array_merge($this->import_convertvalue_array[$r], array(
707 'p.fk_unit' => array(
708 'rule' => 'fetchidfromcodeorlabel',
709 'classfile' => '/core/class/cunits.class.php',
710 'class' => 'CUnits',
711 'method' => 'fetch',
712 'dict' => 'DictionaryUnits'
713 )
714 ));
715 }
716 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
717 $this->import_updatekeys_array[$r] = array('p.ref' => 'Ref');
718 if (isModEnabled('barcode')) {
719 $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
720 }
721
722 if (!isModEnabled("product")) { // We enable next import templates only if module product not already enabled (to avoid duplicate entries)
723 if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
724 // Import suppliers prices (note: this code is duplicated in module Service)
725 $r++;
726 $this->import_code[$r] = $this->rights_class.'_supplierprices';
727 $this->import_label[$r] = "SuppliersPricesOfProductsOrServices"; // Translation key
728 $this->import_icon[$r] = $this->picto;
729 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
730 $this->import_tables_array[$r] = array('sp' => MAIN_DB_PREFIX.'product_fournisseur_price');
731 $this->import_tables_creator_array[$r] = array('sp' => 'fk_user');
732 $this->import_fields_array[$r] = array(//field order as per structure of table llx_product_fournisseur_price, without optional fields
733 'sp.fk_product' => "ProductOrService*",
734 'sp.fk_soc' => "Supplier*",
735 'sp.ref_fourn' => 'SupplierRef*',
736 'sp.quantity' => "QtyMin*",
737 'sp.tva_tx' => 'VATRate',
738 'sp.default_vat_code' => 'VATCode',
739 'sp.delivery_time_days' => 'NbDaysToDelivery',
740 'sp.supplier_reputation' => 'SupplierReputation'
741 );
742 if (is_object($mysoc) && $usenpr) {
743 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.recuperableonly' => 'VATNPR'));
744 }
745 if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
746 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax1_tx' => 'LT1', 'sp.localtax1_type' => 'LT1Type'));
747 }
748 if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
749 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('sp.localtax2_tx' => 'LT2', 'sp.localtax2_type' => 'LT2Type'));
750 }
751 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
752 'sp.price' => "PriceQtyMinHT*",
753 'sp.unitprice' => 'UnitPriceHT*', // TODO Make this field not required and calculate it from price and qty
754 'sp.remise_percent' => 'DiscountQtyMin'
755 ));
756
757 if (isModEnabled("multicurrency")) {
758 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
759 'sp.fk_multicurrency' => 'CurrencyCodeId', //ideally this should be automatically obtained from the CurrencyCode on the next line
760 'sp.multicurrency_code' => 'CurrencyCode',
761 'sp.multicurrency_tx' => 'CurrencyRate',
762 'sp.multicurrency_unitprice' => 'CurrencyUnitPrice',
763 'sp.multicurrency_price' => 'CurrencyPrice',
764 ));
765 }
766
767 $this->import_convertvalue_array[$r] = array(
768 'sp.fk_soc' => array('rule' => 'fetchidfromref', 'classfile' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
769 'sp.fk_product' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product')
770 );
771 $this->import_examplevalues_array[$r] = array(
772 'sp.fk_product' => "ref:PRODUCT_REF or id:123456",
773 'sp.fk_soc' => "My Supplier",
774 'sp.ref_fourn' => "XYZ-F123456",
775 'sp.quantity' => "5",
776 'sp.tva_tx' => '10',
777 'sp.price' => "50",
778 'sp.unitprice' => '50',
779 'sp.remise_percent' => '0',
780 'sp.default_vat_code' => '',
781 'sp.delivery_time_days' => '5',
782 'sp.supplier_reputation' => 'FAVORITE / NOTTHGOOD / DONOTORDER'
783 );
784 if (is_object($mysoc) && $usenpr) {
785 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.recuperableonly' => ''));
786 }
787 if (is_object($mysoc) && $mysoc->useLocalTax(1)) {
788 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax1_tx' => 'LT1', 'sp.localtax1_type' => 'LT1Type'));
789 }
790 if (is_object($mysoc) && $mysoc->useLocalTax(2)) {
791 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array('sp.localtax2_tx' => 'LT2', 'sp.localtax2_type' => 'LT2Type'));
792 }
793 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
794 'sp.price' => "50.00",
795 'sp.unitprice' => '10',
796 // TODO Make this field not required and calculate it from price and qty
797 'sp.remise_percent' => '20'
798 ));
799 if (isModEnabled("multicurrency")) {
800 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
801 'sp.fk_multicurrency' => 'eg: 2, rowid for code of multicurrency currency',
802 'sp.multicurrency_code' => 'GBP',
803 'sp.multicurrency_tx' => '1.12345',
804 'sp.multicurrency_unitprice' => '',
805 // TODO Make this field not required and calculate it from price and qty
806 'sp.multicurrency_price' => ''
807 ));
808 }
809 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
810 $this->import_examplevalues_array[$r] = array_merge($this->import_examplevalues_array[$r], array(
811 'sp.packaging' => '10',
812 ));
813 }
814
815 $this->import_updatekeys_array[$r] = array('sp.fk_product' => 'ProductOrService', 'sp.ref_fourn' => 'SupplierRef', 'sp.fk_soc' => 'Supplier');
816 }
817
818 if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
819 // Import products multiprices
820 $r++;
821 $this->import_code[$r] = $this->rights_class.'_multiprice';
822 $this->import_label[$r] = "ProductsOrServiceMultiPrice"; // Translation key
823 $this->import_icon[$r] = $this->picto;
824 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
825 $this->import_tables_array[$r] = array('pr' => MAIN_DB_PREFIX.'product_price', 'extra' => MAIN_DB_PREFIX.'product_price_extrafields');
826 $this->import_tables_creator_array[$r] = array('pr' => 'fk_user_author'); // Fields to store import user id
827 $this->import_fields_array[$r] = array('pr.fk_product' => "ProductOrService*",
828 'pr.price_base_type' => "PriceBase", 'pr.price_level' => "PriceLevel",
829 'pr.price' => "PriceLevelUnitPriceHT", 'pr.price_ttc' => "PriceLevelUnitPriceTTC",
830 'pr.price_min' => "MinPriceLevelUnitPriceHT", 'pr.price_min_ttc' => "MinPriceLevelUnitPriceTTC",
831 'pr.date_price' => 'DateCreation*');
832 if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) {
833 $this->import_fields_array[$r]['pr.tva_tx'] = 'VATRate';
834 }
835 if (is_object($mysoc) && $usenpr) {
836 $this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('pr.recuperableonly' => 'NPR'));
837 }
838
839 // Add extra fields
840 $import_extrafield_sample = array();
841 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'product_price' AND entity IN (0, ".$conf->entity.")";
842 $resql = $this->db->query($sql);
843 if ($resql) { // This can fail when class is used on old database (during migration for example)
844 while ($obj = $this->db->fetch_object($resql)) {
845 $fieldname = 'extra.'.$obj->name;
846 $fieldlabel = ucfirst($obj->label);
847 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
848 $import_extrafield_sample[$fieldname] = $fieldlabel;
849 }
850 }
851 // End add extra fields
852 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'product_price'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
853 $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]$');
854 $this->import_convertvalue_array[$r] = array(
855 'pr.fk_product' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product')
856 );
857 $this->import_examplevalues_array[$r] = array('pr.fk_product' => "ref:SERVICE_REF or id:123456",
858 'pr.price_base_type' => "HT (for excl tax) or TTC (for inc tax)", 'pr.price_level' => "1",
859 'pr.price' => "100", 'pr.price_ttc' => "110",
860 'pr.price_min' => "100", 'pr.price_min_ttc' => "110",
861 'pr.tva_tx' => '20',
862 'pr.recuperableonly' => '0',
863 'pr.date_price' => '2013-04-10');
864 }
865
866 if (getDolGlobalInt('MAIN_MULTILANGS')) {
867 // Import translations of product names and descriptions
868 $r++;
869 $this->import_code[$r] = $this->rights_class.'_languages';
870 $this->import_label[$r] = "ProductsOrServicesTranslations";
871 $this->import_icon[$r] = $this->picto;
872 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
873 $this->import_tables_array[$r] = array('l' => MAIN_DB_PREFIX.'product_lang');
874 // multiline translation, one line per translation
875 $this->import_fields_array[$r] = array('l.fk_product' => 'ProductOrService*', 'l.lang' => 'Language*', 'l.label' => 'TranslatedLabel', 'l.description' => 'TranslatedDescription');
876 //$this->import_fields_array[$r]['l.note']='TranslatedNote';
877 $this->import_convertvalue_array[$r] = array(
878 'l.fk_product' => array('rule' => 'fetchidfromref', 'classfile' => '/product/class/product.class.php', 'class' => 'Product', 'method' => 'fetch', 'element' => 'Product')
879 );
880 $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');
881 $this->import_updatekeys_array[$r] = array('l.fk_product' => 'ProductOrService', 'l.lang' => 'Language');
882 }
883 }
884 }
885
886
895 public function init($options = '')
896 {
897 $this->remove($options);
898
899 $sql = array();
900
901 return $this->_init($sql, $options);
902 }
903}
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161