dolibarr 24.0.0-beta
modHoliday.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
6 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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
34include_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
35
36
41{
47 public function __construct($db)
48 {
49 global $conf; // Required by some include code
50
51 $this->db = $db;
52
53 // Id for module (must be unique).
54 // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
55 $this->numero = 20000;
56 // Key text used to identify module (for permissions, menus, etc...)
57 $this->rights_class = 'holiday';
58
59 // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
60 // It is used to group modules in module setup page
61 $this->family = "hr";
62 $this->module_position = '42';
63 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
64 $this->name = preg_replace('/^mod/i', '', get_class($this));
65 // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
66 $this->description = "Leave requests";
67 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
68 $this->version = 'dolibarr';
69 // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
70 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
71 // Name of image file used for this module.
72 // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
73 // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
74 $this->picto = 'holiday';
75
76 // Data directories to create when module is enabled.
77 // Example: this->dirs = array("/mymodule/temp");
78 $this->dirs = array("/holiday/temp");
79 $r = 0;
80
81 // Config pages
82 $this->config_page_url = array("holiday.php");
83
84 // Dependencies
85 $this->hidden = false; // A condition to hide module
86 $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
87 $this->requiredby = array(); // List of module ids to disable if this one is disabled
88 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
89 $this->langfiles = array("holiday");
90
91 // Constants
92 // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
93 $this->const = [
94 [
95 "HOLIDAY_ADDON",
96 "chaine",
97 "mod_holiday_madonna",
98 'Nom du gestionnaire de numerotation des congés',
99 0,
100 ],
101 [
102 "HOLIDAY_ADDON_PDF",
103 "chaine",
104 "celebrate",
105 'Name of PDF model of holiday',
106 0,
107 ],
108 [
109 "HOLIDAY_ADDON_PDF_ODT_PATH",
110 "chaine",
111 "DOL_DATA_ROOT".($conf->entity > 1 ? '/'.$conf->entity : '')."/doctemplates/holiday",
112 "",
113 0,
114 ],
115 ];
116
117 // Array to add new pages in new tabs
118 //$this->tabs[] = array('data'=>'user:+paidholidays:CPTitreMenu:holiday:$user->rights->holiday->read:/holiday/list.php?mainmenu=hrm&id=__ID__'); // We avoid to get one tab for each module. RH data are already in RH tab.
119 $this->tabs[] = array(); // To add a new tab identified by code tabname1
120
121 // Boxes
122 $this->boxes = array(); // List of boxes
123 $r = 0;
124
125 // Add here list of php file(s) stored in includes/boxes that contains class to show a box.
126 // Example:
127 //$this->boxes[$r][1] = "myboxa.php";
128 //$r++;
129 //$this->boxes[$r][1] = "myboxb.php";
130 //$r++;
131
132
133 // Cronjobs
134 $arraydate = dol_getdate(dol_now());
135 $datestart = dol_mktime(4, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
136 $this->cronjobs = array(
137 0 => array(
138 'label' => 'HolidayBalanceMonthlyUpdate:holiday',
139 'jobtype' => 'method',
140 'class' => 'holiday/class/holiday.class.php',
141 'objectname' => 'Holiday',
142 'method' => 'updateBalance',
143 'parameters' => '',
144 'comment' => 'Update holiday balance every month',
145 'frequency' => 1,
146 'unitfrequency' => 3600 * 24,
147 'priority' => 50,
148 'status' => 1,
149 'test' => '$conf->holiday->enabled',
150 'datestart' => $datestart
151 ),
152 1 => array(
153 'label' => 'SendPreviousMonthHRInformations:holiday',
154 'jobtype' => 'method',
155 'class' => 'holiday/class/holiday.class.php',
156 'objectname' => 'Holiday',
157 'method' => 'sendPreviousMonthHRInformations',
158 'parameters' => 'emailaddress, HolidayHrInformationsPreviousMonth',
159 'comment' => 'Send HR information to the defined email address in first parameter. Second parameter must be the email template code (can be id or label of emailtemplate to send)',
160 'frequency' => 1,
161 'unitfrequency' => 3600 * 24 * 31,
162 'priority' => 50,
163 'status' => 0,
164 'test' => 'isModEnabled("holiday")',
165 'datestart' => $datestart
166 )
167 );
168
169
170 // Permissions
171 $this->rights = array(); // Permission array used by this module
172 $r = 0;
173
174 $this->rights[$r][0] = 20001; // Permission id (must not be already used)
175 $this->rights[$r][1] = 'Read leave requests (yours and your subordinates)'; // Permission label
176 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
177 $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
178 $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
179 $r++;
180
181 $this->rights[$r][0] = 20002; // Permission id (must not be already used)
182 $this->rights[$r][1] = 'Create/modify leave requests'; // Permission label
183 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
184 $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
185 $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
186 $r++;
187
188 $this->rights[$r][0] = 20003; // Permission id (must not be already used)
189 $this->rights[$r][1] = 'Delete leave requests'; // Permission label
190 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
191 $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
192 $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
193 $r++;
194
195 $this->rights[$r][0] = 20007;
196 $this->rights[$r][1] = 'Approve leave requests';
197 $this->rights[$r][2] = 'w';
198 $this->rights[$r][3] = 0;
199 $this->rights[$r][4] = 'approve';
200 $r++;
201
202 $this->rights[$r][0] = 20004; // Permission id (must not be already used)
203 $this->rights[$r][1] = 'Read leave requests for everybody'; // Permission label
204 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
205 $this->rights[$r][4] = 'readall'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
206 $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
207 $r++;
208
209 $this->rights[$r][0] = 20005; // Permission id (must not be already used)
210 $this->rights[$r][1] = 'Create/modify leave requests for everybody'; // Permission label
211 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
212 $this->rights[$r][4] = 'writeall'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
213 $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
214 $r++;
215
216 $this->rights[$r][0] = 20006; // Permission id (must not be already used)
217 $this->rights[$r][1] = 'Setup leave requests of users (setup and update balance)'; // Permission label
218 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
219 $this->rights[$r][4] = 'define_holiday'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
220 $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
221 $r++;
222
223
224 // Menus
225 //-------
226 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
227
228
229 // Exports
230 $r = 0;
231
232 $r++;
233 $this->export_code[$r] = 'leaverequest_'.$r;
234 $this->export_label[$r] = 'ListeCP';
235 $this->export_icon[$r] = 'holiday';
236 $this->export_permission[$r] = array(array("holiday", "readall"));
237 $this->export_fields_array[$r] = array(
238 'd.rowid' => "LeaveId", 'd.fk_type' => 'TypeOfLeaveId', 't.code' => 'TypeOfLeaveCode', 't.label' => 'TypeOfLeaveLabel', 'd.fk_user' => 'UserID',
239 'd.date_debut' => 'DateStart', 'd.date_fin' => 'DateEnd', 'd.halfday' => 'HalfDay', 'none.num_open_days' => 'NbUseDaysCP',
240 'd.date_valid' => 'DateApprove', 'd.fk_validator' => "UserForApprovalID",
241 'u.lastname' => 'Lastname', 'u.firstname' => 'Firstname', 'u.login' => "Login", 'u.fk_country' => "CountyID",
242 'ua.lastname' => "UserForApprovalLastname", 'ua.firstname' => "UserForApprovalFirstname",
243 'ua.login' => "UserForApprovalLogin", 'd.description' => 'Description', 'd.statut' => 'Status'
244 );
245 $this->export_TypeFields_array[$r] = array(
246 'd.rowid' => "Numeric", 't.code' => 'Text', 't.label' => 'Text', 'd.fk_user' => 'Numeric',
247 'd.date_debut' => 'Date', 'd.date_fin' => 'Date', 'none.num_open_days' => 'NumericCompute',
248 'd.date_valid' => 'Date', 'd.fk_validator' => "Numeric",
249 'u.lastname' => 'Text', 'u.firstname' => 'Text', 'u.login' => "Text", 'u.fk_country' => 'Numeric',
250 'ua.lastname' => "Text", 'ua.firstname' => "Text",
251 'ua.login' => "Text", 'd.description' => 'Text', 'd.statut' => 'Numeric'
252 );
253 $this->export_entities_array[$r] = array(
254 'u.lastname' => 'user', 'u.firstname' => 'user', 'u.login' => 'user', 'ua.lastname' => 'user', 'ua.firstname' => 'user', 'ua.login' => 'user'
255 );
256 //$this->export_alias_array[$r] = array('d.rowid'=>"idholiday");
257 $this->export_special_array[$r] = array('none.num_open_days' => 'getNumOpenDays');
258 $this->export_dependencies_array[$r] = array('none.num_open_days' => 'u.fk_country'); // To force addition in GUI of u.fk_country when none.num_open_days is included in exported fields
259 //$this->export_dependencies_array[$r] = array();
260
261 $keyforselect = 'holiday';
262 $keyforelement = 'holiday';
263 $keyforaliasextra = 'extra';
264 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
265 $keyforselect = 'user';
266 $keyforelement = 'user';
267 $keyforaliasextra = 'extrau';
268 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
269
270 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
271 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'holiday as d';
272 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'holiday_extrafields as extra on d.rowid = extra.fk_object';
273 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_holiday_types as t ON t.rowid = d.fk_type AND t.entity IN (0, '.getEntity('c_holiday_types').')';
274 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua ON ua.rowid = d.fk_validator,';
275 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'user as u';
276 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user_extrafields as extrau ON u.rowid = extrau.fk_object';
277 $this->export_sql_end[$r] .= ' WHERE d.fk_user = u.rowid';
278 $this->export_sql_end[$r] .= ' AND d.entity IN ('.getEntity('holiday').')';
279
280 // Example:
281 // $this->export_code[$r]=$this->rights_class.'_'.$r;
282 // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
283 // $this->export_permission[$r]=array(array("facture","facture","export"));
284 // $this->export_fields_array[$r]=array(
285 // 's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone',
286 // 's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
287 // 's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",
288 // 'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus',
289 // 'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",
290 // 'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",
291 // 'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'
292 //);
293 // $this->export_entities_array[$r]=array(
294 // 's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company',
295 // 's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company',
296 // 'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",
297 // 'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",
298 // 'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",
299 // 'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'
300 //);
301 // $this->export_sql_start[$r]='SELECT DISTINCT ';
302 // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
303 // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
304 // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
305 // $r++;
306
307 // Imports
308 //--------
309 $r = 0;
310
311 // Import list of leave request
312
313 $r++;
314 $this->import_code[$r] = $this->rights_class.'_'.$r;
315 $this->import_label[$r] = "ListeCP"; // Translation key
316 $this->import_icon[$r] = 'holiday';
317 $this->import_tables_array[$r] = array('d' => MAIN_DB_PREFIX.'holiday');
318 $this->import_fields_array[$r] = array(
319 'd.ref' => 'Ref*', 'd.fk_user' => 'UserID*', 'd.fk_type' => 'TypeOfLeaveId*','d.fk_validator' => 'ApprovedBy*',
320 'd.date_debut' => 'DateStart*', 'd.date_fin' => 'DateEnd*', 'd.halfday' => 'HalfDay', 'd.description' => 'Description*',
321 'd.date_create' => 'DateCreation*'
322 );
323
324 // Import of leave balance
325 $r++;
326 $this->import_code[$r] = $this->rights_class.'_'.$r;
327 $this->import_label[$r] = "ListeLB"; // Translation key
328 $this->import_icon[$r] = 'holiday';
329 $this->import_tables_array[$r] = array('d' => MAIN_DB_PREFIX.'holiday_users');
330 $this->import_fields_array[$r] = array(
331 'd.fk_user' => "Employee*", 'd.nb_holiday' => "LeaveBalance*", 'd.fk_type' => "LeaveType*"
332 );
333
334 $keyforselect = 'holiday';
335 $keyforelement = 'holiday';
336 $keyforaliasextra = 'extra';
337 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
338 }
339
348 public function init($options = '')
349 {
350 // Permissions
351 $this->remove($options);
352
353 //ODT template
354 /*$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/holiday/template_holiday.odt';
355 $dirodt=DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/holiday';
356 $dest=$dirodt.'/template_order.odt';
357
358 if (file_exists($src) && ! file_exists($dest))
359 {
360 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
361 dol_mkdir($dirodt);
362 $result=dol_copy($src, $dest, 0, 0);
363 if ($result < 0)
364 {
365 $langs->load("errors");
366 $this->error=$langs->trans('ErrorFailToCopyFile', $src, $dest);
367 return 0;
368 }
369 }
370 */
371
372 $sql = array(
373 // "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'holiday' AND entity = ".((int) $conf->entity),
374 // "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','holiday',".((int) $conf->entity).")"
375 );
376
377 return $this->_init($sql, $options);
378 }
379}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Description and activation class for module holiday.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
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_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133