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