modSociete.class.php 40 KB

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