modSalaries.class.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 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-2012 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2014 Alexandre Spangaro <aspangaro@zendsi.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. * or see http://www.gnu.org/
  23. */
  24. /**
  25. * \defgroup salaries Module salaries
  26. * \brief Module to include salaries management
  27. * \file htdocs/core/modules/modSalaries.class.php
  28. * \ingroup salaries
  29. * \brief File to activate module salaries
  30. */
  31. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  32. /**
  33. * Class to manage salaries module
  34. */
  35. class modSalaries extends DolibarrModules
  36. {
  37. /**
  38. * Constructor. Define names, constants, directories, boxes, permissions
  39. *
  40. * @param DoliDB $db Database handler
  41. */
  42. function __construct($db)
  43. {
  44. global $conf;
  45. $this->db = $db;
  46. $this->numero = 510; // Perms from 501..519
  47. $this->family = "compta";
  48. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  49. $this->name = preg_replace('/^mod/i','',get_class($this));
  50. // Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
  51. $this->description = "Payment of salaries";
  52. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  53. $this->version = 'dolibarr';
  54. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  55. $this->picto='bill';
  56. // Data directories to create when module is enabled
  57. $this->dirs = array("/salaries/temp");
  58. // Config pages
  59. //$this->config_page_url = array('salaries.php');
  60. $this->config_page_url = array();
  61. // Dependencies
  62. $this->hidden = false; // A condition to hide module
  63. $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
  64. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  65. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  66. $this->phpmin = array(5,4); // Minimum version of PHP required by module
  67. $this->langfiles = array("salaries","bills");
  68. // Constants
  69. $this->const = array();
  70. $this->const[0] = array(
  71. "SALARIES_ACCOUNTING_ACCOUNT_PAYMENT",
  72. "chaine",
  73. "421"
  74. );
  75. $this->const[1] = array(
  76. "SALARIES_ACCOUNTING_ACCOUNT_CHARGE",
  77. "chaine",
  78. "641"
  79. );
  80. // Boxes
  81. $this->boxes = array();
  82. // Permissions
  83. $this->rights = array();
  84. $this->rights_class = 'salaries';
  85. $r=0;
  86. $r++;
  87. $this->rights[$r][0] = 511;
  88. $this->rights[$r][1] = 'Read payments of employee salaries';
  89. $this->rights[$r][2] = 'r';
  90. $this->rights[$r][3] = 0;
  91. $this->rights[$r][4] = 'read';
  92. $this->rights[$r][5] = '';
  93. $r++;
  94. $this->rights[$r][0] = 512;
  95. $this->rights[$r][1] = 'Create/modify payments of empoyee salaries';
  96. $this->rights[$r][2] = 'w';
  97. $this->rights[$r][3] = 0;
  98. $this->rights[$r][4] = 'write';
  99. $this->rights[$r][5] = '';
  100. $r++;
  101. $this->rights[$r][0] = 514;
  102. $this->rights[$r][1] = 'Delete payments of employee salary';
  103. $this->rights[$r][2] = 'd';
  104. $this->rights[$r][3] = 0;
  105. $this->rights[$r][4] = 'delete';
  106. $this->rights[$r][5] = '';
  107. $r++;
  108. $this->rights[$r][0] = 517;
  109. $this->rights[$r][1] = 'Export payments of employee salaries';
  110. $this->rights[$r][2] = 'r';
  111. $this->rights[$r][3] = 0;
  112. $this->rights[$r][4] = 'export';
  113. $this->rights[$r][5] = '';
  114. // Menus
  115. //-------
  116. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  117. // Exports
  118. //--------
  119. $r=0;
  120. $r++;
  121. $this->export_code[$r]=$this->rights_class.'_'.$r;
  122. $this->export_label[$r]='Salaries and payments';
  123. $this->export_permission[$r]=array(array("salaries","export"));
  124. $this->export_fields_array[$r]=array('u.firstname'=>"Firstname",'u.lastname'=>"Lastname",'u.login'=>"Login",'u.salary'=>'CurrentSalary','p.datep'=>'DatePayment','p.datesp'=>'DateStartPeriod','p.dateep'=>'DateEndPeriod','p.amount'=>'AmountPayment','p.num_payment'=>'Numero','p.label'=>'Label','p.note'=>'Note');
  125. $this->export_TypeFields_array[$r]=array('u.firstname'=>"Text",'u.lastname'=>"Text",'u.login'=>'Text','u.salary'=>"Numeric",'p.datep'=>'Date','p.datesp'=>'Date','p.dateep'=>'Date','p.amount'=>'Numeric','p.num_payment'=>'Numeric','p.label'=>'Text');
  126. $this->export_entities_array[$r]=array('u.firstname'=>'user','u.lastname'=>'user','u.login'=>'user','u.salary'=>'user','p.datep'=>'payment','p.datesp'=>'payment','p.dateep'=>'payment','p.amount'=>'payment','p.label'=>'payment','p.note'=>'payment','p.num_payment'=>'payment');
  127. $this->export_sql_start[$r]='SELECT DISTINCT ';
  128. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u';
  129. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'payment_salary as p ON p.fk_user = u.rowid';
  130. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_typepayment = cp.id';
  131. $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('user').')';
  132. }
  133. /**
  134. * Function called when module is enabled.
  135. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  136. * It also creates data directories
  137. *
  138. * @param string $options Options when enabling module ('', 'noboxes')
  139. * @return int 1 if OK, 0 if KO
  140. */
  141. function init($options='')
  142. {
  143. global $conf;
  144. // Clean before activation
  145. $this->remove($options);
  146. $sql = array();
  147. return $this->_init($sql,$options);
  148. }
  149. }