modSociete.class.php 41 KB

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