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