modSociete.class.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 sociétés 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->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. // Dependencies
  59. $this->depends = array();
  60. $this->requiredby = array("modExpedition","modFacture","modFournisseur","modFicheinter","modPropale","modContrat","modCommande");
  61. $this->langfiles = array("companies",'bills');
  62. // Constants
  63. $this->const = array();
  64. $r=0;
  65. $this->const[$r][0] = "SOCIETE_CODECLIENT_ADDON";
  66. $this->const[$r][1] = "chaine";
  67. $this->const[$r][2] = "mod_codeclient_monkey";
  68. $this->const[$r][3] = 'Module to control third parties codes';
  69. $this->const[$r][4] = 0;
  70. $r++;
  71. $this->const[$r][0] = "SOCIETE_CODECOMPTA_ADDON";
  72. $this->const[$r][1] = "chaine";
  73. $this->const[$r][2] = "mod_codecompta_panicum";
  74. $this->const[$r][3] = 'Module to control third parties codes';
  75. $this->const[$r][4] = 0;
  76. $r++;
  77. $this->const[$r][0] = "SOCIETE_FISCAL_MONTH_START";
  78. $this->const[$r][1] = "chaine";
  79. $this->const[$r][2] = "0";
  80. $this->const[$r][3] = "Enter the month number of the first month of the fiscal year, e. g. 9 for September";
  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. /*
  90. $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
  91. $this->const[$r][1] = "chaine";
  92. $this->const[$r][2] = "0";
  93. $this->const[$r][3] = "hide thirdparty customer inative in combobox";
  94. $this->const[$r][4] = 1;
  95. $r++;
  96. */
  97. $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
  98. $this->const[$r][1] = "yesno";
  99. $this->const[$r][2] = "0";
  100. $this->const[$r][3] = "Display customer ref into select list";
  101. $this->const[$r][4] = 0;
  102. $r++;
  103. // Boxes
  104. $this->boxes = array();
  105. $r=0;
  106. $this->boxes[$r][1] = "box_clients.php";
  107. $r++;
  108. $this->boxes[$r][1] = "box_prospect.php";
  109. $r++;
  110. $this->boxes[$r][1] = "box_contacts.php";
  111. $r++;
  112. $this->boxes[$r][1] = "box_activity.php";
  113. $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
  114. $r++;
  115. $this->boxes[$r][1] = "box_goodcustomers.php";
  116. $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
  117. $r++;
  118. // Permissions
  119. $this->rights = array();
  120. $this->rights_class = 'societe';
  121. $r=0;
  122. $r++;
  123. $this->rights[$r][0] = 121; // id de la permission
  124. $this->rights[$r][1] = 'Read third parties'; // libelle de la permission
  125. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  126. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  127. $this->rights[$r][4] = 'lire';
  128. /* $r++;
  129. $this->rights[$r][0] = 241;
  130. $this->rights[$r][1] = 'Read thirdparties customers';
  131. $this->rights[$r][2] = 'r';
  132. $this->rights[$r][3] = 0;
  133. $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  134. $this->rights[$r][5] = 'read';
  135. $r++;
  136. $this->rights[$r][0] = 242;
  137. $this->rights[$r][1] = 'Read thirdparties suppliers';
  138. $this->rights[$r][2] = 'r';
  139. $this->rights[$r][3] = 0;
  140. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  141. $this->rights[$r][5] = 'read';
  142. */
  143. $r++;
  144. $this->rights[$r][0] = 122; // id de la permission
  145. $this->rights[$r][1] = 'Create and update third parties'; // libelle de la permission
  146. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  147. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  148. $this->rights[$r][4] = 'creer';
  149. /* $r++;
  150. $this->rights[$r][0] = 251;
  151. $this->rights[$r][1] = 'Create thirdparties customers';
  152. $this->rights[$r][2] = 'r';
  153. $this->rights[$r][3] = 0;
  154. $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  155. $this->rights[$r][5] = 'read';
  156. $r++;
  157. $this->rights[$r][0] = 252;
  158. $this->rights[$r][1] = 'Create thirdparties suppliers';
  159. $this->rights[$r][2] = 'r';
  160. $this->rights[$r][3] = 0;
  161. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  162. $this->rights[$r][5] = 'read';
  163. */
  164. $r++;
  165. $this->rights[$r][0] = 125; // id de la permission
  166. $this->rights[$r][1] = 'Delete third parties'; // libelle de la permission
  167. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  168. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  169. $this->rights[$r][4] = 'supprimer';
  170. $r++;
  171. $this->rights[$r][0] = 126; // id de la permission
  172. $this->rights[$r][1] = 'Export third parties'; // libelle de la permission
  173. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  174. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  175. $this->rights[$r][4] = 'export';
  176. // 262 : Resteindre l'acces des commerciaux
  177. $r++;
  178. $this->rights[$r][0] = 262;
  179. $this->rights[$r][1] = 'Read all third parties by internal users (otherwise only if commercial contact). Not effective for external users (limited to themselves).';
  180. $this->rights[$r][2] = 'r';
  181. $this->rights[$r][3] = 0;
  182. $this->rights[$r][4] = 'client';
  183. $this->rights[$r][5] = 'voir';
  184. $r++;
  185. $this->rights[$r][0] = 281; // id de la permission
  186. $this->rights[$r][1] = 'Read contacts'; // libelle de la permission
  187. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  188. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  189. $this->rights[$r][4] = 'contact';
  190. $this->rights[$r][5] = 'lire';
  191. $r++;
  192. $this->rights[$r][0] = 282; // id de la permission
  193. $this->rights[$r][1] = 'Create and update contact'; // libelle de la permission
  194. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  195. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  196. $this->rights[$r][4] = 'contact';
  197. $this->rights[$r][5] = 'creer';
  198. $r++;
  199. $this->rights[$r][0] = 283; // id de la permission
  200. $this->rights[$r][1] = 'Delete contacts'; // libelle de la permission
  201. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  202. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  203. $this->rights[$r][4] = 'contact';
  204. $this->rights[$r][5] = 'supprimer';
  205. $r++;
  206. $this->rights[$r][0] = 286; // id de la permission
  207. $this->rights[$r][1] = 'Export contacts'; // libelle de la permission
  208. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  209. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  210. $this->rights[$r][4] = 'contact';
  211. $this->rights[$r][5] = 'export';
  212. // Menus
  213. //-------
  214. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  215. // Exports
  216. //--------
  217. $r=0;
  218. // Export list of third parties and attributes
  219. $r++;
  220. $this->export_code[$r]=$this->rights_class.'_'.$r;
  221. $this->export_label[$r]='ExportDataset_company_1';
  222. $this->export_icon[$r]='company';
  223. $this->export_permission[$r]=array(array("societe","export"));
  224. $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','payterm.libelle'=>'PaymentConditions','paymode.libelle'=>'PaymentMode');
  225. if (! empty($conf->global->SOCIETE_USEPREFIX)) $this->export_fields_array[$r]['s.prefix']='Prefix';
  226. // Add multicompany field
  227. if (! empty($conf->global->MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED))
  228. {
  229. $nbofallowedentities=count(explode(',',getEntity('societe'))); // If project are shared, nb will be > 1
  230. if (! empty($conf->multicompany->enabled) && $nbofallowedentities > 1) $this->export_fields_array[$r]+=array('s.entity'=>'Entity');
  231. }
  232. $keyforselect='societe'; $keyforelement='company'; $keyforaliasextra='extra';
  233. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  234. $this->export_fields_array[$r]+=array('u.login'=>'SaleRepresentativeLogin','u.firstname'=>'SaleRepresentativeFirstname', 'u.lastname'=>'SaleRepresentativeLastname');
  235. //$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');
  236. $this->export_TypeFields_array[$r]=array('s.rowid'=>"Numeric", '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','payterm.libelle'=>'Text','paymode.libelle'=>'Text','s.entity'=>'Numeric');
  237. $this->export_entities_array[$r]=array('u.login'=>'user','u.firstname'=>'user','u.lastname'=>'user'); // We define here only fields that use another picto
  238. $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)');
  239. $this->export_sql_start[$r]='SELECT DISTINCT ';
  240. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
  241. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
  242. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  243. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
  244. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
  245. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
  246. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
  247. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
  248. $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';
  249. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as payterm ON s.cond_reglement = payterm.rowid';
  250. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as paymode ON s.mode_reglement = paymode.id';
  251. $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe').')';
  252. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  253. $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' ';
  254. if (! empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
  255. $subordinatesids = $user->getAllChildIds();
  256. $this->export_sql_end[$r] .=count($subronidatesids)>0 ? ' OR (sc.fk_user IN ('.implode(',',$subronidatesids).')' : '';
  257. }
  258. $this->export_sql_end[$r] .=')';
  259. }
  260. // Export list of contacts and attributes
  261. $r++;
  262. $this->export_code[$r]=$this->rights_class.'_'.$r;
  263. $this->export_label[$r]='ExportDataset_company_2';
  264. $this->export_icon[$r]='contact';
  265. $this->export_permission[$r]=array(array("societe","contact","export"));
  266. $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');
  267. $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)');
  268. $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");
  269. $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
  270. if (empty($conf->fournisseur->enabled))
  271. {
  272. unset($this->export_fields_array[$r]['s.code_fournisseur']);
  273. unset($this->export_entities_array[$r]['s.code_fournisseur']);
  274. }
  275. $keyforselect='socpeople'; $keyforelement='contact'; $keyforaliasextra='extra';
  276. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  277. $keyforselect='societe'; $keyforelement='company'; $keyforaliasextra='extrasoc';
  278. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  279. $this->export_sql_start[$r]='SELECT DISTINCT ';
  280. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c';
  281. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
  282. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extrasoc ON s.rowid = extrasoc.fk_object';
  283. if (is_object($user) && empty($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';
  284. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
  285. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
  286. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
  287. $this->export_sql_end[$r] .=' WHERE c.entity IN ('.getEntity('societe').')';
  288. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  289. $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' ';
  290. if (! empty($conf->global->SOCIETE_EXPORT_SUBORDINATES_CHILDS)) {
  291. $subordinatesids = $user->getAllChildIds();
  292. $this->export_sql_end[$r] .=count($subronidatesids)>0 ? ' OR (sc.fk_user IN ('.implode(',',$subronidatesids).')' : '';
  293. }
  294. $this->export_sql_end[$r] .=')';
  295. }
  296. // Imports
  297. //--------
  298. $r=0;
  299. // Import list of third parties and attributes
  300. $r++;
  301. $this->import_code[$r]=$this->rights_class.'_'.$r;
  302. $this->import_label[$r]='ImportDataset_company_1';
  303. $this->import_icon[$r]='company';
  304. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  305. $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)
  306. $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");
  307. // Add extra fields
  308. $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe' AND entity = ".$conf->entity;
  309. $resql=$this->db->query($sql);
  310. if ($resql) // This can fail when class is used on old database (during migration for example)
  311. {
  312. while ($obj=$this->db->fetch_object($resql))
  313. {
  314. $fieldname='extra.'.$obj->name;
  315. $fieldlabel=ucfirst($obj->label);
  316. $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
  317. }
  318. }
  319. // End add extra fields
  320. $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)
  321. $this->import_convertvalue_array[$r]=array(
  322. 's.fk_typent'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionaryCompanyType'),
  323. 's.fk_departement'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
  324. 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
  325. 's.fk_stcomm'=>array('rule'=>'zeroifnull'),
  326. 's.code_client'=>array('rule'=>'getcustomercodeifauto'),
  327. 's.code_fournisseur'=>array('rule'=>'getsuppliercodeifauto'),
  328. 's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifauto'),
  329. 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifauto'),
  330. 's.capital'=>array('rule'=>'numeric')
  331. );
  332. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  333. $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])?$');
  334. $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");
  335. $this->import_updatekeys_array[$r]=array('s.nom'=>'Name','s.code_client'=>'CustomerCode','s.code_fournisseur'=>'SupplierCode','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode');
  336. // Import list of contact and attributes
  337. $r++;
  338. $this->import_code[$r]=$this->rights_class.'_'.$r;
  339. $this->import_label[$r]='ImportDataset_company_2';
  340. $this->import_icon[$r]='contact';
  341. $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
  342. $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)
  343. $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");
  344. // Add extra fields
  345. $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'socpeople' AND entity = ".$conf->entity;
  346. $resql=$this->db->query($sql);
  347. if ($resql) // This can fail when class is used on old database (during migration for example)
  348. {
  349. while ($obj=$this->db->fetch_object($resql))
  350. {
  351. $fieldname='extra.'.$obj->name;
  352. $fieldlabel=ucfirst($obj->label);
  353. $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
  354. }
  355. }
  356. // End add extra fields
  357. $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)
  358. $this->import_convertvalue_array[$r]=array(
  359. 's.fk_soc'=>array('rule'=>'fetchidfromref','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
  360. 's.fk_departement'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cstate.class.php','class'=>'Cstate','method'=>'fetch','dict'=>'DictionaryState'),
  361. 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
  362. );
  363. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  364. $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])?$');
  365. $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");
  366. // Import Bank Accounts
  367. $r++;
  368. $this->import_code[$r]=$this->rights_class.'_'.$r;
  369. $this->import_label[$r]="ImportDataset_company_3"; // Translation key
  370. $this->import_icon[$r]='company';
  371. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  372. $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_rib');
  373. $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.bank'=>"Bank",
  374. 'sr.code_banque'=>"BankCode",'sr.code_guichet'=>"DeskCode",'sr.number'=>"BankAccountNumber*",
  375. 'sr.cle_rib'=>"BankAccountNumberKey",'sr.bic'=>"BIC",'sr.iban_prefix'=>"IBAN", 'sr.domiciliation'=>"BankAccountDomiciliation",'sr.proprio' => "BankAccountOwner", 'sr.owner_address' => "BankAccountOwnerAddress", 'sr.default_rib' => 'Default'
  376. );
  377. $this->import_convertvalue_array[$r]=array(
  378. 'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
  379. );
  380. $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.bank'=>"ING",
  381. 'sr.code_banque'=>"0000", 'sr.code_guichet'=>"1111",'sr.number'=>"3333333333",
  382. 'sr.cle_rib'=>"22",'sr.bic'=>"USHINGMMXXX",'sr.iban_prefix'=>"US00 0000 1111 22 3333 3333",'sr.domiciliation'=>"PARIS",'sr.proprio' => "Name of owner", 'sr.owner_address' => "15 paris street 75000 Paris", 'sr.default_rib' => '1 or 0'
  383. );
  384. // Import Company Salesman
  385. $r++;
  386. $this->import_code[$r]=$this->rights_class.'_'.$r;
  387. $this->import_label[$r]="ImportDataset_company_4"; // Translation key
  388. $this->import_icon[$r]='company';
  389. $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
  390. $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
  391. $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.fk_user'=>"User*");
  392. $this->import_convertvalue_array[$r]=array(
  393. 'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
  394. 'sr.fk_user'=>array('rule'=>'fetchidfromref','classfile'=>'/user/class/user.class.php','class'=>'User','method'=>'fetch','element'=>'User')
  395. );
  396. $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.fk_user'=>"login");
  397. }
  398. /**
  399. * Function called when module is enabled.
  400. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  401. * It also creates data directories
  402. *
  403. * @param string $options Options when enabling module ('', 'noboxes')
  404. * @return int 1 if OK, 0 if KO
  405. */
  406. function init($options='')
  407. {
  408. global $conf, $langs;
  409. // We disable this to prevent pb of modules not correctly disabled
  410. //$this->remove($options);
  411. //ODT template
  412. $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
  413. $dirodt=DOL_DATA_ROOT.'/doctemplates/thirdparties';
  414. $dest=$dirodt.'/template_thirdparty.odt';
  415. if (file_exists($src) && ! file_exists($dest))
  416. {
  417. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  418. dol_mkdir($dirodt);
  419. $result=dol_copy($src,$dest,0,0);
  420. if ($result < 0)
  421. {
  422. $langs->load("errors");
  423. $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
  424. return 0;
  425. }
  426. }
  427. $sql = array();
  428. return $this->_init($sql,$options);
  429. }
  430. }