modSociete.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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@capnetworks.com>
  7. * Copyright (C) 2012-2014 Juanjo Menent <jmenent@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \defgroup societe Module societe
  24. * \brief Module to manage third parties (customers, prospects)
  25. * \file htdocs/core/modules/modSociete.class.php
  26. * \ingroup societe
  27. * \brief Fichier de description et activation du module Societe
  28. */
  29. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  30. /**
  31. * Class to describe and enable module Societe
  32. */
  33. class modSociete extends DolibarrModules
  34. {
  35. /**
  36. * Constructor. Define names, constants, directories, boxes, permissions
  37. *
  38. * @param DoliDB $db Database handler
  39. */
  40. function __construct($db)
  41. {
  42. global $conf, $user;
  43. $this->db = $db;
  44. $this->numero = 1;
  45. $this->family = "crm";
  46. $this->module_position = 10;
  47. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  48. $this->name = preg_replace('/^mod/i','',get_class($this));
  49. $this->description = "Gestion des societes et contacts";
  50. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  51. $this->version = 'dolibarr';
  52. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  53. $this->special = 0;
  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->depends = array();
  61. $this->requiredby = array("modExpedition","modFacture","modFournisseur","modFicheinter","modPropale","modContrat","modCommande");
  62. $this->langfiles = array("companies");
  63. // Constants
  64. $this->const = array();
  65. $r=0;
  66. $this->const[$r][0] = "SOCIETE_CODECLIENT_ADDON";
  67. $this->const[$r][1] = "chaine";
  68. $this->const[$r][2] = "mod_codeclient_leopard";
  69. $this->const[$r][3] = 'Module to control third parties codes';
  70. $this->const[$r][4] = 0;
  71. $r++;
  72. $this->const[$r][0] = "SOCIETE_CODECOMPTA_ADDON";
  73. $this->const[$r][1] = "chaine";
  74. $this->const[$r][2] = "mod_codecompta_panicum";
  75. $this->const[$r][3] = 'Module to control third parties codes';
  76. $this->const[$r][4] = 0;
  77. $r++;
  78. $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
  79. $this->const[$r][1] = "chaine";
  80. $this->const[$r][2] = "0";
  81. $this->const[$r][3] = "Mettre le numero du mois du debut d\'annee fiscale, ex: 9 pour septembre";
  82. $this->const[$r][4] = 0;
  83. $r++;
  84. $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
  85. $this->const[$r][1] = "chaine";
  86. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
  87. $this->const[$r][3] = "";
  88. $this->const[$r][4] = 0;
  89. $r++;
  90. /*
  91. $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
  92. $this->const[$r][1] = "chaine";
  93. $this->const[$r][2] = "0";
  94. $this->const[$r][3] = "hide thirdparty customer inative in combobox";
  95. $this->const[$r][4] = 1;
  96. $r++;
  97. */
  98. $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
  99. $this->const[$r][1] = "yesno";
  100. $this->const[$r][2] = "0";
  101. $this->const[$r][3] = "Display customer ref into select list";
  102. $this->const[$r][4] = 0;
  103. $r++;
  104. // Boxes
  105. $this->boxes = array();
  106. $r=0;
  107. $this->boxes[$r][1] = "box_clients.php";
  108. $r++;
  109. $this->boxes[$r][1] = "box_prospect.php";
  110. $r++;
  111. $this->boxes[$r][1] = "box_contacts.php";
  112. $r++;
  113. $this->boxes[$r][1] = "box_activity.php";
  114. $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
  115. $r++;
  116. $this->boxes[$r][1] = "box_goodcustomers.php";
  117. $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
  118. $r++;
  119. // Permissions
  120. $this->rights = array();
  121. $this->rights_class = 'societe';
  122. $r=0;
  123. $r++;
  124. $this->rights[$r][0] = 121; // id de la permission
  125. $this->rights[$r][1] = 'Lire les societes'; // libelle de la permission
  126. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  127. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  128. $this->rights[$r][4] = 'lire';
  129. /* $r++;
  130. $this->rights[$r][0] = 241;
  131. $this->rights[$r][1] = 'Read thirdparties customers';
  132. $this->rights[$r][2] = 'r';
  133. $this->rights[$r][3] = 0;
  134. $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  135. $this->rights[$r][5] = 'read';
  136. $r++;
  137. $this->rights[$r][0] = 242;
  138. $this->rights[$r][1] = 'Read thirdparties suppliers';
  139. $this->rights[$r][2] = 'r';
  140. $this->rights[$r][3] = 0;
  141. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  142. $this->rights[$r][5] = 'read';
  143. */
  144. $r++;
  145. $this->rights[$r][0] = 122; // id de la permission
  146. $this->rights[$r][1] = 'Creer modifier les societes'; // libelle de la permission
  147. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  148. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  149. $this->rights[$r][4] = 'creer';
  150. /* $r++;
  151. $this->rights[$r][0] = 251;
  152. $this->rights[$r][1] = 'Create thirdparties customers';
  153. $this->rights[$r][2] = 'r';
  154. $this->rights[$r][3] = 0;
  155. $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  156. $this->rights[$r][5] = 'read';
  157. $r++;
  158. $this->rights[$r][0] = 252;
  159. $this->rights[$r][1] = 'Create thirdparties suppliers';
  160. $this->rights[$r][2] = 'r';
  161. $this->rights[$r][3] = 0;
  162. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  163. $this->rights[$r][5] = 'read';
  164. */
  165. $r++;
  166. $this->rights[$r][0] = 125; // id de la permission
  167. $this->rights[$r][1] = 'Supprimer les societes'; // libelle de la permission
  168. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  169. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  170. $this->rights[$r][4] = 'supprimer';
  171. $r++;
  172. $this->rights[$r][0] = 126; // id de la permission
  173. $this->rights[$r][1] = 'Exporter les societes'; // libelle de la permission
  174. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  175. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  176. $this->rights[$r][4] = 'export';
  177. // 262 : Resteindre l'acces des commerciaux
  178. $r++;
  179. $this->rights[$r][0] = 262;
  180. $this->rights[$r][1] = 'Consulter tous les tiers par utilisateurs internes (sinon uniquement si contact commercial). Non effectif pour utilisateurs externes (tjs limités à eux-meme).';
  181. $this->rights[$r][2] = 'r';
  182. $this->rights[$r][3] = 1;
  183. $this->rights[$r][4] = 'client';
  184. $this->rights[$r][5] = 'voir';
  185. $r++;
  186. $this->rights[$r][0] = 281; // id de la permission
  187. $this->rights[$r][1] = 'Lire les contacts'; // libelle de la permission
  188. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  189. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  190. $this->rights[$r][4] = 'contact';
  191. $this->rights[$r][5] = 'lire';
  192. $r++;
  193. $this->rights[$r][0] = 282; // id de la permission
  194. $this->rights[$r][1] = 'Creer modifier les contacts'; // libelle de la permission
  195. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  196. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  197. $this->rights[$r][4] = 'contact';
  198. $this->rights[$r][5] = 'creer';
  199. $r++;
  200. $this->rights[$r][0] = 283; // id de la permission
  201. $this->rights[$r][1] = 'Supprimer les contacts'; // libelle de la permission
  202. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  203. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  204. $this->rights[$r][4] = 'contact';
  205. $this->rights[$r][5] = 'supprimer';
  206. $r++;
  207. $this->rights[$r][0] = 286; // id de la permission
  208. $this->rights[$r][1] = 'Exporter les contacts'; // libelle de la permission
  209. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  210. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  211. $this->rights[$r][4] = 'contact';
  212. $this->rights[$r][5] = 'export';
  213. // Exports
  214. //--------
  215. $r=0;
  216. // Export list of third parties and attributes
  217. $r++;
  218. $this->export_code[$r]=$this->rights_class.'_'.$r;
  219. $this->export_label[$r]='ExportDataset_company_1';
  220. $this->export_icon[$r]='company';
  221. $this->export_permission[$r]=array(array("societe","export"));
  222. $this->export_fields_array[$r]=array('s.rowid'=>"Id",'s.nom'=>"Name",'s.status'=>"Status",'s.client'=>"Customer",'s.fournisseur'=>"Supplier",'s.datec'=>"DateCreation",'s.tms'=>"DateLastModification",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.code_compta'=>"AccountancyCode",'s.code_compta_fournisseur'=>"SupplierAccountancyCode",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'d.nom'=>'State','c.label'=>"Country",'c.code'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.default_lang'=>"DefaultLang",'s.siren'=>"ProfId1",'s.siret'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.idprof5'=>"ProfId5",'s.idprof6'=>"ProfId6",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note_private'=>"NotePrivate",'s.note_public'=>"NotePublic",'t.libelle'=>"ThirdPartyType",'ce.code'=>"Staff","cfj.libelle"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','st.code'=>'ProspectStatus');
  223. if (! empty($conf->global->SOCIETE_USEPREFIX)) $this->export_fields_array[$r]['s.prefix']='Prefix';
  224. $keyforselect='societe'; $keyforelement='company'; $keyforaliasextra='extra';
  225. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  226. $this->export_fields_array[$r]+=array('u.login'=>'SaleRepresentativeLogin','u.firstname'=>'SaleRepresentativeFirstname', 'u.lastname'=>'SaleRepresentativeLastname');
  227. //$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>"Text",'s.status'=>"Text",'s.client'=>"Boolean",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",'s.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.default_lang'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note'=>"Text",'t.libelle'=>"Text",'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code','s.fk_stcomm'=>'List:c_stcomm:libelle:code','d.nom'=>'List:c_departements:nom:rowid');
  228. $this->export_TypeFields_array[$r]=array('s.nom'=>"Text",'s.status'=>"Numeric",'s.client'=>"Numeric",'s.fournisseur'=>"Boolean",'s.datec'=>"Date",'s.tms'=>"Date",'s.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.code_compta'=>"Text",'s.code_compta_fournisseur'=>"Text",'s.address'=>"Text",'s.zip'=>"Text",'s.town'=>"Text",'c.label'=>"List:c_country:label:label",'c.code'=>"Text",'s.phone'=>"Text",'s.fax'=>"Text",'s.url'=>"Text",'s.email'=>"Text",'s.default_lang'=>"Text",'s.siret'=>"Text",'s.siren'=>"Text",'s.ape'=>"Text",'s.idprof4'=>"Text",'s.idprof5'=>"Text",'s.idprof6'=>"Text",'s.tva_intra'=>"Text",'s.capital'=>"Numeric",'s.note_private'=>"Text",'s.note_public'=>"Text",'t.libelle'=>"Text",'ce.code'=>"List:c_effectif:libelle:code","cfj.libelle"=>"Text",'s.fk_prospectlevel'=>'List:c_prospectlevel:label:code','st.code'=>'List:c_stcomm:libelle:code','d.nom'=>'Text','u.login'=>'Text','u.firstname'=>'Text','u.lastname'=>'Text');
  229. $this->export_entities_array[$r]=array('u.login'=>'user','u.firstname'=>'user','u.lastname'=>'user'); // We define here only fields that use another picto
  230. $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)');
  231. $this->export_sql_start[$r]='SELECT DISTINCT ';
  232. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
  233. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
  234. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  235. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
  236. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
  237. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
  238. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
  239. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
  240. $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';
  241. $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe', 1).')';
  242. if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
  243. // Export list of contacts and attributes
  244. $r++;
  245. $this->export_code[$r]=$this->rights_class.'_'.$r;
  246. $this->export_label[$r]='ExportDataset_company_2';
  247. $this->export_icon[$r]='contact';
  248. $this->export_permission[$r]=array(array("societe","contact","export"));
  249. $this->export_fields_array[$r]=array('c.rowid'=>"IdContact",'c.civility'=>"CivilityCode",'c.lastname'=>'Lastname','c.firstname'=>'Firstname','c.poste'=>'PostOrFunction','c.datec'=>"DateCreation",'c.tms'=>"DateLastModification",'c.priv'=>"ContactPrivate",'c.address'=>"Address",'c.zip'=>"Zip",'c.town'=>"Town",'d.nom'=>'State','co.label'=>"Country",'co.code'=>"CountryCode",'c.phone'=>"Phone",'c.fax'=>"Fax",'c.phone_mobile'=>"Mobile",'c.email'=>"EMail",'s.rowid'=>"IdCompany",'s.nom'=>"CompanyName",'s.status'=>"Status",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode", 's.client'=>'Customer','s.fournisseur'=>'Supplier');
  250. $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)');
  251. $this->export_TypeFields_array[$r]=array('c.civility'=>"List:c_civility:label:code",'c.lastname'=>'Text','c.firstname'=>'Text','c.poste'=>'Text','c.datec'=>"Date",'c.priv'=>"Boolean",'c.address'=>"Text",'c.zip'=>"Text",'c.town'=>"Text",'d.nom'=>'Text','co.label'=>"List:c_country:label:rowid",'co.code'=>"Text",'c.phone'=>"Text",'c.fax'=>"Text",'c.email'=>"Text",'s.rowid'=>"List:societe:nom",'s.nom'=>"Text",'s.status'=>"Status",'s.code_client'=>"Text",'s.code_fournisseur'=>"Text",'s.client'=>"Text",'s.fournisseur'=>"Text");
  252. $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>"company", 's.status'=>'company', 's.code_client'=>"company",'s.code_fournisseur'=>"company", 's.client'=>"company", 's.fournisseur'=>"company"); // We define here only fields that use another picto
  253. if (empty($conf->fournisseur->enabled))
  254. {
  255. unset($this->export_fields_array[$r]['s.code_fournisseur']);
  256. unset($this->export_entities_array[$r]['s.code_fournisseur']);
  257. }
  258. $keyforselect='socpeople'; $keyforelement='contact'; $keyforaliasextra='extra';
  259. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  260. $this->export_sql_start[$r]='SELECT DISTINCT ';
  261. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c';
  262. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
  263. if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  264. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
  265. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
  266. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
  267. $this->export_sql_end[$r] .=' WHERE c.entity IN ('.getEntity("societe", 1).')';
  268. if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
  269. // Imports
  270. //--------
  271. $r=0;
  272. // Import list of third parties and attributes
  273. $r++;
  274. $this->import_code[$r]=$this->rights_class.'_'.$r;
  275. $this->import_label[$r]='ImportDataset_company_1';
  276. $this->import_icon[$r]='company';
  277. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  278. $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'societe','extra'=>MAIN_DB_PREFIX.'societe_extrafields'); // List of tables to insert into (insert done in same order)
  279. $this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.code_compta'=>"CustomerAccountancyCode",'s.code_compta_fournisseur'=>"SupplierAccountancyCode",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'s.fk_departement'=>"StateId",'s.fk_pays'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siren'=>"ProfId1",'s.siret'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.idprof5'=>"ProfId5",'s.idprof6'=>"ProfId6",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note_private'=>"NotePrivate",'s.note_public'=>"NotePublic",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Staff","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.barcode'=>'BarCode','s.datec'=>"DateCreation");
  280. // Add extra fields
  281. $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe' AND entity = ".$conf->entity;
  282. $resql=$this->db->query($sql);
  283. if ($resql) // This can fail when class is used on old database (during migration for example)
  284. {
  285. while ($obj=$this->db->fetch_object($resql))
  286. {
  287. $fieldname='extra.'.$obj->name;
  288. $fieldlabel=ucfirst($obj->label);
  289. $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
  290. }
  291. }
  292. // End add extra fields
  293. $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'societe'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
  294. $this->import_convertvalue_array[$r]=array(
  295. 's.fk_typent'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionaryCompanyType'),
  296. 's.fk_departement'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
  297. 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
  298. 's.fk_stcomm'=>array('rule'=>'zeroifnull'),
  299. 's.code_client'=>array('rule'=>'getcustomercodeifauto'),
  300. 's.code_fournisseur'=>array('rule'=>'getsuppliercodeifauto'),
  301. 's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifauto'),
  302. 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifauto')
  303. );
  304. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  305. $this->import_regex_array[$r]=array('s.status'=>'^[0|1]','s.client'=>'^[0|1|2|3]','s.fournisseur'=>'^[0|1]','s.fk_typent'=>'id@'.MAIN_DB_PREFIX.'c_typent','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])?$');
  306. $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(dol_now(),'%Y-%m-%d'),'s.code_client'=>'CU01-0001 or empty or "auto"','s.code_fournisseur'=>'SU01-0001 or empty or "auto"','s.address'=>"61 jump street",'s.zip'=>"123456",'s.town'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.phone'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.idprof5'=>"",'s.idprof6'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note_private'=>"This is an example of private note for record",'s.note_public'=>"This is an example of public note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'0','s.default_lang'=>'en_US','s.barcode'=>'123456789','s.datec'=>"2015-01-01 or 2015-01-01 12:30:00");
  307. // Import list of contact and attributes
  308. $r++;
  309. $this->import_code[$r]=$this->rights_class.'_'.$r;
  310. $this->import_label[$r]='ImportDataset_company_2';
  311. $this->import_icon[$r]='contact';
  312. $this->import_entities_array[$r]=array('s.fk_soc'=>'company'); // We define here only fields that use another icon that the one defined into import_icon
  313. $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'socpeople','extra'=>MAIN_DB_PREFIX.'socpeople_extrafields'); // List of tables to insert into (insert done in same order)
  314. $this->import_fields_array[$r]=array('s.fk_soc'=>'ThirdPartyName','s.civility'=>'UserTitle','s.lastname'=>"Lastname*",'s.firstname'=>"Firstname",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'s.fk_pays'=>"CountryCode",'s.birthday'=>"BirthdayDate",'s.poste'=>"Role",'s.phone'=>"Phone",'s.phone_perso'=>"PhonePerso",'s.phone_mobile'=>"PhoneMobile",'s.fax'=>"Fax",'s.email'=>"Email",'s.note_private'=>"Note",'s.note_public'=>"Note",'s.datec'=>"DateCreation");
  315. // Add extra fields
  316. $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'socpeople' AND entity = ".$conf->entity;
  317. $resql=$this->db->query($sql);
  318. if ($resql) // This can fail when class is used on old database (during migration for example)
  319. {
  320. while ($obj=$this->db->fetch_object($resql))
  321. {
  322. $fieldname='extra.'.$obj->name;
  323. $fieldlabel=ucfirst($obj->label);
  324. $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
  325. }
  326. }
  327. // End add extra fields
  328. $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'socpeople'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
  329. $this->import_convertvalue_array[$r]=array(
  330. 's.fk_soc'=>array('rule'=>'fetchidfromref','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
  331. 's.fk_departement'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
  332. 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
  333. );
  334. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  335. $this->import_regex_array[$r]=array('s.birthday'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','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])?$');
  336. $this->import_examplevalues_array[$r]=array('s.fk_soc'=>'MyBigCompany','s.civility'=>"MR",'s.lastname'=>"Smith",'s.firstname'=>'John','s.address'=>'61 jump street','s.zip'=>'75000','s.town'=>'Bigtown','s.fk_pays'=>'US, FR, DE...','s.datec'=>'1972-10-10','s.poste'=>"Director",'s.phone'=>"5551122",'s.phone_perso'=>"5551133",'s.phone_mobile'=>"5551144",'s.fax'=>"5551155",'s.email'=>"johnsmith@email.com",'s.note_private'=>"My private note",'s.note_public'=>"My public note");
  337. // Import Bank Accounts
  338. $r++;
  339. $this->import_code[$r]=$this->rights_class.'_'.$r;
  340. $this->import_label[$r]="ImportDataset_company_3"; // Translation key
  341. $this->import_icon[$r]='account';
  342. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  343. $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_rib');
  344. $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.bank'=>"Bank",
  345. 'sr.code_banque'=>"BankCode*",'sr.code_guichet'=>"DeskCode*",'sr.number'=>"BankAccountNumber*",
  346. 'sr.cle_rib'=>"BankAccountNumberKey*",'sr.bic'=>"BIC",'sr.iban_prefix'=>"IBAN"
  347. );
  348. $this->import_convertvalue_array[$r]=array(
  349. 'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
  350. );
  351. $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.bank'=>"ING",
  352. 'sr.code_banque'=>"0000", 'sr.code_guichet'=>"1111",'sr.number'=>"3333333333",
  353. 'sr.cle_rib'=>"22",'sr.bic'=>"USHINGMMXXX",'sr.iban_prefix'=>"US00 0000 1111 22 3333 3333"
  354. );
  355. // Import Company Salesman
  356. $r++;
  357. $this->import_code[$r]=$this->rights_class.'_'.$r;
  358. $this->import_label[$r]="ImportDataset_company_4"; // Translation key
  359. $this->import_icon[$r]='company';
  360. $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
  361. $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
  362. $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.fk_user'=>"User*");
  363. $this->import_convertvalue_array[$r]=array(
  364. 'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
  365. 'sr.fk_user'=>array('rule'=>'fetchidfromref','classfile'=>'/user/class/user.class.php','class'=>'User','method'=>'fetch','element'=>'User')
  366. );
  367. $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.fk_user'=>"login");
  368. }
  369. /**
  370. * Function called when module is enabled.
  371. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  372. * It also creates data directories
  373. *
  374. * @param string $options Options when enabling module ('', 'noboxes')
  375. * @return int 1 if OK, 0 if KO
  376. */
  377. function init($options='')
  378. {
  379. global $conf, $langs;
  380. // We disable this to prevent pb of modules not correctly disabled
  381. //$this->remove($options);
  382. //ODT template
  383. $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
  384. $dirodt=DOL_DATA_ROOT.'/doctemplates/thirdparties';
  385. $dest=$dirodt.'/template_thirdparty.odt';
  386. if (file_exists($src) && ! file_exists($dest))
  387. {
  388. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  389. dol_mkdir($dirodt);
  390. $result=dol_copy($src,$dest,0,0);
  391. if ($result < 0)
  392. {
  393. $langs->load("errors");
  394. $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
  395. return 0;
  396. }
  397. }
  398. $sql = array();
  399. return $this->_init($sql,$options);
  400. }
  401. }