dolibarr 25.0.0-alpha
modSalaries.class.php
Go to the documentation of this file.
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@inodbox.com>
7 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2014-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
9 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * or see https://www.gnu.org/
24 */
25
33include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
34
35
40{
46 public function __construct($db)
47 {
48 global $user;
49
50 $this->db = $db;
51 $this->numero = 510; // Perms from 501..519
52
53 // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
54 // It is used to group modules by family in module setup page
55 $this->family = "financial";
56 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57 $this->name = preg_replace('/^mod/i', '', get_class($this));
58 // Module description used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
59 $this->description = "Payment of salaries";
60
61 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
62 $this->version = 'dolibarr';
63
64 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
65 $this->picto = 'salary';
66
67 // Data directories to create when module is enabled
68 $this->dirs = array("/salaries/temp");
69
70 // Parts of module
71 $this->module_parts = array(
72 'models' => 1,
73 'triggers' => 0,
74 'substitutions' => 0,
75 );
76
77 // Config pages
78 $this->config_page_url = array('salaries.php@salaries');
79
80 // Dependencies
81 $this->hidden = false; // A condition to hide module
82 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
83 $this->requiredby = array(); // List of module ids to disable if this one is disabled
84 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
85 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
86 $this->langfiles = array("salaries", "bills");
87
88 // Constants
89 $this->const = [
90 [
91 "SALARIES_ACCOUNTING_ACCOUNT_PAYMENT",
92 "chaine",
93 "421",
94 "",
95 0,
96 ],
97 [
98 "SALARIES_ACCOUNTING_ACCOUNT_CHARGE",
99 "chaine",
100 "641",
101 "",
102 0,
103 ]
104 ];
105
106 // Boxes
107 $this->boxes = array();
108
109 // Permissions
110 $this->rights = array();
111 $this->rights_class = 'salaries';
112 $r = 0;
113
114 $r++;
115 $this->rights[$r][0] = 511;
116 $this->rights[$r][1] = 'Read employee salaries and payments (yours only)';
117 $this->rights[$r][2] = 'r';
118 $this->rights[$r][3] = 0;
119 $this->rights[$r][4] = 'read';
120 $this->rights[$r][5] = '';
121
122 $r++;
123 $this->rights[$r][0] = 512;
124 $this->rights[$r][1] = 'Read employee salaries and payments (yours and of your subordinates)';
125 $this->rights[$r][2] = 'r';
126 $this->rights[$r][3] = 0;
127 $this->rights[$r][4] = 'readchild';
128 $this->rights[$r][5] = '';
129
130 $r++;
131 $this->rights[$r][0] = 513;
132 $this->rights[$r][1] = 'Create/modify payments of empoyee salaries';
133 $this->rights[$r][2] = 'w';
134 $this->rights[$r][3] = 0;
135 $this->rights[$r][4] = 'write';
136 $this->rights[$r][5] = '';
137
138 $r++;
139 $this->rights[$r][0] = 514;
140 $this->rights[$r][1] = 'Delete payments of employee salary';
141 $this->rights[$r][2] = 'd';
142 $this->rights[$r][3] = 0;
143 $this->rights[$r][4] = 'delete';
144 $this->rights[$r][5] = '';
145
146 $r++;
147 $this->rights[$r][0] = 517;
148 $this->rights[$r][1] = 'Read salaries and payments (of all employees)';
149 $this->rights[$r][2] = 'r';
150 $this->rights[$r][3] = 0;
151 $this->rights[$r][4] = 'readall';
152
153 $r++;
154 $this->rights[$r][0] = 519;
155 $this->rights[$r][1] = 'Export payments of employee salaries';
156 $this->rights[$r][2] = 'r';
157 $this->rights[$r][3] = 0;
158 $this->rights[$r][4] = 'export';
159 $this->rights[$r][5] = '';
160
161
162
163 // Menus
164 //-------
165 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
166
167
168 // Exports
169 //--------
170 $r = 0;
171
172 $r++;
173 $this->export_code[$r] = $this->rights_class.'_'.$r;
174 $this->export_label[$r] = 'SalariesAndPayments';
175 $this->export_icon[$r] = 'salary';
176 $this->export_permission[$r] = array(array("salaries", "export"));
177 $this->export_fields_array[$r] = array('s.rowid' => 'SalaryID', 's.label'=>'Label', 's.datesp'=>'DateStartPeriod', 's.dateep'=>'DateEndPeriod', 's.amount' => 'SalaryAmount', 's.paye' => 'Status', 'u.firstname'=>"Firstname", 'u.lastname'=>"Lastname", 'u.login'=>"Login", 'u.salary'=>'CurrentSalary', 'p.datep'=>'DatePayment', 'p.amount'=>'AmountPayment', 'p.num_payment'=>'Numero', 'p.note'=>'Note');
178 $this->export_TypeFields_array[$r] = array('s.rowid' => 'Numeric', 's.label'=>'Text', 's.amount' => 'Numeric', 's.paye' => 'Numeric', 'u.firstname'=>"Text", 'u.lastname'=>"Text", 'u.login'=>'Text', 'u.salary'=>"Numeric", 'p.datep'=>'Date', 's.datesp'=>'Date', 's.dateep'=>'Date', 'p.amount'=>'Numeric', 'p.num_payment'=>'Numeric');
179 $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');
180
181 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
182 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'salary as s';
183 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON s.fk_user = u.rowid';
184 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'payment_salary as p ON p.fk_salary = s.rowid';
185 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_typepayment = cp.id';
186 $this->export_sql_end[$r] .= ' WHERE s.entity IN ('.getEntity('salary').')';
187 if (is_object($user) && !$user->hasRight('salaries', 'readall')) {
188 $childids = $user->getAllChildIds(1);
189 $this->export_sql_end[$r] .= ' AND s.fk_user IN ('.$this->db->sanitize(implode(',', $childids)).')';
190 }
191 if (is_object($user) && !$user->hasRight('salaries', 'readchild')) {
192 $this->export_sql_end[$r] .= ' AND s.fk_user = '.((int) $user->id);
193 }
194 }
195
204 public function init($options = '')
205 {
206 global $conf;
207
208 // Clean before activation
209 $this->remove($options);
210
211 // Ensure data directory exists
212 $dirSalary = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/salaries/temp';
213 if (!is_dir($dirSalary)) {
214 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
215 dol_mkdir($dirSalary);
216 }
217
218 // Register the PDF model
219 $sql = array();
220 $sql[] = "DELETE FROM ".MAIN_DB_PREFIX."document_model
221 WHERE nom = 'standard_salary'
222 AND type = 'salary'
223 AND entity = ".((int) $conf->entity);
224
225 $sql[] = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity)
226 VALUES ('standard_salary', 'salary', ".((int) $conf->entity).")";
227
228 return $this->_init($sql, $options);
229 }
230}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class to manage salaries module.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf browser version
Definition main.inc.php:229
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140