dolibarr  19.0.0-dev
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  *
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 <https://www.gnu.org/licenses/>.
21  * or see https://www.gnu.org/
22  */
23 
32 include_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
33 
34 
39 {
45  public function __construct($db)
46  {
47  global $conf, $user; // Required by some include code
48 
49  $this->db = $db;
50 
51  // Id for module (must be unique).
52  // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
53  $this->numero = 20000;
54  // Key text used to identify module (for permissions, menus, etc...)
55  $this->rights_class = 'holiday';
56 
57  // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
58  // It is used to group modules in module setup page
59  $this->family = "hr";
60  $this->module_position = '42';
61  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
62  $this->name = preg_replace('/^mod/i', '', get_class($this));
63  // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
64  $this->description = "Leave requests";
65  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
66  $this->version = 'dolibarr';
67  // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
68  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
69  // Name of image file used for this module.
70  // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
71  // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
72  $this->picto = 'holiday';
73 
74  // Data directories to create when module is enabled.
75  // Example: this->dirs = array("/mymodule/temp");
76  $this->dirs = array("/holiday/temp");
77  $r = 0;
78 
79  // Config pages
80  $this->config_page_url = array("holiday.php");
81 
82  // Dependencies
83  $this->hidden = false; // A condition to hide module
84  $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
85  $this->requiredby = array(); // List of module ids to disable if this one is disabled
86  $this->conflictwith = array(); // List of module class names as string this module is in conflict with
87  $this->phpmin = array(7, 0); // Minimum version of PHP required by module
88  $this->need_dolibarr_version = array(3, 0); // Minimum version of Dolibarr required by module
89  $this->langfiles = array("holiday");
90 
91  // Constants
92  // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
93  // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
94  // 2=>array('MAIN_MODULE_MYMODULE_NEEDSMARTY','chaine',1,'Constant to say module need smarty',0)
95  $this->const = array(); // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
96  $r = 0;
97 
98  $this->const[$r][0] = "HOLIDAY_ADDON";
99  $this->const[$r][1] = "chaine";
100  $this->const[$r][2] = "mod_holiday_madonna";
101  $this->const[$r][3] = 'Nom du gestionnaire de numerotation des congés';
102  $this->const[$r][4] = 0;
103  $r++;
104 
105  $this->const[$r][0] = "HOLIDAY_ADDON_PDF";
106  $this->const[$r][1] = "chaine";
107  $this->const[$r][2] = "celebrate";
108  $this->const[$r][3] = 'Name of PDF model of holiday';
109  $this->const[$r][4] = 0;
110  $r++;
111 
112  $this->const[$r][0] = "HOLIDAY_ADDON_PDF_ODT_PATH";
113  $this->const[$r][1] = "chaine";
114  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/holiday";
115  $this->const[$r][3] = "";
116  $this->const[$r][4] = 0;
117  $r++;
118 
119  // Array to add new pages in new tabs
120  //$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.
121  $this->tabs[] = array(); // To add a new tab identified by code tabname1
122 
123  // Boxes
124  $this->boxes = array(); // List of boxes
125  $r = 0;
126 
127  // Add here list of php file(s) stored in includes/boxes that contains class to show a box.
128  // Example:
129  //$this->boxes[$r][1] = "myboxa.php";
130  //$r++;
131  //$this->boxes[$r][1] = "myboxb.php";
132  //$r++;
133 
134 
135  // Cronjobs
136  $arraydate = dol_getdate(dol_now());
137  $datestart = dol_mktime(4, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
138  $this->cronjobs = array(
139  0 => array(
140  'label' => 'HolidayBalanceMonthlyUpdate:holiday',
141  'jobtype' => 'method',
142  'class' => 'holiday/class/holiday.class.php',
143  'objectname' => 'Holiday',
144  'method' => 'updateBalance',
145  'parameters' => '',
146  'comment' => 'Update holiday balance every month',
147  'frequency' => 1,
148  'unitfrequency' => 3600 * 24,
149  'priority' => 50,
150  'status' => 1,
151  'test' => '$conf->holiday->enabled',
152  'datestart' => $datestart
153  )
154  );
155 
156 
157  // Permissions
158  $this->rights = array(); // Permission array used by this module
159  $r = 0;
160 
161  $this->rights[$r][0] = 20001; // Permission id (must not be already used)
162  $this->rights[$r][1] = 'Read leave requests (yours and your subordinates)'; // Permission label
163  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
164  $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
165  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
166  $r++;
167 
168  $this->rights[$r][0] = 20002; // Permission id (must not be already used)
169  $this->rights[$r][1] = 'Create/modify leave requests'; // Permission label
170  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
171  $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
172  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
173  $r++;
174 
175  $this->rights[$r][0] = 20003; // Permission id (must not be already used)
176  $this->rights[$r][1] = 'Delete leave requests'; // Permission label
177  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
178  $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
179  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
180  $r++;
181 
182  $this->rights[$r][0] = 20007;
183  $this->rights[$r][1] = 'Approve leave requests';
184  $this->rights[$r][2] = 'w';
185  $this->rights[$r][3] = 0;
186  $this->rights[$r][4] = 'approve';
187  $r++;
188 
189  $this->rights[$r][0] = 20004; // Permission id (must not be already used)
190  $this->rights[$r][1] = 'Read leave requests for everybody'; // Permission label
191  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
192  $this->rights[$r][4] = 'readall'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
193  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
194  $r++;
195 
196  $this->rights[$r][0] = 20005; // Permission id (must not be already used)
197  $this->rights[$r][1] = 'Create/modify leave requests for everybody'; // Permission label
198  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
199  $this->rights[$r][4] = 'writeall'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
200  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
201  $r++;
202 
203  $this->rights[$r][0] = 20006; // Permission id (must not be already used)
204  $this->rights[$r][1] = 'Setup leave requests of users (setup and update balance)'; // Permission label
205  $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
206  $this->rights[$r][4] = 'define_holiday'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
207  $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
208  $r++;
209 
210 
211  // Menus
212  //-------
213  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
214 
215 
216  // Exports
217  $r = 0;
218 
219  $r++;
220  $this->export_code[$r] = 'leaverequest_'.$r;
221  $this->export_label[$r] = 'ListeCP';
222  $this->export_icon[$r] = 'holiday';
223  $this->export_permission[$r] = array(array("holiday", "readall"));
224  $this->export_fields_array[$r] = array(
225  'd.rowid'=>"LeaveId", 'd.fk_type'=>'TypeOfLeaveId', 't.code'=>'TypeOfLeaveCode', 't.label'=>'TypeOfLeaveLabel', 'd.fk_user'=>'UserID',
226  'd.date_debut'=>'DateStart', 'd.date_fin'=>'DateEnd', 'd.halfday'=>'HalfDay', 'none.num_open_days'=>'NbUseDaysCP',
227  'd.date_valid'=>'DateApprove', 'd.fk_validator'=>"UserForApprovalID",
228  'u.lastname'=>'Lastname', 'u.firstname'=>'Firstname', 'u.login'=>"Login",
229  'ua.lastname'=>"UserForApprovalLastname", 'ua.firstname'=>"UserForApprovalFirstname",
230  'ua.login'=>"UserForApprovalLogin", 'd.description'=>'Description', 'd.statut'=>'Status'
231  );
232  $this->export_TypeFields_array[$r] = array(
233  'd.rowid'=>"Numeric", 't.code'=>'Text', 't.label'=>'Text', 'd.fk_user'=>'Numeric',
234  'd.date_debut'=>'Date', 'd.date_fin'=>'Date', 'none.num_open_days'=>'NumericCompute',
235  'd.date_valid'=>'Date', 'd.fk_validator'=>"Numeric",
236  'u.lastname'=>'Text', 'u.firstname'=>'Text', 'u.login'=>"Text",
237  'ua.lastname'=>"Text", 'ua.firstname'=>"Text",
238  'ua.login'=>"Text", 'd.description'=>'Text', 'd.statut'=>'Numeric'
239  );
240  $this->export_entities_array[$r] = array(
241  'u.lastname'=>'user', 'u.firstname'=>'user', 'u.login'=>'user', 'ua.lastname'=>'user', 'ua.firstname'=>'user', 'ua.login'=>'user'
242  );
243  //$this->export_alias_array[$r] = array('d.rowid'=>"idholiday");
244  $this->export_special_array[$r] = array('none.num_open_days'=>'getNumOpenDays');
245  $this->export_dependencies_array[$r] = array(); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
246 
247  $keyforselect = 'holiday';
248  $keyforelement = 'holiday';
249  $keyforaliasextra = 'extra';
250  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
251  $keyforselect = 'user'; $keyforelement = 'user'; $keyforaliasextra = 'extrau';
252  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
253 
254  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
255  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'holiday as d';
256  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'holiday_extrafields as extra on d.rowid = extra.fk_object';
257  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_holiday_types as t ON t.rowid = d.fk_type';
258  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua ON ua.rowid = d.fk_validator,';
259  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'user as u';
260  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user_extrafields as extrau ON u.rowid = extrau.fk_object';
261  $this->export_sql_end[$r] .= ' WHERE d.fk_user = u.rowid';
262  $this->export_sql_end[$r] .= ' AND d.entity IN ('.getEntity('holiday').')';
263 
264  // Example:
265  // $this->export_code[$r]=$this->rights_class.'_'.$r;
266  // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
267  // $this->export_permission[$r]=array(array("facture","facture","export"));
268  // $this->export_fields_array[$r]=array(
269  // 's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone',
270  // 's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
271  // 's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",
272  // 'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus',
273  // 'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",
274  // 'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",
275  // 'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'
276  //);
277  // $this->export_entities_array[$r]=array(
278  // 's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company',
279  // 's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company',
280  // 'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",
281  // 'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",
282  // 'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",
283  // 'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'
284  //);
285  // $this->export_sql_start[$r]='SELECT DISTINCT ';
286  // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
287  // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
288  // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
289  // $r++;
290  }
291 
300  public function init($options = '')
301  {
302  global $conf;
303 
304  // Permissions
305  $this->remove($options);
306 
307  //ODT template
308  /*$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/holiday/template_holiday.odt';
309  $dirodt=DOL_DATA_ROOT.'/doctemplates/holiday';
310  $dest=$dirodt.'/template_order.odt';
311 
312  if (file_exists($src) && ! file_exists($dest))
313  {
314  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
315  dol_mkdir($dirodt);
316  $result=dol_copy($src, $dest, 0, 0);
317  if ($result < 0)
318  {
319  $langs->load("errors");
320  $this->error=$langs->trans('ErrorFailToCopyFile', $src, $dest);
321  return 0;
322  }
323  }
324  */
325 
326  $sql = array(
327  // "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'holiday' AND entity = ".((int) $conf->entity),
328  // "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','holiday',".((int) $conf->entity).")"
329  );
330 
331  return $this->_init($sql, $options);
332  }
333 }
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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode='auto')
Return date for now.
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:123