PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/modSociete.class.php

https://github.com/asterix14/dolibarr
PHP | 331 lines | 203 code | 43 blank | 85 comment | 7 complexity | b81dbdf7d233be5e6e5a0ee9ed0f1906 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 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-2011 Regis Houssin <regis@dolibarr.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \defgroup societe Module societe
  23. * \brief Module to manage third parties (customers, prospects)
  24. * \file htdocs/core/modules/modSociete.class.php
  25. * \ingroup societe
  26. * \brief Fichier de description et activation du module Societe
  27. */
  28. include_once(DOL_DOCUMENT_ROOT ."/core/modules/DolibarrModules.class.php");
  29. /**
  30. * \class modSociete
  31. * \brief Classe de description et activation du 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 modSociete($DB)
  41. {
  42. global $conf;
  43. $this->db = $DB ;
  44. $this->numero = 1 ;
  45. $this->family = "crm";
  46. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  47. $this->name = preg_replace('/^mod/i','',get_class($this));
  48. $this->description = "Gestion des societes et contacts";
  49. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  50. $this->version = 'dolibarr';
  51. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  52. $this->special = 0;
  53. $this->config_page_url = array("societe.php@societe");
  54. // Name of image file used for this module.
  55. $this->picto='company';
  56. // Data directories to create when module is enabled
  57. $this->dirs = array("/societe/temp");
  58. // Dependances
  59. $this->depends = array();
  60. $this->requiredby = array("modExpedition","modFacture","modFournisseur","modFicheinter","modPropale","modContrat","modCommande");
  61. $this->langfiles = array("companies");
  62. // Constantes
  63. $this->const = array();
  64. $r=0;
  65. $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
  66. $this->const[$r][1] = "chaine";
  67. $this->const[$r][2] = "0";
  68. $this->const[$r][3] = "Mettre le numero du mois du debut d\'annee fiscale, ex: 9 pour septembre";
  69. $this->const[$r][4] = 0;
  70. $r++;
  71. $this->const[$r][0] = "MAIN_SEARCHFORM_SOCIETE";
  72. $this->const[$r][1] = "yesno";
  73. $this->const[$r][2] = "1";
  74. $this->const[$r][3] = "Show form for quick company search";
  75. $this->const[$r][4] = 0;
  76. $r++;
  77. $this->const[$r][0] = "MAIN_SEARCHFORM_CONTACT";
  78. $this->const[$r][1] = "yesno";
  79. $this->const[$r][2] = "1";
  80. $this->const[$r][3] = "Show form for quick contact search";
  81. $this->const[$r][4] = 0;
  82. $r++;
  83. $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
  84. $this->const[$r][1] = "chaine";
  85. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
  86. $this->const[$r][3] = "";
  87. $this->const[$r][4] = 0;
  88. $r++;
  89. // Boxes
  90. $this->boxes = array();
  91. $r=0;
  92. $this->boxes[$r][1] = "box_clients.php";
  93. $r++;
  94. $this->boxes[$r][1] = "box_prospect.php";
  95. $r++;
  96. $this->boxes[$r][1] = "box_contacts.php";
  97. $r++;
  98. // Permissions
  99. $this->rights = array();
  100. $this->rights_class = 'societe';
  101. $r=0;
  102. $r++;
  103. $this->rights[$r][0] = 121; // id de la permission
  104. $this->rights[$r][1] = 'Lire les societes'; // libelle de la permission
  105. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  106. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  107. $this->rights[$r][4] = 'lire';
  108. $r++;
  109. $this->rights[$r][0] = 122; // id de la permission
  110. $this->rights[$r][1] = 'Creer modifier les societes'; // libelle de la permission
  111. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  112. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  113. $this->rights[$r][4] = 'creer';
  114. $r++;
  115. $this->rights[$r][0] = 125; // id de la permission
  116. $this->rights[$r][1] = 'Supprimer les societes'; // libelle de la permission
  117. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  118. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  119. $this->rights[$r][4] = 'supprimer';
  120. $r++;
  121. $this->rights[$r][0] = 126; // id de la permission
  122. $this->rights[$r][1] = 'Exporter les societes'; // libelle de la permission
  123. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  124. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  125. $this->rights[$r][4] = 'export';
  126. // 262 : Resteindre l'acces des commerciaux
  127. $r++;
  128. $this->rights[$r][0] = 262;
  129. $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).';
  130. $this->rights[$r][2] = 'r';
  131. $this->rights[$r][3] = 1;
  132. $this->rights[$r][4] = 'client';
  133. $this->rights[$r][5] = 'voir';
  134. $r++;
  135. $this->rights[$r][0] = 281; // id de la permission
  136. $this->rights[$r][1] = 'Lire les contacts'; // libelle de la permission
  137. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  138. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  139. $this->rights[$r][4] = 'contact';
  140. $this->rights[$r][5] = 'lire';
  141. $r++;
  142. $this->rights[$r][0] = 282; // id de la permission
  143. $this->rights[$r][1] = 'Creer modifier les contacts'; // libelle de la permission
  144. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  145. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  146. $this->rights[$r][4] = 'contact';
  147. $this->rights[$r][5] = 'creer';
  148. $r++;
  149. $this->rights[$r][0] = 283; // id de la permission
  150. $this->rights[$r][1] = 'Supprimer les contacts'; // libelle de la permission
  151. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  152. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  153. $this->rights[$r][4] = 'contact';
  154. $this->rights[$r][5] = 'supprimer';
  155. $r++;
  156. $this->rights[$r][0] = 286; // id de la permission
  157. $this->rights[$r][1] = 'Exporter les contacts'; // libelle de la permission
  158. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  159. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  160. $this->rights[$r][4] = 'contact';
  161. $this->rights[$r][5] = 'export';
  162. // Exports
  163. //--------
  164. $r=0;
  165. // Export list of third parties and attributes
  166. $r++;
  167. $this->export_code[$r]=$this->rights_class.'_'.$r;
  168. $this->export_label[$r]='ExportDataset_company_1';
  169. $this->export_icon[$r]='company';
  170. $this->export_permission[$r]=array(array("societe","export"));
  171. $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.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.default_lang'=>"DefaultLang",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'t.libelle'=>"ThirdPartyType",'ce.code'=>"Effectif","cfj.libelle"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','d.nom'=>'State');
  172. $this->export_entities_array[$r]=array(); // We define here only fields that use another picto
  173. // Add extra fields
  174. $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'company'";
  175. $resql=$this->db->query($sql);
  176. if ($resql) // This can fail when class is used on old database (during migration for example)
  177. {
  178. while ($obj=$this->db->fetch_object($resql))
  179. {
  180. $fieldname='extra.'.$obj->name;
  181. $fieldlabel=ucfirst($obj->label);
  182. $this->export_fields_array[$r][$fieldname]=$fieldlabel;
  183. $this->export_entities_array[$r][$fieldname]='company';
  184. }
  185. }
  186. // End add axtra fields
  187. $this->export_sql_start[$r]='SELECT DISTINCT ';
  188. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
  189. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
  190. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  191. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON s.fk_pays = p.rowid';
  192. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
  193. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
  194. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
  195. $this->export_sql_end[$r] .=' WHERE s.entity = '.$conf->entity;
  196. // Export list of contacts and attributes
  197. $r++;
  198. $this->export_code[$r]=$this->rights_class.'_'.$r;
  199. $this->export_label[$r]='ExportDataset_company_2';
  200. $this->export_icon[$r]='contact';
  201. $this->export_permission[$r]=array(array("societe","contact","export"));
  202. $this->export_fields_array[$r]=array('c.rowid'=>"IdContact",'c.civilite'=>"CivilityCode",'c.name'=>'Lastname','c.firstname'=>'Firstname','c.datec'=>"DateCreation",'c.tms'=>"DateLastModification",'c.priv'=>"ContactPrivate",'c.address'=>"Address",'c.cp'=>"Zip",'c.ville'=>"Town",'c.phone'=>"Phone",'c.fax'=>"Fax",'c.email'=>"EMail",'p.libelle'=>"Country",'p.code'=>"CountryCode",'s.rowid'=>"IdCompany",'s.nom'=>"CompanyName",'s.status'=>"Status",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode");
  203. $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>"company",'s.code_client'=>"company",'s.code_fournisseur'=>"company"); // We define here only fields that use another picto
  204. if (empty($conf->fournisseur->enabled))
  205. {
  206. unset($this->export_fields_array[$r]['s.code_fournisseur']);
  207. unset($this->export_entities_array[$r]['s.code_fournisseur']);
  208. }
  209. // Add extra fields
  210. $sql="SELECT name, label FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'contact'";
  211. $resql=$this->db->query($sql);
  212. if ($resql) // This can fail when class is used on old database (during migration for example)
  213. {
  214. while ($obj=$this->db->fetch_object($resql))
  215. {
  216. $fieldname='extra.'.$obj->name;
  217. $fieldlabel=ucfirst($obj->label);
  218. $this->export_fields_array[$r][$fieldname]=$fieldlabel;
  219. $this->export_entities_array[$r][$fieldname]='contact';
  220. }
  221. }
  222. // End add axtra fields
  223. $this->export_sql_start[$r]='SELECT DISTINCT ';
  224. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c';
  225. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
  226. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON c.fk_pays = p.rowid';
  227. $this->export_sql_end[$r] .=' WHERE c.entity = '.$conf->entity;
  228. // Imports
  229. //--------
  230. $r=0;
  231. // Import list of third parties and attributes
  232. $r++;
  233. $this->import_code[$r]=$this->rights_class.'_'.$r;
  234. $this->import_label[$r]='ImportDataset_company_1';
  235. $this->import_icon[$r]='company';
  236. $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'societe'); // List of tables to insert into (insert done in same order)
  237. $this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.datec'=>"DateCreation",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.tel'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siret'=>"IdProf1",'s.siren'=>"IdProf2",'s.ape'=>"IdProf3",'s.idprof4'=>"IdProf4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note'=>"Note",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Effectif","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.gencod'=>'BarCode');
  238. $this->import_entities_array[$r]=array(); // We define here only fields that use another picto
  239. $this->import_regex_array[$r]=array('s.status'=>'^[0|1]','s.client'=>'^[0|1|2|3]','s.fournisseur'=>'^[0|1]');
  240. //$this->import_regex_array[$r]=array('s.status'=>'^[0|1]','s.client'=>'^[0|1|2|3]','s.fournisseur'=>'^[0|1]','s.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','s.fk_typent'=>array('rule'=>'fetchidfromcode','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch')));
  241. $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(mktime(),'YYYY-MM-DD'),'s.code_client'=>"CU01-0001",'s.code_fournisseur'=>"SU01-0001",'s.address'=>"61 jump street",'s.cp'=>"123456",'s.ville'=>"Big town",'s.tel'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note'=>"This is an example of note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'','s.default_lang'=>'en_US','s.gencod'=>'123456789');
  242. // Import list of contact and attributes
  243. /* $r++;
  244. $this->import_code[$r]=$this->rights_class.'_'.$r;
  245. $this->import_label[$r]='ImportDataset_company_2';
  246. $this->import_icon[$r]='contact';
  247. //$this->import_permission[$r]=array(array("societe","export"));
  248. $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'socpeople'); // List of tables to insert into (insert done in same order)
  249. $this->import_fields_array[$r]=array('s.fk_soc'=>'ThirdPartyName*','s.civilite'=>'Civility','s.name'=>"Name*",'s.firstname'=>"Firstname",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"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'=>"Note");
  250. $this->import_entities_array[$r]=array('s.fk_soc'=>'company'); // We define here only fields that use another picto
  251. $this->import_examplevalues_array[$r]=array('s.fk_soc'=>'The Big Company','s.civilite'=>"MR",'s.name'=>"Smith",'s.firstname'=>'John','s.address'=>'61 jump street','s.cp'=>'75000','s.ville'=>'Bigtown','s.fk_pays'=>'0','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'=>"My comments");
  252. // If value for some fields are a ref to found the key of parent
  253. $this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'fetchidfromref','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch'));
  254. // If value for some fields must be the previous inserted record (lastinsertid)
  255. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  256. */
  257. }
  258. /**
  259. * Function called when module is enabled.
  260. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  261. * It also creates data directories.
  262. * @return int 1 if OK, 0 if KO
  263. */
  264. function init($options='')
  265. {
  266. global $conf;
  267. // We disable this to prevent pb of modules not correctly disabled
  268. //$this->remove($options);
  269. require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
  270. $dirodt=DOL_DATA_ROOT.'/doctemplates/thirdparties';
  271. create_exdir($dirodt);
  272. dol_copy(DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt',$dirodt.'/template_thirdparty.odt',0,0);
  273. $sql = array();
  274. return $this->_init($sql,$options);
  275. }
  276. /**
  277. * Function called when module is disabled.
  278. * Remove from database constants, boxes and permissions from Dolibarr database.
  279. * Data directories are not deleted.
  280. * @return int 1 if OK, 0 if KO
  281. */
  282. function remove($options='')
  283. {
  284. $sql = array();
  285. return $this->_remove($sql,$options);
  286. }
  287. }
  288. ?>