modService.class.php 48 KB

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