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