modSociete.class.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  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. * Copyright (C) 2022 Ferran Marcet <fmarcet@2byte.es>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \defgroup societe Module societe
  25. * \brief Module to manage third parties (customers, prospects)
  26. * \file htdocs/core/modules/modSociete.class.php
  27. * \ingroup societe
  28. * \brief Description and activation file for the module societe (thirdparty)
  29. */
  30. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  31. /**
  32. * Class to describe and enable module Societe
  33. */
  34. class modSociete extends DolibarrModules
  35. {
  36. /**
  37. * Constructor. Define names, constants, directories, boxes, permissions
  38. *
  39. * @param DoliDB $db Database handler
  40. */
  41. public function __construct($db)
  42. {
  43. global $conf, $user, $mysoc, $langs;
  44. $this->db = $db;
  45. $this->numero = 1;
  46. $this->family = "crm";
  47. $this->module_position = '09';
  48. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  49. $this->name = preg_replace('/^mod/i', '', get_class($this));
  50. $this->description = "Gestion des sociétés et contacts";
  51. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  52. $this->version = 'dolibarr';
  53. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  54. $this->config_page_url = array("societe.php@societe");
  55. // Name of image file used for this module.
  56. $this->picto = 'company';
  57. // Data directories to create when module is enabled
  58. $this->dirs = array("/societe/temp");
  59. // Dependencies
  60. $this->hidden = false; // A condition to hide module
  61. $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
  62. $this->requiredby = array("modExpedition", "modFacture", "modFournisseur", "modFicheinter", "modPropale", "modContrat", "modCommande"); // List of module ids to disable if this one is disabled
  63. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  64. $this->phpmin = array(7, 0); // Minimum version of PHP required by module
  65. $this->langfiles = array("companies", 'bills', "compta", "admin", "banks");
  66. // Constants
  67. $this->const = array();
  68. $r = 0;
  69. $this->const[$r][0] = "SOCIETE_CODECLIENT_ADDON";
  70. $this->const[$r][1] = "chaine";
  71. $this->const[$r][2] = "mod_codeclient_monkey";
  72. $this->const[$r][3] = 'Module to control third parties codes';
  73. $this->const[$r][4] = 0;
  74. $r++;
  75. $this->const[$r][0] = "SOCIETE_CODECOMPTA_ADDON";
  76. $this->const[$r][1] = "chaine";
  77. $this->const[$r][2] = "mod_codecompta_panicum";
  78. $this->const[$r][3] = 'Module to control third parties codes';
  79. $this->const[$r][4] = 0;
  80. $r++;
  81. $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
  82. $this->const[$r][1] = "chaine";
  83. $this->const[$r][2] = "0";
  84. $this->const[$r][3] = "Enter the month number of the first month of the fiscal year, e. g. 9 for September";
  85. $this->const[$r][4] = 0;
  86. $r++;
  87. $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
  88. $this->const[$r][1] = "chaine";
  89. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
  90. $this->const[$r][3] = "";
  91. $this->const[$r][4] = 0;
  92. $r++;
  93. /*
  94. $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
  95. $this->const[$r][1] = "chaine";
  96. $this->const[$r][2] = "0";
  97. $this->const[$r][3] = "hide thirdparty customer inative in combobox";
  98. $this->const[$r][4] = 1;
  99. $r++;
  100. */
  101. $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
  102. $this->const[$r][1] = "yesno";
  103. $this->const[$r][2] = "0";
  104. $this->const[$r][3] = "Display customer ref into select list";
  105. $this->const[$r][4] = 0;
  106. $r++;
  107. // Boxes
  108. $this->boxes = array(
  109. 0=>array('file'=>'box_clients.php', 'enabledbydefaulton'=>'Home'),
  110. 1=>array('file'=>'box_prospect.php', 'enabledbydefaulton'=>'Home'),
  111. 2=>array('file'=>'box_contacts.php', 'enabledbydefaulton'=>'Home'),
  112. 3=>array('file'=>'box_activity.php', 'enabledbydefaulton'=>'Home', 'note'=>'(WarningUsingThisBoxSlowDown)'),
  113. 4=>array('file'=>'box_goodcustomers.php', 'enabledbydefaulton'=>'Home', 'note'=>'(WarningUsingThisBoxSlowDown)'),
  114. );
  115. // Permissions
  116. $this->rights = array();
  117. $this->rights_class = 'societe';
  118. $r = 0;
  119. $r++;
  120. $this->rights[$r][0] = 121; // id de la permission
  121. $this->rights[$r][1] = 'Read third parties'; // libelle de la permission
  122. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  123. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  124. $this->rights[$r][4] = 'lire';
  125. /*$r++;
  126. $this->rights[$r][0] = 241;
  127. $this->rights[$r][1] = 'Read thirdparties customers';
  128. $this->rights[$r][2] = 'r';
  129. $this->rights[$r][3] = 0;
  130. $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  131. $this->rights[$r][5] = 'read';
  132. $r++;
  133. $this->rights[$r][0] = 242;
  134. $this->rights[$r][1] = 'Read thirdparties suppliers';
  135. $this->rights[$r][2] = 'r';
  136. $this->rights[$r][3] = 0;
  137. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  138. $this->rights[$r][5] = 'read';
  139. */
  140. $r++;
  141. $this->rights[$r][0] = 122; // id de la permission
  142. $this->rights[$r][1] = 'Create and update third parties'; // libelle de la permission
  143. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  144. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  145. $this->rights[$r][4] = 'creer';
  146. /* $r++;
  147. $this->rights[$r][0] = 251;
  148. $this->rights[$r][1] = 'Create thirdparties customers';
  149. $this->rights[$r][2] = 'r';
  150. $this->rights[$r][3] = 0;
  151. $this->rights[$r][4] = 'thirdparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  152. $this->rights[$r][5] = 'read';
  153. $r++;
  154. $this->rights[$r][0] = 252;
  155. $this->rights[$r][1] = 'Create thirdparties suppliers';
  156. $this->rights[$r][2] = 'r';
  157. $this->rights[$r][3] = 0;
  158. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  159. $this->rights[$r][5] = 'read';
  160. */
  161. $r++;
  162. $this->rights[$r][0] = 125; // id de la permission
  163. $this->rights[$r][1] = 'Delete third parties'; // libelle de la permission
  164. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  165. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  166. $this->rights[$r][4] = 'supprimer';
  167. $r++;
  168. $this->rights[$r][0] = 126; // id de la permission
  169. $this->rights[$r][1] = 'Export third parties'; // libelle de la permission
  170. $this->rights[$r][2] = 'r'; // 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] = 'export';
  173. $r++;
  174. $this->rights[$r][0] = 130;
  175. $this->rights[$r][1] = 'Modify thirdparty information payment';
  176. $this->rights[$r][3] = 0;
  177. $this->rights[$r][4] = 'thirdparty_paymentinformation_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  178. $this->rights[$r][5] = 'write';
  179. // 262 : Restrict access to sales representative
  180. $r++;
  181. $this->rights[$r][0] = 262;
  182. $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).';
  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. /*
  188. $r++;
  189. $this->rights[$r][0] = 263;
  190. $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).';
  191. $this->rights[$r][2] = 'r';
  192. $this->rights[$r][3] = 0;
  193. $this->rights[$r][4] = 'client';
  194. $this->rights[$r][5] = 'readallthirdparties_advance';
  195. */
  196. $r++;
  197. $this->rights[$r][0] = 281; // id de la permission
  198. $this->rights[$r][1] = 'Read contacts'; // libelle de la permission
  199. $this->rights[$r][2] = 'r'; // 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] = 'lire';
  203. $r++;
  204. $this->rights[$r][0] = 282; // id de la permission
  205. $this->rights[$r][1] = 'Create and update contact'; // libelle de la permission
  206. $this->rights[$r][2] = 'w'; // 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] = 'creer';
  210. $r++;
  211. $this->rights[$r][0] = 283; // id de la permission
  212. $this->rights[$r][1] = 'Delete 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] = 'supprimer';
  217. $r++;
  218. $this->rights[$r][0] = 286; // id de la permission
  219. $this->rights[$r][1] = 'Export contacts'; // libelle de la permission
  220. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  221. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  222. $this->rights[$r][4] = 'contact';
  223. $this->rights[$r][5] = 'export';
  224. // Menus
  225. //-------
  226. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  227. // Exports
  228. //--------
  229. $r = 0;
  230. // Export list of third parties and attributes
  231. $r++;
  232. $this->export_code[$r] = $this->rights_class.'_'.$r;
  233. $this->export_label[$r] = 'ExportDataset_company_1';
  234. $this->export_icon[$r] = 'company';
  235. $this->export_permission[$r] = array(array("societe", "export"));
  236. $this->export_fields_array[$r] = array(
  237. 's.rowid'=>"Id", 's.nom'=>"Name", 's.name_alias'=>"AliasNameShort", 'ps.nom'=>"ParentCompany",
  238. 's.status'=>"Status", 's.client'=>"Customer", 's.fournisseur'=>"Supplier", 's.datec'=>"DateCreation", 's.tms'=>"DateLastModification",
  239. 's.code_client'=>"CustomerCode", 's.code_fournisseur'=>"SupplierCode", 's.code_compta'=>"AccountancyCode", 's.code_compta_fournisseur'=>"SupplierAccountancyCode",
  240. '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",
  241. '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",
  242. 's.idprof5'=>"ProfId5", 's.idprof6'=>"ProfId6", 's.tva_intra'=>"VATIntraShort", 's.capital'=>"Capital", 's.note_private'=>"NotePrivate", 's.note_public'=>"NotePublic",
  243. 't.code'=>"ThirdPartyType", 'ce.code'=>"DictionaryStaff", "cfj.libelle"=>"JuridicalStatus", 's.fk_prospectlevel'=>'ProspectLevel',
  244. 'st.code'=>'ProspectStatus', 'payterm.libelle'=>'PaymentConditions', 'paymode.libelle'=>'PaymentMode',
  245. 's.outstanding_limit'=>'OutstandingBill', 'pbacc.ref'=>'PaymentBankAccount', 'incoterm.code'=>'IncotermLabel'
  246. );
  247. if (getDolGlobalString('SOCIETE_USEPREFIX')) {
  248. $this->export_fields_array[$r]['s.prefix'] = 'Prefix';
  249. }
  250. if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
  251. $this->export_fields_array[$r]['s.price_level'] = 'PriceLevel';
  252. }
  253. if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
  254. $this->export_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode');
  255. }
  256. // Add multicompany field
  257. if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
  258. $nbofallowedentities = count(explode(',', getEntity('societe'))); // If project are shared, nb will be > 1
  259. if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
  260. $this->export_fields_array[$r] += array('s.entity'=>'Entity');
  261. }
  262. }
  263. $keyforselect = 'societe';
  264. $keyforelement = 'company';
  265. $keyforaliasextra = 'extra';
  266. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  267. $this->export_fields_array[$r] += array('u.login'=>'SaleRepresentativeLogin', 'u.firstname'=>'SaleRepresentativeFirstname', 'u.lastname'=>'SaleRepresentativeLastname');
  268. $this->export_TypeFields_array[$r] = array(
  269. 's.rowid'=>"Numeric", 's.nom'=>"Text", 's.name_alias'=>"Text", 'ps.nom'=>"Text",
  270. 's.status'=>"Numeric", 's.client'=>"Numeric", 's.fournisseur'=>"Boolean", 's.datec'=>"Date", 's.tms'=>"Date",
  271. 's.code_client'=>"Text", 's.code_fournisseur'=>"Text", 's.code_compta'=>"Text", 's.code_compta_fournisseur'=>"Text",
  272. 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text",
  273. 'd.nom'=>'Text', 'r.nom'=>'Text', 'c.label'=>'List:c_country:label:label', 'c.code'=>'Text',
  274. 's.phone'=>"Text", 's.fax'=>"Text",
  275. 's.url'=>"Text", 's.email'=>"Text", 's.default_lang'=>"Text", 's.canvas' => "Text",
  276. 's.siret'=>"Text", 's.siren'=>"Text", 's.ape'=>"Text", 's.idprof4'=>"Text", 's.idprof5'=>"Text", 's.idprof6'=>"Text",
  277. 's.tva_intra'=>"Text", 's.capital'=>"Numeric",
  278. 's.note_private'=>"Text", 's.note_public'=>"Text",
  279. 't.code'=>"List:c_typent:libelle:code",
  280. 'ce.code'=>"List:c_effectif:libelle:code",
  281. "cfj.libelle"=>"Text",
  282. 's.fk_prospectlevel'=>'List:c_prospectlevel:label:code',
  283. 'st.code'=>'List:c_stcomm:libelle:code',
  284. 'payterm.libelle'=>'Text', 'paymode.libelle'=>'Text',
  285. 's.outstanding_limit'=>'Numeric', 'pbacc.ref'=>'Text', 'incoterm.code'=>'Text',
  286. 'u.login'=>'Text', 'u.firstname'=>'Text', 'u.lastname'=>'Text',
  287. 's.entity'=>'List:entity:label:rowid', 's.price_level'=>'Numeric',
  288. 's.accountancy_code_sell'=>'Text', 's.accountancy_code_buy'=>'Text'
  289. );
  290. $this->export_entities_array[$r] = array( // We define here only fields that use another picto
  291. 'u.login'=>'user',
  292. 'u.firstname'=>'user',
  293. 'u.lastname'=>'user');
  294. $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)');
  295. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  296. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
  297. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
  298. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON s.parent = ps.rowid';
  299. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  300. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
  301. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
  302. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
  303. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
  304. $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';
  305. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
  306. $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';
  307. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid';
  308. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id';
  309. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as pbacc ON s.fk_account = pbacc.rowid';
  310. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as incoterm ON s.fk_incoterms = incoterm.rowid';
  311. $this->export_sql_end[$r] .= ' WHERE s.entity IN ('.getEntity('societe').')';
  312. if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
  313. $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
  314. if (getDolGlobalString('SOCIETE_EXPORT_SUBORDINATES_CHILDS')) {
  315. $subordinatesids = $user->getAllChildIds();
  316. $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
  317. }
  318. $this->export_sql_end[$r] .= ')';
  319. }
  320. // Export list of contacts and attributes
  321. $r++;
  322. $this->export_code[$r] = $this->rights_class.'_'.$r;
  323. $this->export_label[$r] = 'ExportDataset_company_2';
  324. $this->export_icon[$r] = 'contact';
  325. $this->export_permission[$r] = array(array("societe", "contact", "export"));
  326. $this->export_fields_array[$r] = array(
  327. 'c.rowid'=>"IdContact", 'c.civility'=>"CivilityCode", 'c.lastname'=>'Lastname', 'c.firstname'=>'Firstname', 'c.poste'=>'PostOrFunction',
  328. 'c.datec'=>"DateCreation", 'c.tms'=>"DateLastModification", 'c.priv'=>"ContactPrivate", 'c.address'=>"Address", 'c.zip'=>"Zip", 'c.town'=>"Town",
  329. '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",
  330. 'c.note_private'=>'NotePrivate', 'c.note_public'=>"NotePublic",
  331. 'c.statut'=>"Status",
  332. 's.rowid'=>"IdCompany", 's.nom'=>"CompanyName", 's.status'=>"Status", 's.code_client'=>"CustomerCode", 's.code_fournisseur'=>"SupplierCode",
  333. 's.code_compta'=>"AccountancyCode", 's.code_compta_fournisseur'=>"SupplierAccountancyCode",
  334. 's.client'=>'Customer', 's.fournisseur'=>'Supplier',
  335. 's.address'=>'Address', 's.zip'=>"Zip", 's.town'=>"Town", 's.phone'=>'Phone', 's.email'=>"Email",
  336. 's.note_private'=>'NotePrivate', 's.note_public'=>"NotePublic",
  337. 't.code'=>"ThirdPartyType"
  338. );
  339. // Add multicompany field
  340. if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
  341. if (isModEnabled('multicompany')) {
  342. $nbofallowedentities = count(explode(',', getEntity('contact')));
  343. if ($nbofallowedentities > 1) {
  344. $this->export_fields_array[$r]['c.entity'] = 'Entity';
  345. }
  346. $nbofallowedentities = count(explode(',', getEntity('societe')));
  347. if ($nbofallowedentities > 1) {
  348. $this->export_fields_array[$r]['s.entity'] = 'Entity';
  349. }
  350. }
  351. }
  352. $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)');
  353. $this->export_TypeFields_array[$r] = array(
  354. 'c.civility'=>"List:c_civility:label:code", 'c.lastname'=>'Text', 'c.firstname'=>'Text', 'c.poste'=>'Text', 'c.datec'=>"Date", 'c.priv'=>"Boolean",
  355. '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",
  356. 'c.fax'=>"Text", 'c.email'=>"Text",
  357. 'c.statut'=>"Status",
  358. 's.rowid'=>"Numeric", 's.nom'=>"Text", 's.status'=>"Status", 's.code_client'=>"Text", 's.code_fournisseur'=>"Text",
  359. 's.code_compta'=>"Text", 's.code_compta_fournisseur'=>"Text",
  360. 's.client'=>"Numeric", 's.fournisseur'=>"Numeric",
  361. 's.address'=>"Text", 's.zip'=>"Text", 's.town'=>"Text", 's.phone'=>"Text", 's.email'=>"Text",
  362. 't.code'=>"List:c_stcomm:libelle:code",
  363. 'c.entity'=>'List:entity:label:rowid',
  364. 's.entity'=>'List:entity:label:rowid',
  365. );
  366. $this->export_entities_array[$r] = array( // We define here only fields that use another picto
  367. 's.rowid'=>"company", 's.nom'=>"company", 's.status'=>'company', 's.code_client'=>"company", 's.code_fournisseur'=>"company",
  368. 's.code_compta'=>"company", 's.code_compta_fournisseur'=>"company",
  369. 's.client'=>"company", 's.fournisseur'=>"company",
  370. 's.address'=>"company", 's.zip'=>"company", 's.town'=>"company", 's.phone'=>"company", 's.email'=>"company",
  371. 't.code'=>"company",
  372. 's.entity'=>'company',
  373. ); // We define here only fields that use another picto
  374. if (!isModEnabled("supplier_order") && !isModEnabled("supplier_invoice")) {
  375. unset($this->export_fields_array[$r]['s.code_fournisseur']);
  376. unset($this->export_entities_array[$r]['s.code_fournisseur']);
  377. }
  378. $keyforselect = 'socpeople';
  379. $keyforelement = 'contact';
  380. $keyforaliasextra = 'extra';
  381. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  382. $keyforselect = 'societe';
  383. $keyforelement = 'company';
  384. $keyforaliasextra = 'extrasoc';
  385. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  386. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  387. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'socpeople as c';
  388. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
  389. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extrasoc ON s.rowid = extrasoc.fk_object';
  390. if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
  391. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  392. }
  393. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
  394. $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';
  395. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
  396. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
  397. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  398. $this->export_sql_end[$r] .= ' WHERE c.entity IN ('.getEntity('contact').')';
  399. if (is_object($user) && !$user->hasRight('societe', 'client', 'voir')) {
  400. $this->export_sql_end[$r] .= ' AND (sc.fk_user = '.((int) $user->id).' ';
  401. if (getDolGlobalString('SOCIETE_EXPORT_SUBORDINATES_CHILDS')) {
  402. $subordinatesids = $user->getAllChildIds();
  403. $this->export_sql_end[$r] .= count($subordinatesids) > 0 ? ' OR (sc.fk_user IN ('.$this->db->sanitize(implode(',', $subordinatesids)).')' : '';
  404. }
  405. $this->export_sql_end[$r] .= ')';
  406. }
  407. // Imports
  408. //--------
  409. $r = 0;
  410. // Import list of third parties and attributes
  411. $r++;
  412. $this->import_code[$r] = $this->rights_class.'_'.$r;
  413. $this->import_label[$r] = 'ImportDataset_company_1';
  414. $this->import_icon[$r] = 'company';
  415. $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon from the one defined in import_icon
  416. $this->import_tables_array[$r] = array(
  417. 's' => MAIN_DB_PREFIX.'societe',
  418. 'extra' => MAIN_DB_PREFIX.'societe_extrafields'
  419. ); // List of tables to insert into (insert done in same order)
  420. $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe
  421. 's.nom' => "ThirdPartyName*",
  422. 's.name_alias' => "AliasNameShort",
  423. 's.parent' => "ParentCompany",
  424. 's.status' => "Status*",
  425. 's.code_client' => "CustomerCode",
  426. 's.code_fournisseur' => "SupplierCode",
  427. 's.code_compta' => "CustomerAccountancyCode",
  428. 's.code_compta_fournisseur' => "SupplierAccountancyCode",
  429. 's.address' => "Address",
  430. 's.zip' => "Zip",
  431. 's.town' => "Town",
  432. 's.fk_departement' => "StateCode",
  433. 's.fk_pays' => "CountryCode",
  434. 's.phone' => "Phone",
  435. 's.fax' => "Fax",
  436. 's.url' => "Url",
  437. 's.email' => "Email",
  438. 's.fk_effectif' => "Staff",
  439. 's.fk_typent' => "ThirdPartyType",
  440. "s.fk_forme_juridique" => "JuridicalStatus",
  441. 's.siren' => "ProfId1",
  442. 's.siret' => "ProfId2",
  443. 's.ape' => "ProfId3",
  444. 's.idprof4' => "ProfId4",
  445. 's.idprof5' => "ProfId5",
  446. 's.idprof6' => "ProfId6",
  447. 's.tva_intra' => "VATIntraShort",
  448. 's.capital' => "Capital",
  449. 's.fk_stcomm' => 'ProspectStatus',
  450. 's.note_private' => "NotePrivate",
  451. 's.note_public' => "NotePublic",
  452. 's.client' => "Customer*",
  453. 's.fournisseur' => "Supplier*",
  454. 's.fk_prospectlevel' => 'ProspectLevel',
  455. 's.mode_reglement' => 'PaymentTypeCustomer',
  456. 's.cond_reglement' => "PaymentTermsCustomer",
  457. 's.mode_reglement_supplier' => 'PaymentTypeSupplier',
  458. 's.cond_reglement_supplier' => "PaymentTermsSupplier",
  459. 's.outstanding_limit'=>'OutstandingBill',
  460. 's.fk_account'=>'PaymentBankAccount',
  461. 's.fk_incoterms'=>'IncotermLabel',
  462. 's.tva_assuj' => 'VATIsUsed',
  463. 's.barcode' => 'BarCode',
  464. 's.default_lang' => 'DefaultLanguage',
  465. 's.canvas' => "Canvas",
  466. 's.datec' => "DateCreation",
  467. 's.fk_multicurrency' => 'MulticurrencyUsed',
  468. 's.multicurrency_code' => 'MulticurrencyCurrency'
  469. );
  470. if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
  471. $this->import_fields_array[$r]['s.price_level'] = 'PriceLevel';
  472. }
  473. if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) {
  474. $this->import_fields_array[$r] += array('s.accountancy_code_sell'=>'ProductAccountancySellCode', 's.accountancy_code_buy'=>'ProductAccountancyBuyCode');
  475. }
  476. // Add social networks fields
  477. if (isModEnabled('socialnetworks')) {
  478. $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
  479. $resql = $this->db->query($sql);
  480. while ($obj = $this->db->fetch_object($resql)) {
  481. $fieldname = 's.socialnetworks_'.$obj->code;
  482. $fieldlabel = ucfirst($obj->label);
  483. $this->import_fields_array[$r][$fieldname] = $fieldlabel;
  484. }
  485. }
  486. // Add extra fields
  487. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'societe' AND entity IN (0, ".$conf->entity.")";
  488. $resql = $this->db->query($sql);
  489. if ($resql) { // This can fail when class is used on old database (during migration for example)
  490. while ($obj = $this->db->fetch_object($resql)) {
  491. $fieldname = 'extra.'.$obj->name;
  492. $fieldlabel = ucfirst($obj->label);
  493. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  494. }
  495. }
  496. // End add extra fields
  497. $this->import_fieldshidden_array[$r] = array(
  498. 's.fk_user_creat' => 'user->id',
  499. 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'societe'
  500. ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
  501. $this->import_convertvalue_array[$r] = array(//field order as per structure of table llx_societe
  502. 's.code_client' => array('rule' => 'getcustomercodeifauto'),
  503. 's.code_fournisseur' => array('rule' => 'getsuppliercodeifauto'),
  504. 's.code_compta' => array('rule' => 'getcustomeraccountancycodeifauto'),
  505. 's.code_compta_fournisseur' => array('rule' => 'getsupplieraccountancycodeifauto'),
  506. 's.fk_departement' => array(
  507. 'rule' => 'fetchidfromcodeid',
  508. 'classfile' => '/core/class/cstate.class.php',
  509. 'class' => 'Cstate',
  510. 'method' => 'fetch',
  511. 'dict' => 'DictionaryStateCode'
  512. ),
  513. 's.fk_pays' => array(
  514. 'rule' => 'fetchidfromcodeid',
  515. 'classfile' => '/core/class/ccountry.class.php',
  516. 'class' => 'Ccountry',
  517. 'method' => 'fetch',
  518. 'dict' => 'DictionaryCountry'
  519. ),
  520. 's.fk_typent' => array(
  521. 'rule' => 'fetchidfromcodeorlabel',
  522. 'classfile' => '/core/class/ctypent.class.php',
  523. 'class' => 'Ctypent',
  524. 'method' => 'fetch',
  525. 'dict' => 'DictionaryCompanyType'
  526. ),
  527. 's.capital' => array('rule' => 'numeric'),
  528. 's.parent' => array(
  529. 'rule' => 'fetchidfromref',
  530. 'file' => '/societe/class/societe.class.php',
  531. 'class' => 'Societe',
  532. 'method' => 'fetch',
  533. 'element' => 'ThirdParty'
  534. ),
  535. 's.outstanding_limit' => array('rule' => 'numeric'),
  536. 's.fk_account' => array(
  537. 'rule' => 'fetchidfromcodeid',
  538. 'classfile' => '/compta/bank/class/account.class.php',
  539. 'class' => 'Account',
  540. 'method' => 'fetch',
  541. 'element' => 'BankAccount'
  542. ),
  543. 's.fk_stcomm' => array(
  544. 'rule' => 'fetchidfromcodeid',
  545. 'classfile' => '/core/class/cgenericdic.class.php',
  546. 'class' => 'CGenericDic',
  547. 'method' => 'fetch',
  548. 'dict' => 'DictionaryProspectStatus',
  549. 'element' => 'c_stcomm',
  550. 'table_element' => 'c_stcomm'
  551. ),
  552. /*
  553. 's.fk_prospectlevel' => array(
  554. 'rule' => 'fetchidfromcodeid',
  555. 'classfile' => '/core/class/cgenericdic.class.php',
  556. 'class' => 'CGenericDic',
  557. 'method' => 'fetch',
  558. 'dict' => 'DictionaryProspectLevel',
  559. 'element' => 'c_prospectlevel',
  560. 'table_element' => 'c_prospectlevel'
  561. ),*/
  562. // TODO
  563. // 's.fk_incoterms' => array(
  564. // 'rule' => 'fetchidfromcodeid',
  565. // 'classfile' => '/core/class/cincoterm.class.php',
  566. // 'class' => 'Cincoterm',
  567. // 'method' => 'fetch',
  568. // 'dict' => 'IncotermLabel'
  569. // )
  570. );
  571. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  572. $this->import_regex_array[$r] = array(//field order as per structure of table llx_societe
  573. 's.status' => '^[0|1]',
  574. 's.fk_typent' => 'id@'.MAIN_DB_PREFIX.'c_typent',
  575. 's.client' => '^[0|1|2|3]',
  576. 's.fournisseur' => '^[0|1]',
  577. 's.mode_reglement' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
  578. 's.cond_reglement' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
  579. 's.mode_reglement_supplier' => 'id@'.MAIN_DB_PREFIX.'c_paiement',
  580. 's.cond_reglement_supplier' => 'rowid@'.MAIN_DB_PREFIX.'c_payment_term',
  581. 's.fk_incoterms' => 'rowid@'.MAIN_DB_PREFIX.'c_incoterms',
  582. 's.tva_assuj' => '^[0|1]',
  583. 's.fk_multicurrency' => '^[0|1]',
  584. '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])?$',
  585. 's.multicurrency_code' => 'code_iso@'.MAIN_DB_PREFIX.'c_currencies'
  586. );
  587. $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe
  588. 's.nom' => "TPBigCompany",
  589. 's.name_alias' => "Alias for TPBigCompany",
  590. 's.parent' => "TPMotherCompany",
  591. 's.status' => "0 (closed) / 1 (active)",
  592. 's.code_client' => 'eg. CU01-0001 / empty / "auto"',
  593. 's.code_fournisseur' => 'eg. SU01-0001 / empty / "auto"',
  594. 's.code_compta' => "Code or empty to be auto-created",
  595. 's.code_compta_fournisseur' => "Code or empty to be auto-created",
  596. 's.address' => "61 Jump Street",
  597. 's.zip' => "123456",
  598. 's.town' => "Bigtown",
  599. 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
  600. 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
  601. 's.phone' => "eg: +34123456789",
  602. 's.fax' => "eg. +34987654321",
  603. 's.url' => "e.g. https://www.mybigcompany.com",
  604. 's.email' => "e.g. test@mybigcompany.com",
  605. 's.fk_effectif' => "1/2/3/5: represents one of the five ranges of employees",
  606. 's.fk_typent' => 'matches field "id" (1-9 etc.) OR "code" (TE_SMALL etc.) in table "'.MAIN_DB_PREFIX.'c_typent"',
  607. 's.fk_forme_juridique' => '1/2/3 etc...matches field "code" in table "'.MAIN_DB_PREFIX.'c_forme_juridique"',
  608. 's.siret' => "",
  609. 's.siren' => "",
  610. 's.ape' => "",
  611. 's.idprof4' => "",
  612. 's.idprof5' => "",
  613. 's.idprof6' => "",
  614. 's.tva_intra' => 'VAT number e.g."FR0123456789"',
  615. 's.capital' => "10000",
  616. 's.fk_stcomm' => '-1/0/1/2 etc... matches field "id" in table "'.MAIN_DB_PREFIX.'c_stcomm"',
  617. 's.note_private' => "Example of a PRIVATE note.",
  618. 's.note_public' => "Example of a PUBLIC note.",
  619. 's.client' => '0 (no customer no prospect) / 1 (customer) / 2 (prospect)/ 3 (customer and prospect)',
  620. 's.fournisseur' => '0 (not supplier) / 1 (supplier)',
  621. 's.fk_prospectlevel' => 'eg. "PL_MEDIUM" matches field "code" in table "'.MAIN_DB_PREFIX.'c_prospectlevel"',
  622. 's.mode_reglement' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
  623. 's.cond_reglement' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
  624. 's.mode_reglement_supplier' => '1/2/3...matches field "id" in table "'.MAIN_DB_PREFIX.'c_paiement"',
  625. 's.cond_reglement_supplier' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_payment_term"',
  626. 's.outstanding_limit' => "5000",
  627. 's.fk_account' => "rowid or ref",
  628. 's.fk_incoterms' => '1/2/3...matches field "rowid" in table "'.MAIN_DB_PREFIX.'c_incoterms"',
  629. 's.tva_assuj' => '0 (VAT not used) / 1 (VAT used)',
  630. 's.barcode' => '123456789',
  631. 's.default_lang' => 'en_US / es_ES etc...matches a language directory in htdocs/langs/',
  632. 's.canvas' => "empty / a custom canvas form layout url e.g. mycanvas@mymodule",
  633. 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
  634. 's.fk_multicurrency' => '0 (use system default currency) / 1 (use local currency)',
  635. 's.multicurrency_code' => 'GBP/USD etc... matches field "code_iso" in table "'.MAIN_DB_PREFIX.'c_currencies"',
  636. 's.accountancy_code_sell' => '707',
  637. 's.accountancy_code_buy' => '607',
  638. );
  639. $this->import_updatekeys_array[$r] = array(
  640. 's.nom' => 'ThirdPartyName',
  641. 's.zip' => 'Zip',
  642. 's.email' => 'Email',
  643. 's.code_client' => 'CustomerCode',
  644. 's.code_fournisseur' => 'SupplierCode',
  645. 's.code_compta' => 'CustomerAccountancyCode',
  646. 's.code_compta_fournisseur' => 'SupplierAccountancyCode'
  647. );
  648. if (isModEnabled('socialnetworks')) {
  649. $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
  650. $resql = $this->db->query($sql);
  651. while ($obj = $this->db->fetch_object($resql)) {
  652. $fieldname = 's.socialnetworks_'.$obj->code;
  653. $fieldlabel = ucfirst($obj->label);
  654. $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
  655. }
  656. }
  657. // Add profids as criteria to search duplicates
  658. $langs->load("companies");
  659. $i=1;
  660. while ($i <= 6) {
  661. if ($i == 1) {
  662. $this->import_updatekeys_array[$r]['s.siren'] = 'ProfId1'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
  663. }
  664. if ($i == 2) {
  665. $this->import_updatekeys_array[$r]['s.siret'] = 'ProfId2'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
  666. }
  667. if ($i == 3) {
  668. $this->import_updatekeys_array[$r]['s.ape'] = 'ProfId3'.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
  669. }
  670. if ($i >= 4) {
  671. //var_dump($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)));
  672. if ($langs->trans('ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code)) != '-') {
  673. $this->import_updatekeys_array[$r]['s.idprof'.$i] = 'ProfId'.$i.(empty($mysoc->country_code) ? '' : $mysoc->country_code);
  674. }
  675. }
  676. $i++;
  677. }
  678. // Import list of contacts/addresses of thirparties and attributes
  679. $r++;
  680. $this->import_code[$r] = $this->rights_class.'_'.$r;
  681. $this->import_label[$r] = 'ImportDataset_company_2';
  682. $this->import_icon[$r] = 'contact';
  683. $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
  684. $this->import_tables_array[$r] = array(
  685. 's' => MAIN_DB_PREFIX.'socpeople',
  686. 'extra' => MAIN_DB_PREFIX.'socpeople_extrafields'
  687. ); // List of tables to insert into (insert done in same order)
  688. $this->import_fields_array[$r] = array(//field order as per structure of table llx_socpeople
  689. 's.rowid' => 'Id',
  690. 's.datec' => "DateCreation",
  691. 's.fk_soc' => 'ThirdPartyName',
  692. 's.civility' => 'UserTitle',
  693. 's.lastname' => "Lastname*",
  694. 's.firstname' => "Firstname",
  695. 's.address' => "Address",
  696. 's.zip' => "Zip",
  697. 's.town' => "Town",
  698. 's.fk_departement' => "StateCode",
  699. 's.fk_pays' => "CountryCode",
  700. 's.birthday' => "DateOfBirth",
  701. 's.poste' => "PostOrFunction",
  702. 's.phone' => "Phone",
  703. 's.phone_perso' => "PhonePerso",
  704. 's.phone_mobile' => "PhoneMobile",
  705. 's.fax' => "Fax",
  706. 's.email' => "Email",
  707. 's.note_private' => "NotePrivate",
  708. 's.note_public' => "NotePublic"
  709. );
  710. // Add social networks fields
  711. if (isModEnabled('socialnetworks')) {
  712. $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
  713. $resql = $this->db->query($sql);
  714. while ($obj = $this->db->fetch_object($resql)) {
  715. $fieldname = 's.socialnetworks_'.$obj->code;
  716. $fieldlabel = ucfirst($obj->label);
  717. $this->import_fields_array[$r][$fieldname] = $fieldlabel;
  718. }
  719. }
  720. // Add extra fields
  721. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'socpeople' AND entity IN (0, ".$conf->entity.")";
  722. $resql = $this->db->query($sql);
  723. if ($resql) { // This can fail when class is used on an old database (during a migration for example)
  724. while ($obj = $this->db->fetch_object($resql)) {
  725. $fieldname = 'extra.'.$obj->name;
  726. $fieldlabel = ucfirst($obj->label);
  727. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  728. }
  729. }
  730. // End add extra fields
  731. $this->import_fieldshidden_array[$r] = array(
  732. 's.fk_user_creat' => 'user->id',
  733. 'extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'socpeople'
  734. ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
  735. $this->import_convertvalue_array[$r] = array(
  736. 's.fk_soc' => array(
  737. 'rule' => 'fetchidfromref',
  738. 'file' => '/societe/class/societe.class.php',
  739. 'class' => 'Societe',
  740. 'method' => 'fetch',
  741. 'element' => 'ThirdParty'
  742. ),
  743. 's.fk_departement' => array(
  744. 'rule' => 'fetchidfromcodeid',
  745. 'classfile' => '/core/class/cstate.class.php',
  746. 'class' => 'Cstate',
  747. 'method' => 'fetch',
  748. 'dict' => 'DictionaryCanton'
  749. ),
  750. 's.fk_pays' => array(
  751. 'rule' => 'fetchidfromcodeid',
  752. 'classfile' => '/core/class/ccountry.class.php',
  753. 'class' => 'Ccountry',
  754. 'method' => 'fetch',
  755. 'dict' => 'DictionaryCountry'
  756. ),
  757. );
  758. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  759. $this->import_regex_array[$r] = array(
  760. 's.birthday' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$',
  761. '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])?$'
  762. );
  763. $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_socpeople
  764. 's.rowid' => '1',
  765. 's.datec' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
  766. 's.fk_soc' => 'Third Party name eg. TPBigCompany',
  767. 's.civility' => 'Title of civility eg: MR...matches field "code" in table "'.MAIN_DB_PREFIX.'c_civility"',
  768. 's.lastname' => "lastname or label",
  769. 's.firstname' => 'John',
  770. 's.address' => '61 Jump street',
  771. 's.zip' => '75000',
  772. 's.town' => 'Bigtown',
  773. 's.fk_departement' => 'matches field "code_departement" in table "'.MAIN_DB_PREFIX.'c_departements"',
  774. 's.fk_pays' => 'US/FR/DE etc. matches field "code" in table "'.MAIN_DB_PREFIX.'c_country"',
  775. 's.birthday' => 'formatted as '.dol_print_date(dol_now(), '%Y-%m-%d'),
  776. 's.poste' => "Director",
  777. 's.phone' => "5551122",
  778. 's.phone_perso' => "5551133",
  779. 's.phone_mobile' => "5551144",
  780. 's.fax' => "5551155",
  781. 's.email' => "johnsmith@email.com",
  782. 's.note_private' => "My private note",
  783. 's.note_public' => "My public note"
  784. );
  785. $this->import_updatekeys_array[$r] = array(
  786. 's.rowid' => 'Id',
  787. 's.lastname' => "Lastname",
  788. 's.email' => "E-mail",
  789. );
  790. if (isModEnabled('socialnetworks')) {
  791. $sql = "SELECT code, label FROM ".MAIN_DB_PREFIX."c_socialnetworks WHERE active = 1";
  792. $resql = $this->db->query($sql);
  793. while ($obj = $this->db->fetch_object($resql)) {
  794. $fieldname = 's.socialnetworks_'.$obj->code;
  795. $fieldlabel = ucfirst($obj->label);
  796. $this->import_updatekeys_array[$r][$fieldname] = $fieldlabel;
  797. }
  798. }
  799. // Import Bank Accounts
  800. $r++;
  801. $this->import_code[$r] = $this->rights_class.'_'.$r;
  802. $this->import_label[$r] = "ImportDataset_company_3"; // Translation key
  803. $this->import_icon[$r] = 'company';
  804. $this->import_entities_array[$r] = array(); // We define here only fields that use a different icon to the one defined in import_icon
  805. $this->import_tables_array[$r] = array('sr' => MAIN_DB_PREFIX.'societe_rib');
  806. $this->import_fields_array[$r] = array(//field order as per structure of table llx_societe_rib
  807. 'sr.label' => "Label*",
  808. 'sr.fk_soc' => "ThirdPartyName*",
  809. 'sr.datec' => "DateCreation*",
  810. 'sr.bank' => "Bank",
  811. 'sr.code_banque' => "BankCode",
  812. 'sr.code_guichet' => "DeskCode",
  813. 'sr.number' => "BankAccountNumber",
  814. 'sr.cle_rib' => "BankAccountNumberKey",
  815. 'sr.bic' => "BIC",
  816. 'sr.iban_prefix' => "IBAN",
  817. 'sr.domiciliation' => "BankAccountDomiciliation",
  818. 'sr.proprio' => "BankAccountOwner",
  819. 'sr.owner_address' => "BankAccountOwnerAddress",
  820. 'sr.default_rib' => 'Default',
  821. 'sr.rum' => 'RUM',
  822. 'sr.frstrecur' => "WithdrawMode",
  823. 'sr.type' => "Type ban is defaut",
  824. );
  825. $this->import_convertvalue_array[$r] = array(
  826. 'sr.fk_soc' => array(
  827. 'rule' => 'fetchidfromref',
  828. 'classfile' => '/societe/class/societe.class.php',
  829. 'class' => 'Societe',
  830. 'method' => 'fetch',
  831. 'element' => 'ThirdParty'
  832. )
  833. );
  834. $this->import_examplevalues_array[$r] = array(//field order as per structure of table llx_societe_rib
  835. 'sr.label' => 'eg. "account1"',
  836. 'sr.fk_soc' => 'eg. "TPBigCompany"',
  837. 'sr.datec' => 'date used for creating direct debit UMR formatted as '.dol_print_date(
  838. dol_now(),
  839. '%Y-%m-%d'
  840. ),
  841. 'sr.bank' => 'bank name eg: "ING-Direct"',
  842. 'sr.code_banque' => 'account sort code (GB)/Routing number (US) eg. "8456"',
  843. 'sr.code_guichet' => "bank code for office/branch",
  844. 'sr.number' => 'account number eg. "3333333333"',
  845. 'sr.cle_rib' => 'account checksum/control digits (if used) eg. "22"',
  846. 'sr.bic' => 'bank identifier eg. "USHINGMMXXX"',
  847. 'sr.iban_prefix' => 'complete account IBAN eg. "GB78CPBK08925068637123"',
  848. 'sr.domiciliation' => 'bank branch address eg. "PARIS"',
  849. 'sr.proprio' => 'name on the bank account',
  850. 'sr.owner_address' => 'address of account holder',
  851. 'sr.default_rib' => '1 (default account) / 0 (not default)',
  852. 'sr.rum' => 'RUM code',
  853. 'sr.frstrecur' => 'FRST',
  854. 'sr.type' => 'ban',
  855. );
  856. // Import Company Sales representatives
  857. $r++;
  858. $this->import_code[$r] = $this->rights_class.'_'.$r;
  859. $this->import_label[$r] = "ImportDataset_company_4"; // Translation key
  860. $this->import_icon[$r] = 'company';
  861. $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
  862. $this->import_tables_array[$r] = array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
  863. $this->import_fields_array[$r] = array('sr.fk_soc'=>"ThirdPartyName*", 'sr.fk_user'=>"User*");
  864. $this->import_convertvalue_array[$r] = array(
  865. 'sr.fk_soc'=>array('rule'=>'fetchidfromref', 'classfile'=>'/societe/class/societe.class.php', 'class'=>'Societe', 'method'=>'fetch', 'element'=>'ThirdParty'),
  866. 'sr.fk_user'=>array('rule'=>'fetchidfromref', 'classfile'=>'/user/class/user.class.php', 'class'=>'User', 'method'=>'fetch', 'element'=>'User')
  867. );
  868. $this->import_examplevalues_array[$r] = array('sr.fk_soc'=>"MyBigCompany", 'sr.fk_user'=>"login");
  869. }
  870. /**
  871. * Function called when module is enabled.
  872. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  873. * It also creates data directories
  874. *
  875. * @param string $options Options when enabling module ('', 'noboxes')
  876. * @return int 1 if OK, 0 if KO
  877. */
  878. public function init($options = '')
  879. {
  880. global $conf, $langs;
  881. // We disable this to prevent pb of modules not correctly disabled
  882. //$this->remove($options);
  883. //ODT template
  884. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
  885. $dirodt = DOL_DATA_ROOT.'/doctemplates/thirdparties';
  886. $dest = $dirodt.'/template_thirdparty.odt';
  887. if (file_exists($src) && !file_exists($dest)) {
  888. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  889. dol_mkdir($dirodt);
  890. $result = dol_copy($src, $dest, 0, 0);
  891. if ($result < 0) {
  892. $langs->load("errors");
  893. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  894. return 0;
  895. }
  896. }
  897. $sql = array();
  898. return $this->_init($sql, $options);
  899. }
  900. }