modSociete.class.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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;
  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] = "MAIN_SEARCHFORM_SOCIETE";
  85. $this->const[$r][1] = "yesno";
  86. $this->const[$r][2] = "1";
  87. $this->const[$r][3] = "Show form for quick company search";
  88. $this->const[$r][4] = 0;
  89. $r++;
  90. $this->const[$r][0] = "MAIN_SEARCHFORM_CONTACT";
  91. $this->const[$r][1] = "yesno";
  92. $this->const[$r][2] = "1";
  93. $this->const[$r][3] = "Show form for quick contact search";
  94. $this->const[$r][4] = 0;
  95. $r++;
  96. $this->const[$r][0] = "COMPANY_ADDON_PDF_ODT_PATH";
  97. $this->const[$r][1] = "chaine";
  98. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/thirdparties";
  99. $this->const[$r][3] = "";
  100. $this->const[$r][4] = 0;
  101. $r++;
  102. /*
  103. $this->const[$r][0] = "COMPANY_HIDE_INACTIVE_IN_COMBOBOX";
  104. $this->const[$r][1] = "chaine";
  105. $this->const[$r][2] = "0";
  106. $this->const[$r][3] = "hide thirdparty customer inative in combobox";
  107. $this->const[$r][4] = 1;
  108. $r++;
  109. */
  110. $this->const[$r][0] = "SOCIETE_ADD_REF_IN_LIST";
  111. $this->const[$r][1] = "yesno";
  112. $this->const[$r][2] = "0";
  113. $this->const[$r][3] = "Display customer ref into select list";
  114. $this->const[$r][4] = 0;
  115. $r++;
  116. // Boxes
  117. $this->boxes = array();
  118. $r=0;
  119. $this->boxes[$r][1] = "box_clients.php";
  120. $r++;
  121. $this->boxes[$r][1] = "box_prospect.php";
  122. $r++;
  123. $this->boxes[$r][1] = "box_contacts.php";
  124. $r++;
  125. $this->boxes[$r][1] = "box_activity.php";
  126. $this->boxes[$r][2] = '(WarningUsingThisBoxSlowDown)';
  127. $r++;
  128. // Permissions
  129. $this->rights = array();
  130. $this->rights_class = 'societe';
  131. $r=0;
  132. $r++;
  133. $this->rights[$r][0] = 121; // id de la permission
  134. $this->rights[$r][1] = 'Lire les societes'; // libelle de la permission
  135. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  136. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  137. $this->rights[$r][4] = 'lire';
  138. /* $r++;
  139. $this->rights[$r][0] = 241;
  140. $this->rights[$r][1] = 'Read thirdparties customers';
  141. $this->rights[$r][2] = 'r';
  142. $this->rights[$r][3] = 0;
  143. $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  144. $this->rights[$r][5] = 'read';
  145. $r++;
  146. $this->rights[$r][0] = 242;
  147. $this->rights[$r][1] = 'Read thirdparties suppliers';
  148. $this->rights[$r][2] = 'r';
  149. $this->rights[$r][3] = 0;
  150. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  151. $this->rights[$r][5] = 'read';
  152. */
  153. $r++;
  154. $this->rights[$r][0] = 122; // id de la permission
  155. $this->rights[$r][1] = 'Creer modifier les societes'; // libelle de la permission
  156. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  157. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  158. $this->rights[$r][4] = 'creer';
  159. /* $r++;
  160. $this->rights[$r][0] = 251;
  161. $this->rights[$r][1] = 'Create thirdparties customers';
  162. $this->rights[$r][2] = 'r';
  163. $this->rights[$r][3] = 0;
  164. $this->rights[$r][4] = 'thirparty_customer_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  165. $this->rights[$r][5] = 'read';
  166. $r++;
  167. $this->rights[$r][0] = 252;
  168. $this->rights[$r][1] = 'Create thirdparties suppliers';
  169. $this->rights[$r][2] = 'r';
  170. $this->rights[$r][3] = 0;
  171. $this->rights[$r][4] = 'thirdparty_supplier_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  172. $this->rights[$r][5] = 'read';
  173. */
  174. $r++;
  175. $this->rights[$r][0] = 125; // id de la permission
  176. $this->rights[$r][1] = 'Supprimer les societes'; // libelle de la permission
  177. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  178. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  179. $this->rights[$r][4] = 'supprimer';
  180. $r++;
  181. $this->rights[$r][0] = 126; // id de la permission
  182. $this->rights[$r][1] = 'Exporter les societes'; // libelle de la permission
  183. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  184. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  185. $this->rights[$r][4] = 'export';
  186. // 262 : Resteindre l'acces des commerciaux
  187. $r++;
  188. $this->rights[$r][0] = 262;
  189. $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).';
  190. $this->rights[$r][2] = 'r';
  191. $this->rights[$r][3] = 1;
  192. $this->rights[$r][4] = 'client';
  193. $this->rights[$r][5] = 'voir';
  194. $r++;
  195. $this->rights[$r][0] = 281; // id de la permission
  196. $this->rights[$r][1] = 'Lire les contacts'; // libelle de la permission
  197. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  198. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  199. $this->rights[$r][4] = 'contact';
  200. $this->rights[$r][5] = 'lire';
  201. $r++;
  202. $this->rights[$r][0] = 282; // id de la permission
  203. $this->rights[$r][1] = 'Creer modifier les contacts'; // libelle de la permission
  204. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  205. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  206. $this->rights[$r][4] = 'contact';
  207. $this->rights[$r][5] = 'creer';
  208. $r++;
  209. $this->rights[$r][0] = 283; // id de la permission
  210. $this->rights[$r][1] = 'Supprimer les contacts'; // libelle de la permission
  211. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  212. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  213. $this->rights[$r][4] = 'contact';
  214. $this->rights[$r][5] = 'supprimer';
  215. $r++;
  216. $this->rights[$r][0] = 286; // id de la permission
  217. $this->rights[$r][1] = 'Exporter les contacts'; // libelle de la permission
  218. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  219. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  220. $this->rights[$r][4] = 'contact';
  221. $this->rights[$r][5] = 'export';
  222. // Exports
  223. //--------
  224. $r=0;
  225. // Export list of third parties and attributes
  226. $r++;
  227. $this->export_code[$r]=$this->rights_class.'_'.$r;
  228. $this->export_label[$r]='ExportDataset_company_1';
  229. $this->export_icon[$r]='company';
  230. $this->export_permission[$r]=array(array("societe","export"));
  231. $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",'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','d.nom'=>'State');
  232. if (! empty($conf->global->SOCIETE_USEPREFIX)) $this->export_fields_array[$r]['s.prefix']='Prefix';
  233. //$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');
  234. $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');
  235. $this->export_entities_array[$r]=array(); // We define here only fields that use another picto
  236. $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)');
  237. // Add extra fields
  238. $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe'";
  239. $resql=$this->db->query($sql);
  240. if ($resql) // This can fail when class is used on old database (during migration for example)
  241. {
  242. while ($obj=$this->db->fetch_object($resql))
  243. {
  244. $fieldname='extra.'.$obj->name;
  245. $fieldlabel=ucfirst($obj->label);
  246. $typeFilter="Text";
  247. switch($obj->type)
  248. {
  249. case 'int':
  250. case 'double':
  251. case 'price':
  252. $typeFilter="Numeric";
  253. break;
  254. case 'date':
  255. case 'datetime':
  256. $typeFilter="Date";
  257. break;
  258. case 'boolean':
  259. $typeFilter="Boolean";
  260. break;
  261. case 'sellist':
  262. $tmp='';
  263. $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
  264. if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
  265. if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
  266. break;
  267. }
  268. $this->export_fields_array[$r][$fieldname]=$fieldlabel;
  269. $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
  270. $this->export_entities_array[$r][$fieldname]='company';
  271. }
  272. }
  273. // End add axtra fields
  274. $this->export_sql_start[$r]='SELECT DISTINCT ';
  275. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
  276. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra ON s.rowid = extra.fk_object';
  277. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id';
  278. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
  279. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id';
  280. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code';
  281. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
  282. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
  283. $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe', 1).')';
  284. // Export list of contacts and attributes
  285. $r++;
  286. $this->export_code[$r]=$this->rights_class.'_'.$r;
  287. $this->export_label[$r]='ExportDataset_company_2';
  288. $this->export_icon[$r]='contact';
  289. $this->export_permission[$r]=array(array("societe","contact","export"));
  290. $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');
  291. $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)');
  292. $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");
  293. $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
  294. if (empty($conf->fournisseur->enabled))
  295. {
  296. unset($this->export_fields_array[$r]['s.code_fournisseur']);
  297. unset($this->export_entities_array[$r]['s.code_fournisseur']);
  298. }
  299. // Add extra fields
  300. $sql="SELECT name, label, type, param FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'socpeople'";
  301. $resql=$this->db->query($sql);
  302. if ($resql) // This can fail when class is used on old database (during migration for example)
  303. {
  304. while ($obj=$this->db->fetch_object($resql))
  305. {
  306. $fieldname='extra.'.$obj->name;
  307. $fieldlabel=ucfirst($obj->label);
  308. $typeFilter="Text";
  309. switch($obj->type)
  310. {
  311. case 'int':
  312. case 'double':
  313. case 'price':
  314. $typeFilter="Numeric";
  315. break;
  316. case 'date':
  317. case 'datetime':
  318. $typeFilter="Date";
  319. break;
  320. case 'boolean':
  321. $typeFilter="Boolean";
  322. break;
  323. case 'sellist':
  324. $tmp='';
  325. $tmpparam=unserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
  326. if ($tmpparam['options'] && is_array($tmpparam['options'])) $tmp=array_shift(array_keys($tmpparam['options']));
  327. if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
  328. case 'select':
  329. $typeFilter="Select:".$obj->param;
  330. break;
  331. }
  332. $this->export_fields_array[$r][$fieldname]=$fieldlabel;
  333. $this->export_TypeFields_array[$r][$fieldname]=$typeFilter;
  334. $this->export_entities_array[$r][$fieldname]='contact';
  335. }
  336. }
  337. // End add axtra fields
  338. $this->export_sql_start[$r]='SELECT DISTINCT ';
  339. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c';
  340. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid';
  341. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid';
  342. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid';
  343. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid';
  344. $this->export_sql_end[$r] .=' WHERE c.entity IN ('.getEntity("societe", 1).')';
  345. // Imports
  346. //--------
  347. $r=0;
  348. // Import list of third parties and attributes
  349. $r++;
  350. $this->import_code[$r]=$this->rights_class.'_'.$r;
  351. $this->import_label[$r]='ImportDataset_company_1';
  352. $this->import_icon[$r]='company';
  353. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  354. $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)
  355. $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");
  356. // Add extra fields
  357. $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe' AND entity = ".$conf->entity;
  358. $resql=$this->db->query($sql);
  359. if ($resql) // This can fail when class is used on old database (during migration for example)
  360. {
  361. while ($obj=$this->db->fetch_object($resql))
  362. {
  363. $fieldname='extra.'.$obj->name;
  364. $fieldlabel=ucfirst($obj->label);
  365. $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
  366. }
  367. }
  368. // End add extra fields
  369. $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)
  370. $this->import_convertvalue_array[$r]=array(
  371. 's.fk_typent'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionaryCompanyType'),
  372. 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
  373. 's.fk_stcomm'=>array('rule'=>'zeroifnull'),
  374. 's.code_client'=>array('rule'=>'getcustomercodeifauto'),
  375. 's.code_fournisseur'=>array('rule'=>'getsuppliercodeifauto'),
  376. 's.code_compta'=>array('rule'=>'getcustomeraccountancycodeifauto'),
  377. 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifauto')
  378. );
  379. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  380. $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])?$');
  381. $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");
  382. // Import list of contact and attributes
  383. $r++;
  384. $this->import_code[$r]=$this->rights_class.'_'.$r;
  385. $this->import_label[$r]='ImportDataset_company_2';
  386. $this->import_icon[$r]='contact';
  387. $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
  388. $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)
  389. $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");
  390. // Add extra fields
  391. $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'socpeople' AND entity = ".$conf->entity;
  392. $resql=$this->db->query($sql);
  393. if ($resql) // This can fail when class is used on old database (during migration for example)
  394. {
  395. while ($obj=$this->db->fetch_object($resql))
  396. {
  397. $fieldname='extra.'.$obj->name;
  398. $fieldlabel=ucfirst($obj->label);
  399. $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':'');
  400. }
  401. }
  402. // End add extra fields
  403. $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)
  404. $this->import_convertvalue_array[$r]=array(
  405. 's.fk_soc'=>array('rule'=>'fetchidfromref','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
  406. 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'),
  407. );
  408. //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
  409. $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])?$');
  410. $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");
  411. // Import Bank Accounts
  412. $r++;
  413. $this->import_code[$r]=$this->rights_class.'_'.$r;
  414. $this->import_label[$r]="ImportDataset_company_3"; // Translation key
  415. $this->import_icon[$r]='account';
  416. $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon
  417. $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_rib');
  418. $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.bank'=>"Bank",
  419. 'sr.code_banque'=>"BankCode*",'sr.code_guichet'=>"DeskCode*",'sr.number'=>"BankAccountNumber*",
  420. 'sr.cle_rib'=>"BankAccountNumberKey*",'sr.bic'=>"BIC",'sr.iban_prefix'=>"IBAN"
  421. );
  422. $this->import_convertvalue_array[$r]=array(
  423. 'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty')
  424. );
  425. $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.bank'=>"ING",
  426. 'sr.code_banque'=>"0000", 'sr.code_guichet'=>"1111",'sr.number'=>"3333333333",
  427. 'sr.cle_rib'=>"22",'sr.bic'=>"USHINGMMXXX",'sr.iban_prefix'=>"US00 0000 1111 22 3333 3333"
  428. );
  429. // Import Company Salesman
  430. $r++;
  431. $this->import_code[$r]=$this->rights_class.'_'.$r;
  432. $this->import_label[$r]="ImportDataset_company_4"; // Translation key
  433. $this->import_icon[$r]='company';
  434. $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
  435. $this->import_tables_array[$r]=array('sr'=>MAIN_DB_PREFIX.'societe_commerciaux');
  436. $this->import_fields_array[$r]=array('sr.fk_soc'=>"ThirdPartyName*",'sr.fk_user'=>"User*");
  437. $this->import_convertvalue_array[$r]=array(
  438. 'sr.fk_soc'=>array('rule'=>'fetchidfromref','classfile'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'),
  439. 'sr.fk_user'=>array('rule'=>'fetchidfromref','classfile'=>'/user/class/user.class.php','class'=>'User','method'=>'fetch','element'=>'User')
  440. );
  441. $this->import_examplevalues_array[$r]=array('sr.fk_soc'=>"MyBigCompany",'sr.fk_user'=>"login");
  442. }
  443. /**
  444. * Function called when module is enabled.
  445. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  446. * It also creates data directories
  447. *
  448. * @param string $options Options when enabling module ('', 'noboxes')
  449. * @return int 1 if OK, 0 if KO
  450. */
  451. function init($options='')
  452. {
  453. global $conf, $langs;
  454. // We disable this to prevent pb of modules not correctly disabled
  455. //$this->remove($options);
  456. //ODT template
  457. $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/thirdparties/template_thirdparty.odt';
  458. $dirodt=DOL_DATA_ROOT.'/doctemplates/thirdparties';
  459. $dest=$dirodt.'/template_thirdparty.odt';
  460. if (file_exists($src) && ! file_exists($dest))
  461. {
  462. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  463. dol_mkdir($dirodt);
  464. $result=dol_copy($src,$dest,0,0);
  465. if ($result < 0)
  466. {
  467. $langs->load("errors");
  468. $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
  469. return 0;
  470. }
  471. }
  472. $sql = array();
  473. return $this->_init($sql,$options);
  474. }
  475. }