modSociete.class.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2013 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-2013 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2012-2014 Juanjo Menent <jmenent@2byte.es>
  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 societe Module societe
  24. * \brief Module to manage third parties (customers, prospects)
  25. * \file htdocs/core/modules/modSociete.class.php
  26. * \ingroup societe
  27. * \brief Fichier de description et activation du module Societe
  28. */
  29. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  30. /**
  31. * Class to describe and enable module Societe
  32. */
  33. class modSociete 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, $user;
  43. $this->db = $db;
  44. $this->numero = 1;
  45. $this->family = "crm";
  46. $this->module_position = '09';
  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 = "Gestion des sociétés et contacts";
  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->config_page_url = array("societe.php@societe");
  54. // Name of image file used for this module.
  55. $this->picto = 'company';
  56. // Data directories to create when module is enabled
  57. $this->dirs = array("/societe/temp");
  58. // Dependencies
  59. $this->hidden = false; // A condition to hide module
  60. $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
  61. $this->requiredby = array("modExpedition", "modFacture", "modFournisseur", "modFicheinter", "modPropale", "modContrat", "modCommande"); // List of module ids to disable if this one is disabled
  62. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  63. $this->phpmin = array(5, 4); // Minimum version of PHP required by module
  64. $this->langfiles = array("companies", 'bills', "compta", "admin", "banks");
  65. // Constants
  66. $this->const = array();
  67. $r = 0;
  68. $this->const[$r][0] = "SOCIETE_CODECLIENT_ADDON";
  69. $this->const[$r][1] = "chaine";
  70. $this->const[$r][2] = "mod_codeclient_monkey";
  71. $this->const[$r][3] = 'Module to control third parties codes';
  72. $this->const[$r][4] = 0;
  73. $r++;
  74. $this->const[$r][0] = "SOCIETE_CODECOMPTA_ADDON";
  75. $this->const[$r][1] = "chaine";
  76. $this->const[$r][2] = "mod_codecompta_panicum";
  77. $this->const[$r][3] = 'Module to control third parties codes';
  78. $this->const[$r][4] = 0;
  79. $r++;
  80. $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
  81. $this->const[$r][1] = "chaine";
  82. $this->const[$r][2] = "0";
  83. $this->const[$r][3] = "Enter the month number of the first month of the fiscal year, e. g. 9 for September";
  84. $this->const[$r][4] = 0;
  85. $r++;
  86. $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
  87. $this->const[$r][1] = "chaine";
  88. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
  89. $this->const[$r][3] = "";
  90. $this->const[$r][4] = 0;
  91. $r++;
  92. /*
  93. $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
  94. $this->const[$r][1] = "chaine";
  95. $this->const[$r][2] = "0";
  96. $this->const[$r][3] = "hide thirdparty customer inative in combobox";
  97. $this->const[$r][4] = 1;
  98. $r++;
  99. */
  100. $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
  101. $this->const[$r][1] = "yesno";
  102. $this->const[$r][2] = "0";
  103. $this->const[$r][3] = "Display customer ref into select list";
  104. $this->const[$r][4] = 0;
  105. $r++;
  106. // Boxes
  107. $this->boxes = array();
  108. $r = 0;
  109. $this->boxes[$r][1] = "box_clients.php";
  110. $r++;
  111. $this->boxes[$r][1] = "box_prospect.php";
  112. $r++;
  113. $this->boxes[$r][1] = "box_contacts.php";
  114. $r++;
  115. $this->boxes[$r][1] = "box_activity.php";
  116. $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
  117. $r++;
  118. $this->boxes[$r][1] = "box_goodcustomers.php";
  119. $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
  120. $r++;
  121. // Permissions
  122. $this->rights = array();
  123. $this->rights_class = 'societe';
  124. $r = 0;
  125. $r++;
  126. $this->rights[$r][0] = 121; // id de la permission
  127. $this->rights[$r][1] = 'Read third parties'; // libelle de la permission
  128. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  129. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  130. $this->rights[$r][4] = 'lire';
  131. /*$r++;
  132. $this->rights[$r][0] = 241;
  133. $this->rights[$r][1] = 'Read thirdparties customers';
  134. $this->rights[$r][2] = 'r';
  135. $this->rights[$r][3] = 0;
  136. $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  137. $this->rights[$r][5] = 'read';
  138. $r++;
  139. $this->rights[$r][0] = 242;
  140. $this->rights[$r][1] = 'Read thirdparties suppliers';
  141. $this->rights[$r][2] = 'r';
  142. $this->rights[$r][3] = 0;
  143. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  144. $this->rights[$r][5] = 'read';
  145. */
  146. $r++;
  147. $this->rights[$r][0] = 122; // id de la permission
  148. $this->rights[$r][1] = 'Create and update third parties'; // libelle de la permission
  149. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  150. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  151. $this->rights[$r][4] = 'creer';
  152. /* $r++;
  153. $this->rights[$r][0] = 251;
  154. $this->rights[$r][1] = 'Create thirdparties customers';
  155. $this->rights[$r][2] = 'r';
  156. $this->rights[$r][3] = 0;
  157. $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  158. $this->rights[$r][5] = 'read';
  159. $r++;
  160. $this->rights[$r][0] = 252;
  161. $this->rights[$r][1] = 'Create thirdparties suppliers';
  162. $this->rights[$r][2] = 'r';
  163. $this->rights[$r][3] = 0;
  164. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  165. $this->rights[$r][5] = 'read';
  166. */
  167. $r++;
  168. $this->rights[$r][0] = 125; // id de la permission
  169. $this->rights[$r][1] = 'Delete third parties'; // libelle de la permission
  170. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  171. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  172. $this->rights[$r][4] = 'supprimer';
  173. $r++;
  174. $this->rights[$r][0] = 126; // id de la permission
  175. $this->rights[$r][1] = 'Export third parties'; // libelle de la permission
  176. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  177. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  178. $this->rights[$r][4] = 'export';
  179. // 262 : Resteindre l'acces des commerciaux
  180. $r++;
  181. $this->rights[$r][0] = 262;
  182. $this->rights[$r][1] = 'Read all third parties by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).';
  183. $this->rights[$r][2] = 'r';
  184. $this->rights[$r][3] = 0;
  185. $this->rights[$r][4] = 'client';
  186. $this->rights[$r][5] = 'voir';
  187. $r++;
  188. $this->rights[$r][0] = 281; // id de la permission
  189. $this->rights[$r][1] = 'Read contacts'; // libelle de la permission
  190. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  191. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  192. $this->rights[$r][4] = 'contact';
  193. $this->rights[$r][5] = 'lire';
  194. $r++;
  195. $this->rights[$r][0] = 282; // id de la permission
  196. $this->rights[$r][1] = 'Create and update contact'; // libelle de la permission
  197. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  198. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  199. $this->rights[$r][4] = 'contact';
  200. $this->rights[$r][5] = 'creer';
  201. $r++;
  202. $this->rights[$r][0] = 283; // id de la permission
  203. $this->rights[$r][1] = 'Delete contacts'; // libelle de la permission
  204. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  205. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  206. $this->rights[$r][4] = 'contact';
  207. $this->rights[$r][5] = 'supprimer';
  208. $r++;
  209. $this->rights[$r][0] = 286; // id de la permission
  210. $this->rights[$r][1] = 'Export contacts'; // libelle de la permission
  211. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  212. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  213. $this->rights[$r][4] = 'contact';
  214. $this->rights[$r][5] = 'export';
  215. // Menus
  216. //-------
  217. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  218. // Exports
  219. //--------
  220. $r = 0;
  221. // Export list of third parties and attributes
  222. $r++;
  223. $this->export_code[$r] = $this->rights_class.'_'.$r;
  224. $this->export_label[$r] = 'ExportDataset_company_1';
  225. $this->export_icon[$r] = 'company';
  226. $this->export_permission[$r] = array(array("societe", "export"));
  227. $this->export_fields_array[$r] = array(
  228. 's.rowid'=>"Id", 's.nom'=>"Name", 's.name_alias'=>"AliasNameShort", 's.status'=>"Status", 's.client'=>"Customer", 's.fournisseur'=>"Supplier", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification",
  229. 's.code_client'=>"CustomerCode", 's.code_fournisseur'=>"SupplierCode", 's.code_compta'=>"AccountancyCode", 's.code_compta_fournisseur'=>"SupplierAccountancyCode",
  230. 's.address'=>"Address", 's.zip'=>"Zip", 's.town'=>"Town", 'd.nom'=>'State', 'c.label'=>"Country", 'c.code'=>"CountryCode", 's.phone'=>"Phone", 's.fax'=>"Fax",
  231. 's.url'=>"Url", 's.email'=>"Email", 's.default_lang'=>"DefaultLang", 's.canvas' => "Canvas", 's.siren'=>"ProfId1", 's.siret'=>"ProfId2", 's.ape'=>"ProfId3", 's.idprof4'=>"ProfId4",
  232. 's.idprof5'=>"ProfId5", 's.idprof6'=>"ProfId6", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_private'=>"NotePrivate", 's.note_public'=>"NotePublic",
  233. 't.libelle'=>"ThirdPartyType", 'ce.code'=>"Staff", "cfj.libelle"=>"JuridicalStatus", 's.fk_prospectlevel'=>'ProspectLevel',
  234. 'st.code'=>'ProspectStatus', 'payterm.libelle'=>'PaymentConditions', 'paymode.libelle'=>'PaymentMode'
  235. );
  236. if (!empty($conf->global->SOCIETE_USEPREFIX)) $this->export_fields_array[$r]['s.prefix'] = 'Prefix';
  237. if (!empty($conf->global->PRODUIT_MULTIPRICES)) $this->export_fields_array[$r]['s.price_level'] = 'PriceLevel';
  238. // Add multicompany field
  239. if (!empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED))
  240. {
  241. $nbofallowedentities = count(explode(',', getEntity('societe'))); // If project are shared, nb will be > 1
  242. if (!empty($conf->multicompany->enabled) && $nbofallowedentities > 1) $this->export_fields_array[$r] += array('s.entity'=>'Entity');
  243. }
  244. $keyforselect = 'societe'; $keyforelement = 'company'; $keyforaliasextra = 'extra';
  245. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  246. $this->export_fields_array[$r] += array('u.login'=>'SaleRepresentativeLogin', 'u.firstname'=>'SaleRepresentativeFirstname', 'u.lastname'=>'SaleRepresentativeLastname');
  247. //$this->export_TypeFields_array[$r]=array(
  248. // 's.rowid'=>"List:societe:nom",'s.nom'=>"Text",'s.status'=>"Text",'s.client'=>"Boolean",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",
  249. // 's.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",
  250. // 'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.default_lang'=>"Text",'s.canvas' => "Canvas",'s.siret'=>"Text",'s.siren'=>"Text",
  251. // 's.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note'=>"Text",
  252. // 't.libelle'=>"Text",'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
  253. // 's.fk_stcomm'=>'List:c_stcomm:libelle:code','d.nom'=>'List:c_departements:nom:rowid'
  254. //);
  255. $this->export_TypeFields_array[$r] = array(
  256. 's.rowid'=>"Numeric", 's.nom'=>"Text", 's.name_alias'=>"Text", 's.status'=>"Numeric", 's.client'=>"Numeric", 's.fournisseur'=>"Boolean", 's.datec'=>"Date", 's.tms'=>"Date",
  257. 's.code_client'=>"Text", 's.code_fournisseur'=>"Text", 's.code_compta'=>"Text", 's.code_compta_fournisseur'=>"Text", 's.address'=>"Text", 's.zip'=>"Text",
  258. 's.town'=>"Text", 'c.label'=>"List:c_country:label:label", 'c.code'=>"Text", 's.phone'=>"Text", 's.fax'=>"Text", 's.url'=>"Text", 's.email'=>"Text",
  259. 's.default_lang'=>"Text", 's.canvas' => "Canvas", 's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.idprof5'=>"Text", 's.idprof6'=>"Text",
  260. 's.tva_intra'=>"Text", 's.capital'=>"Numeric", 's.note_private'=>"Text", 's.note_public'=>"Text", 't.libelle'=>"Text",
  261. 'ce.code'=>"List:c_effectif:libelle:code", "cfj.libelle"=>"Text", 's.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
  262. 'st.code'=>'List:c_stcomm:libelle:code', 'd.nom'=>'Text', 'u.login'=>'Text', 'u.firstname'=>'Text', 'u.lastname'=>'Text', 'payterm.libelle'=>'Text',
  263. 'paymode.libelle'=>'Text', 's.entity'=>'Numeric',
  264. 's.price_level'=>'Numeric'
  265. );
  266. $this->export_entities_array[$r] = array('u.login'=>'user', 'u.firstname'=>'user', 'u.lastname'=>'user'); // We define here only fields that use another picto
  267. $this->export_examplevalues_array[$r] = array('s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)', 's.fournisseur'=>'0 (not a supplier) or 1 (supplier)');
  268. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  269. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
  270. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
  271. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  272. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
  273. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
  274. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
  275. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
  276. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
  277. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON sc.fk_user = u.rowid';
  278. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid';
  279. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id';
  280. $this->export_sql_end[$r] .= ' WHERE s.entity IN ('.getEntity('societe').')';
  281. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  282. $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.$user->id.' ';
  283. if (!empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
  284. $subordinatesids = $user->getAllChildIds();
  285. $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.implode(',', $subordinatesids).')' : '';
  286. }
  287. $this->export_sql_end[$r] .= ')';
  288. }
  289. // Export list of contacts and attributes
  290. $r++;
  291. $this->export_code[$r] = $this->rights_class.'_'.$r;
  292. $this->export_label[$r] = 'ExportDataset_company_2';
  293. $this->export_icon[$r] = 'contact';
  294. $this->export_permission[$r] = array(array("societe", "contact", "export"));
  295. $this->export_fields_array[$r] = array(
  296. 'c.rowid'=>"IdContact", 'c.civility'=>"CivilityCode", 'c.lastname'=>'Lastname', 'c.firstname'=>'Firstname', 'c.poste'=>'PostOrFunction',
  297. 'c.datec'=>"DateCreation", 'c.tms'=>"DateLastModification", 'c.priv'=>"ContactPrivate", 'c.address'=>"Address", 'c.zip'=>"Zip", 'c.town'=>"Town",
  298. 'd.nom'=>'State', 'co.label'=>"Country", 'co.code'=>"CountryCode", 'c.phone'=>"Phone", 'c.fax'=>"Fax", 'c.phone_mobile'=>"Mobile", 'c.email'=>"EMail",
  299. 'c.statut'=>"Status",
  300. 's.rowid'=>"IdCompany", 's.nom'=>"CompanyName", 's.status'=>"Status", 's.code_client'=>"CustomerCode", 's.code_fournisseur'=>"SupplierCode",
  301. 's.code_compta'=>"AccountancyCode", 's.code_compta_fournisseur'=>"SupplierAccountancyCode",
  302. 's.client'=>'Customer', 's.fournisseur'=>'Supplier',
  303. 's.address'=>'Address', 's.zip'=>"Zip", 's.town'=>"Town", 's.phone'=>'Phone', 's.email'=>"Email",
  304. 't.libelle'=>"ThirdPartyType"
  305. );
  306. $this->export_examplevalues_array[$r] = array('s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)', 's.fournisseur'=>'0 (not a supplier) or 1 (supplier)');
  307. $this->export_TypeFields_array[$r] = array(
  308. 'c.civility'=>"List:c_civility:label:code", 'c.lastname'=>'Text', 'c.firstname'=>'Text', 'c.poste'=>'Text', 'c.datec'=>"Date", 'c.priv'=>"Boolean",
  309. 'c.address'=>"Text", 'c.zip'=>"Text", 'c.town'=>"Text", 'd.nom'=>'Text', 'co.label'=>"List:c_country:label:rowid", 'co.code'=>"Text", 'c.phone'=>"Text",
  310. 'c.fax'=>"Text", 'c.email'=>"Text",
  311. 'c.statut'=>"Status",
  312. 's.rowid'=>"List:societe:nom::thirdparty", 's.nom'=>"Text", 's.status'=>"Status", 's.code_client'=>"Text", 's.code_fournisseur'=>"Text",
  313. 's.code_compta'=>"Text", 's.code_compta_fournisseur'=>"Text",
  314. 's.client'=>"Text", 's.fournisseur'=>"Text",
  315. 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 's.phone'=>"Text", 's.email'=>"Text",
  316. 't.libelle'=>"Text"
  317. );
  318. $this->export_entities_array[$r] = array(
  319. 's.rowid'=>"company", 's.nom'=>"company", 's.status'=>'company', 's.code_client'=>"company", 's.code_fournisseur'=>"company",
  320. 's.code_compta'=>"company", 's.code_compta_fournisseur'=>"company",
  321. 's.client'=>"company", 's.fournisseur'=>"company",
  322. 's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 's.phone'=>"company", 's.email'=>"company",
  323. 't.libelle'=>"company"
  324. ); // We define here only fields that use another picto
  325. if (empty($conf->fournisseur->enabled))
  326. {
  327. unset($this->export_fields_array[$r]['s.code_fournisseur']);
  328. unset($this->export_entities_array[$r]['s.code_fournisseur']);
  329. }
  330. $keyforselect = 'socpeople'; $keyforelement = 'contact'; $keyforaliasextra = 'extra';
  331. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  332. $keyforselect = 'societe'; $keyforelement = 'company'; $keyforaliasextra = 'extrasoc';
  333. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  334. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  335. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'socpeople as c';
  336. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
  337. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extrasoc ON s.rowid = extrasoc.fk_object';
  338. if (is_object($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  339. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
  340. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
  341. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
  342. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  343. $this->export_sql_end[$r] .= ' WHERE c.entity IN ('.getEntity('socpeople').')';
  344. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  345. $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.$user->id.' ';
  346. if (!empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
  347. $subordinatesids = $user->getAllChildIds();
  348. $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.implode(',', $subordinatesids).')' : '';
  349. }
  350. $this->export_sql_end[$r] .= ')';
  351. }
  352. // Imports
  353. //--------
  354. $r = 0;
  355. // Import list of third parties and attributes
  356. $r++;
  357. $this->import_code[$r] = $this->rights_class.'_'.$r;
  358. $this->import_label[$r] = 'ImportDataset_company_1';
  359. $this->import_icon[$r] = 'company';
  360. $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
  361. $this->import_tables_array[$r] = array(
  362. 's' => MAIN_DB_PREFIX.'societe',
  363. 'extra' => MAIN_DB_PREFIX.'societe_extrafields'
  364. ); // List of tables to insert into (insert done in same order)
  365. $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe
  366. 's.nom' => "Name*",
  367. 's.name_alias' => "AliasNameShort",
  368. 's.status' => "Status",
  369. 's.code_client' => "CustomerCode",
  370. 's.code_fournisseur' => "SupplierCode",
  371. 's.code_compta' => "CustomerAccountancyCode",
  372. 's.code_compta_fournisseur' => "SupplierAccountancyCode",
  373. 's.address' => "Address",
  374. 's.zip' => "Zip",
  375. 's.town' => "Town",
  376. 's.fk_departement' => "StateCode",
  377. 's.fk_pays' => "CountryCode",
  378. 's.phone' => "Phone",
  379. 's.fax' => "Fax",
  380. 's.url' => "Url",
  381. 's.email' => "Email",
  382. 's.skype' => "Skype",
  383. 's.fk_effectif' => "Staff",
  384. 's.fk_typent' => "ThirdPartyType",
  385. "s.fk_forme_juridique" => "JuridicalStatus",
  386. 's.siren' => "ProfId1",
  387. 's.siret' => "ProfId2",
  388. 's.ape' => "ProfId3",
  389. 's.idprof4' => "ProfId4",
  390. 's.idprof5' => "ProfId5",
  391. 's.idprof6' => "ProfId6",
  392. 's.tva_intra' => "VATIntraShort",
  393. 's.capital' => "Capital",
  394. 's.fk_stcomm' => 'ProspectStatus',
  395. 's.note_private' => "NotePrivate",
  396. 's.note_public' => "NotePublic",
  397. 's.client' => "Customer*",
  398. 's.fournisseur' => "Supplier*",
  399. 's.fk_prospectlevel' => 'ProspectLevel',
  400. 's.mode_reglement' => 'PaymentTypeCustomer',
  401. 's.cond_reglement' => "PaymentTermsCustomer",
  402. 's.mode_reglement_supplier' => 'PaymentTypeSupplier',
  403. 's.cond_reglement_supplier' => "PaymentTermsSupplier",
  404. 's.tva_assuj' => 'VATIsUsed',
  405. 's.barcode' => 'BarCode',
  406. 's.default_lang' => 'DefaultLanguage',
  407. 's.canvas' => "Canvas",
  408. 's.datec' => "DateCreation",
  409. 's.fk_multicurrency' => 'MulticurrencyUsed',
  410. 's.multicurrency_code' => 'MulticurrencyCurrency'
  411. );
  412. if (!empty($conf->global->PRODUIT_MULTIPRICES)) $this->import_fields_array[$r]['s.price_level'] = 'PriceLevel';
  413. // Add extra fields
  414. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe' AND entity IN (0, ".$conf->entity.")";
  415. $resql = $this->db->query($sql);
  416. if ($resql) // This can fail when class is used on old database (during migration for example)
  417. {
  418. while ($obj = $this->db->fetch_object($resql)) {
  419. $fieldname = 'extra.'.$obj->name;
  420. $fieldlabel = ucfirst($obj->label);
  421. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  422. }
  423. }
  424. // End add extra fields
  425. $this->import_fieldshidden_array[$r] = array(
  426. 's.fk_user_creat' => 'user->id',
  427. 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'societe'
  428. ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
  429. $this->import_convertvalue_array[$r] = array(//field order as per structure of table llx_societe
  430. 's.code_client' => array('rule' => 'getcustomercodeifauto'),
  431. 's.code_fournisseur' => array('rule' => 'getsuppliercodeifauto'),
  432. 's.code_compta' => array('rule' => 'getcustomeraccountancycodeifauto'),
  433. 's.code_compta_fournisseur' => array('rule' => 'getsupplieraccountancycodeifauto'),
  434. 's.fk_departement' => array(
  435. 'rule' => 'fetchidfromcodeid',
  436. 'classfile' => '/core/class/cstate.class.php',
  437. 'class' => 'Cstate',
  438. 'method' => 'fetch',
  439. 'dict' => 'DictionaryStateCode'
  440. ),
  441. 's.fk_pays' => array(
  442. 'rule' => 'fetchidfromcodeid',
  443. 'classfile' => '/core/class/ccountry.class.php',
  444. 'class' => 'Ccountry',
  445. 'method' => 'fetch',
  446. 'dict' => 'DictionaryCountry'
  447. ),
  448. 's.fk_typent' => array(
  449. 'rule' => 'fetchidfromcodeorlabel',
  450. 'classfile' => '/core/class/ctypent.class.php',
  451. 'class' => 'Ctypent',
  452. 'method' => 'fetch',
  453. 'dict' => 'DictionaryCompanyType'
  454. ),
  455. 's.capital' => array('rule' => 'numeric'),
  456. 's.fk_stcomm' => array('rule' => 'zeroifnull'),
  457. );
  458. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  459. $this->import_regex_array[$r] = array(//field order as per structure of table llx_societe
  460. 's.status' => '^[0|1]',
  461. 's.fk_typent' => 'id@'.MAIN_DB_PREFIX.'c_typent',
  462. 's.client' => '^[0|1|2|3]',
  463. 's.fournisseur' => '^[0|1]',
  464. 's.mode_reglement' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
  465. 's.cond_reglement' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
  466. 's.mode_reglement_supplier' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
  467. 's.cond_reglement_supplier' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
  468. 's.tva_assuj' => '^[0|1]',
  469. 's.fk_multicurrency' => '^[0|1]',
  470. 's.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$',
  471. 's.multicurrency_code' => 'code_iso@'.MAIN_DB_PREFIX.'c_currencies'
  472. );
  473. $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe
  474. 's.nom' => "TPBigCompany",
  475. 's.name_alias' => "Alias for TPBigCompany",
  476. 's.status' => "0 (closed) / 1 (active)",
  477. 's.code_client' => 'eg. CU01-0001 / empty / "auto"',
  478. 's.code_fournisseur' => 'eg. SU01-0001 / empty / "auto"',
  479. 's.code_compta' => "Code or empty to be auto-created",
  480. 's.code_compta_fournisseur' => "Code or empty to be auto-created",
  481. 's.address' => "61 Jump Street",
  482. 's.zip' => "123456",
  483. 's.town' => "Bigtown",
  484. 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
  485. 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
  486. 's.phone' => "eg: +34123456789",
  487. 's.fax' => "eg. +34987654321",
  488. 's.url' => "e.g. https://www.mybigcompany.com",
  489. 's.email' => "e.g. test@mybigcompany.com",
  490. 's.skype' => "Skype name",
  491. 's.fk_effectif' => "1/2/3/5: represents one of the five ranges of employees",
  492. 's.fk_typent' => 'matches field "id" (1-9 etc.) OR "code" (TE_SMALL etc.) in table "'.MAIN_DB_PREFIX.'c_typent"',
  493. 's.fk_forme_juridique' => '1/2/3 etc...matches field "code" in table "'.MAIN_DB_PREFIX.'c_forme_juridique"',
  494. 's.siret' => "",
  495. 's.siren' => "",
  496. 's.ape' => "",
  497. 's.idprof4' => "",
  498. 's.idprof5' => "",
  499. 's.idprof6' => "",
  500. 's.tva_intra' => 'VAT number e.g."FR0123456789"',
  501. 's.capital' => "10000",
  502. 's.fk_stcomm' => '-1/0/1/2 etc... matches field "id" in table "'.MAIN_DB_PREFIX.'c_stcomm"',
  503. 's.note_private' => "Example of a PRIVATE note.",
  504. 's.note_public' => "Example of a PUBLIC note.",
  505. 's.client' => '0 (no customer no prospect) / 1 (customer) / 2 (prospect)/ 3 (customer and prospect)',
  506. 's.fournisseur' => '0 (not supplier) / 1 (supplier)',
  507. 's.fk_prospectlevel' => 'eg. "PL_MEDIUM" matches field "code" in table "'.MAIN_DB_PREFIX.'c_prospectlevel"',
  508. 's.mode_reglement' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
  509. 's.cond_reglement' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
  510. 's.mode_reglement_supplier' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
  511. 's.cond_reglement_supplier' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
  512. 's.tva_assuj' => '0 (VAT not used) / 1 (VAT used)',
  513. 's.barcode' => '123456789',
  514. 's.default_lang' => 'en_US / es_ES etc...matches a language directory in htdocs/langs/',
  515. 's.canvas' => "empty / a custom canvas form layout url e.g. mycanvas@mymodule",
  516. 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
  517. 's.fk_multicurrency' => '0 (use system default currency) / 1 (use local currency)',
  518. 's.multicurrency_code' => 'GBP/USD etc... matches field "code_iso" in table "'.MAIN_DB_PREFIX.'c_currencies"'
  519. );
  520. $this->import_updatekeys_array[$r] = array(
  521. 's.nom' => 'Name',
  522. 's.code_client' => 'CustomerCode',
  523. 's.code_fournisseur' => 'SupplierCode',
  524. 's.code_compta' => 'CustomerAccountancyCode',
  525. 's.code_compta_fournisseur' => 'SupplierAccountancyCode'
  526. );
  527. // Import list of contacts/additional addresses and attributes
  528. $r++;
  529. $this->import_code[$r] = $this->rights_class.'_'.$r;
  530. $this->import_label[$r] = 'ImportDataset_company_2';
  531. $this->import_icon[$r] = 'contact';
  532. $this->import_entities_array[$r] = array('s.fk_soc' => 'company'); // We define here only fields that use a different icon than the one defined in import_icon
  533. $this->import_tables_array[$r] = array(
  534. 's' => MAIN_DB_PREFIX.'socpeople',
  535. 'extra' => MAIN_DB_PREFIX.'socpeople_extrafields'
  536. ); // List of tables to insert into (insert done in same order)
  537. $this->import_fields_array[$r] = array(//field order as per structure of table llx_socpeople
  538. 's.rowid' => 'Id',
  539. 's.datec' => "DateCreation",
  540. 's.fk_soc' => 'ThirdPartyName',
  541. 's.civility' => 'UserTitle',
  542. 's.lastname' => "Lastname*",
  543. 's.firstname' => "Firstname",
  544. 's.address' => "Address",
  545. 's.zip' => "Zip",
  546. 's.town' => "Town",
  547. 's.fk_departement' => "StateCode",
  548. 's.fk_pays' => "CountryCode",
  549. 's.birthday' => "BirthdayDate",
  550. 's.poste' => "Role",
  551. 's.phone' => "Phone",
  552. 's.phone_perso' => "PhonePerso",
  553. 's.phone_mobile' => "PhoneMobile",
  554. 's.fax' => "Fax",
  555. 's.email' => "Email",
  556. 's.skype' => "Skype",
  557. 's.note_private' => "NotePrivate",
  558. 's.note_public' => "NotePublic"
  559. );
  560. // Add extra fields
  561. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")";
  562. $resql = $this->db->query($sql);
  563. if ($resql) // This can fail when class is used on an old database (during a migration for example)
  564. {
  565. while ($obj = $this->db->fetch_object($resql)) {
  566. $fieldname = 'extra.'.$obj->name;
  567. $fieldlabel = ucfirst($obj->label);
  568. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  569. }
  570. }
  571. // End add extra fields
  572. $this->import_fieldshidden_array[$r] = array(
  573. 's.fk_user_creat' => 'user->id',
  574. 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'socpeople'
  575. ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
  576. $this->import_convertvalue_array[$r] = array(
  577. 's.fk_soc' => array(
  578. 'rule' => 'fetchidfromref',
  579. 'file' => '/societe/class/societe.class.php',
  580. 'class' => 'Societe',
  581. 'method' => 'fetch',
  582. 'element' => 'ThirdParty'
  583. ),
  584. 's.fk_departement' => array(
  585. 'rule' => 'fetchidfromcodeid',
  586. 'classfile' => '/core/class/cstate.class.php',
  587. 'class' => 'Cstate',
  588. 'method' => 'fetch',
  589. 'dict' => 'DictionaryStateCode'
  590. ),
  591. 's.fk_pays' => array(
  592. 'rule' => 'fetchidfromcodeid',
  593. 'classfile' => '/core/class/ccountry.class.php',
  594. 'class' => 'Ccountry',
  595. 'method' => 'fetch',
  596. 'dict' => 'DictionaryCountry'
  597. ),
  598. );
  599. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  600. $this->import_regex_array[$r] = array(
  601. 's.birthday' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
  602. 's.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$'
  603. );
  604. $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_socpeople
  605. 's.rowid' => '1',
  606. 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
  607. 's.fk_soc' => 'Third Party name eg. TPBigCompany',
  608. 's.civility' => 'Title of civility eg: MR...matches field "code" in table "'.MAIN_DB_PREFIX.'c_civility"',
  609. 's.lastname' => "lastname or label",
  610. 's.firstname' => 'John',
  611. 's.address' => '61 Jump street',
  612. 's.zip' => '75000',
  613. 's.town' => 'Bigtown',
  614. 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
  615. 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
  616. 's.birthday' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
  617. 's.poste' => "Director",
  618. 's.phone' => "5551122",
  619. 's.phone_perso' => "5551133",
  620. 's.phone_mobile' => "5551144",
  621. 's.fax' => "5551155",
  622. 's.email' => "johnsmith@email.com",
  623. 's.skype' => "skype username",
  624. 's.note_private' => "My private note",
  625. 's.note_public' => "My public note"
  626. );
  627. $this->import_updatekeys_array[$r] = array(
  628. 's.rowid' => 'Id'
  629. );
  630. // Import Bank Accounts
  631. $r++;
  632. $this->import_code[$r] = $this->rights_class.'_'.$r;
  633. $this->import_label[$r] = "ImportDataset_company_3"; // Translation key
  634. $this->import_icon[$r] = 'company';
  635. $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon to the one defined in import_icon
  636. $this->import_tables_array[$r] = array('sr' => MAIN_DB_PREFIX.'societe_rib');
  637. $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe_rib
  638. 'sr.label' => "Label*",
  639. 'sr.fk_soc' => "ThirdPartyName*",
  640. 'sr.datec' => "DateCreation*",
  641. 'sr.bank' => "Bank",
  642. 'sr.code_banque' => "BankCode",
  643. 'sr.code_guichet' => "DeskCode",
  644. 'sr.number' => "BankAccountNumber*",
  645. 'sr.cle_rib' => "BankAccountNumberKey",
  646. 'sr.bic' => "BIC",
  647. 'sr.iban_prefix' => "IBAN",
  648. 'sr.domiciliation' => "BankAccountDomiciliation",
  649. 'sr.proprio' => "BankAccountOwner",
  650. 'sr.owner_address' => "BankAccountOwnerAddress",
  651. 'sr.default_rib' => 'Default',
  652. 'sr.rum' => 'RUM',
  653. 'sr.type' => "Type ban is defaut",
  654. );
  655. $this->import_convertvalue_array[$r] = array(
  656. 'sr.fk_soc' => array(
  657. 'rule' => 'fetchidfromref',
  658. 'classfile' => '/societe/class/societe.class.php',
  659. 'class' => 'Societe',
  660. 'method' => 'fetch',
  661. 'element' => 'ThirdParty'
  662. )
  663. );
  664. $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe_rib
  665. 'sr.label' => 'eg. "account1"',
  666. 'sr.fk_soc' => 'eg. "TPBigCompany"',
  667. 'sr.datec' => 'date used for creating direct debit UMR formatted as '.dol_print_date(dol_now(),
  668. '%Y-%m-%d'),
  669. 'sr.bank' => 'bank name eg: "ING-Direct"',
  670. 'sr.code_banque' => 'account sort code (GB)/Routing number (US) eg. "8456"',
  671. 'sr.code_guichet' => "bank code for office/branch",
  672. 'sr.number' => 'account number eg. "3333333333"',
  673. 'sr.cle_rib' => 'account checksum/control digits (if used) eg. "22"',
  674. 'sr.bic' => 'bank identifier eg. "USHINGMMXXX"',
  675. 'sr.iban_prefix' => 'complete account IBAN eg. "GB78CPBK08925068637123"',
  676. 'sr.domiciliation' => 'bank branch address eg. "PARIS"',
  677. 'sr.proprio' => 'name on the bank account',
  678. 'sr.owner_address' => 'address of account holder',
  679. 'sr.default_rib' => '1 (default account) / 0 (not default)',
  680. 'sr.rum' => 'RUM code',
  681. 'sr.type' => 'ban',
  682. );
  683. // Import Company Sales representatives
  684. $r++;
  685. $this->import_code[$r] = $this->rights_class.'_'.$r;
  686. $this->import_label[$r] = "ImportDataset_company_4"; // Translation key
  687. $this->import_icon[$r] = 'company';
  688. $this->import_entities_array[$r] = array('sr.fk_user'=>'user'); // We define here only fields that use another icon that the one defined into import_icon
  689. $this->import_tables_array[$r] = array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
  690. $this->import_fields_array[$r] = array('sr.fk_soc'=>"ThirdPartyName*", 'sr.fk_user'=>"User*");
  691. $this->import_convertvalue_array[$r] = array(
  692. 'sr.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'),
  693. 'sr.fk_user'=>array('rule'=>'fetchidfromref', 'classfile'=>'/user/class/user.class.php', 'class'=>'User', 'method'=>'fetch', 'element'=>'User')
  694. );
  695. $this->import_examplevalues_array[$r] = array('sr.fk_soc'=>"MyBigCompany", 'sr.fk_user'=>"login");
  696. }
  697. /**
  698. * Function called when module is enabled.
  699. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  700. * It also creates data directories
  701. *
  702. * @param string $options Options when enabling module ('', 'noboxes')
  703. * @return int 1 if OK, 0 if KO
  704. */
  705. public function init($options = '')
  706. {
  707. global $conf, $langs;
  708. // We disable this to prevent pb of modules not correctly disabled
  709. //$this->remove($options);
  710. //ODT template
  711. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
  712. $dirodt = DOL_DATA_ROOT.'/doctemplates/thirdparties';
  713. $dest = $dirodt.'/template_thirdparty.odt';
  714. if (file_exists($src) && !file_exists($dest))
  715. {
  716. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  717. dol_mkdir($dirodt);
  718. $result = dol_copy($src, $dest, 0, 0);
  719. if ($result < 0)
  720. {
  721. $langs->load("errors");
  722. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  723. return 0;
  724. }
  725. }
  726. $sql = array();
  727. return $this->_init($sql, $options);
  728. }
  729. }