modSociete.class.php 42 KB

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