dolibarr 22.0.5
holiday.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3 * Copyright (C) 2012-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.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 <https://www.gnu.org/licenses/>.
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30
31
35class Holiday extends CommonObject
36{
40 public $element = 'holiday';
41
45 public $table_element = 'holiday';
46
50 public $fk_element = 'fk_holiday';
51
55 public $picto = 'holiday';
56
60 public $fk_user;
61
65 public $date_create = '';
66
70 public $description;
71
75 public $date_debut = '';
76
80 public $date_fin = '';
81
85 public $date_debut_gmt = '';
86
90 public $date_fin_gmt = '';
91
95 public $halfday = '';
96
101 public $statut = 0;
102
106 public $fk_validator;
107
111 public $date_valid = 0;
112
116 public $fk_user_valid;
117
121 public $date_approval;
122
126 public $fk_user_approve;
127
131 public $user_approve_id;
132
136 public $date_refuse = 0;
137
141 public $fk_user_refuse;
142
146 public $date_cancel = 0;
147
151 public $fk_user_cancel;
152
156 public $fk_user_create;
157
161 public $detail_refuse = '';
162
166 public $fk_type;
167
168 public $holiday = array();
169 public $events = array();
170 public $logs = array();
171
172
176 public $optName = '';
180 public $optValue = '';
184 public $optRowid = 0;
185
189 const STATUS_DRAFT = 1;
205 const STATUS_REFUSED = 5;
206
207
213 public function __construct($db)
214 {
215 $this->db = $db;
216
217 $this->ismultientitymanaged = 0;
218 }
219
220
228 public function getNextNumRef($objsoc)
229 {
230 global $langs, $conf;
231 $langs->load("order");
232
233 if (!getDolGlobalString('HOLIDAY_ADDON')) {
234 $conf->global->HOLIDAY_ADDON = 'mod_holiday_madonna';
235 }
236
237 if (getDolGlobalString('HOLIDAY_ADDON')) {
238 $mybool = false;
239
240 $file = getDolGlobalString('HOLIDAY_ADDON') . ".php";
241 $classname = getDolGlobalString('HOLIDAY_ADDON');
242
243 // Include file with class
244 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
245 foreach ($dirmodels as $reldir) {
246 $dir = dol_buildpath($reldir."core/modules/holiday/");
247
248 // Load file with numbering class (if found)
249 $mybool = ((bool) @include_once $dir.$file) || $mybool;
250 }
251
252 if (!$mybool) {
253 dol_print_error(null, "Failed to include file ".$file);
254 return '';
255 }
256
257 $obj = new $classname();
258 '@phan-var-force ModelNumRefHolidays $obj';
259 $numref = $obj->getNextValue($objsoc, $this);
260
261 if ($numref != "") {
262 return $numref;
263 } else {
264 $this->error = $obj->error;
265 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
266 return "";
267 }
268 } else {
269 print $langs->trans("Error")." ".$langs->trans("Error_HOLIDAY_ADDON_NotDefined");
270 return "";
271 }
272 }
273
279 public function updateBalance()
280 {
281 $this->db->begin();
282
283 // Update sold of vocations
284 $result = $this->updateSoldeCP();
285
286 // Check nb of users into table llx_holiday_users and update with empty lines
287 //if ($result > 0) $result = $this->verifNbUsers($this->countActiveUsersWithoutCP(), $this->getConfCP('nbUser'));
288
289 if ($result >= 0) {
290 $this->db->commit();
291 return 0; // for cronjob use (0 is OK, any other value is an error code)
292 } else {
293 $this->db->rollback();
294 return -1;
295 }
296 }
297
305 public function create($user, $notrigger = 0)
306 {
307 global $conf;
308 $error = 0;
309
310 $now = dol_now();
311
312 // Check parameters
313 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
314 $this->error = "ErrorBadParameterFkUser";
315 return -1;
316 }
317 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
318 $this->error = "ErrorBadParameterFkValidator";
319 return -1;
320 }
321 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
322 $this->error = "ErrorBadParameterFkType";
323 return -1;
324 }
325
326 // Insert request
327 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday(";
328 $sql .= "ref,";
329 $sql .= "fk_user,";
330 $sql .= "date_create,";
331 $sql .= "description,";
332 $sql .= "date_debut,";
333 $sql .= "date_fin,";
334 $sql .= "halfday,";
335 $sql .= "statut,";
336 $sql .= "fk_validator,";
337 $sql .= "fk_type,";
338 $sql .= "fk_user_create,";
339 $sql .= "entity";
340 $sql .= ") VALUES (";
341 $sql .= "'(PROV)',";
342 $sql .= " ".((int) $this->fk_user).",";
343 $sql .= " '".$this->db->idate($now)."',";
344 $sql .= " '".$this->db->escape($this->description)."',";
345 $sql .= " '".$this->db->idate($this->date_debut)."',";
346 $sql .= " '".$this->db->idate($this->date_fin)."',";
347 $sql .= " ".((int) $this->halfday).",";
348 $sql .= " '1',";
349 $sql .= " ".((int) $this->fk_validator).",";
350 $sql .= " ".((int) $this->fk_type).",";
351 $sql .= " ".((int) $user->id).",";
352 $sql .= " ".((int) $conf->entity);
353 $sql .= ")";
354
355 $this->db->begin();
356
357 dol_syslog(get_class($this)."::create", LOG_DEBUG);
358 $resql = $this->db->query($sql);
359 if (!$resql) {
360 $error++;
361 $this->errors[] = "Error ".$this->db->lasterror();
362 }
363
364 if (!$error) {
365 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday");
366
367 if ($this->id) {
368 // update ref
369 $initialref = '(PROV'.$this->id.')';
370 if (!empty($this->ref)) {
371 $initialref = $this->ref;
372 }
373
374 $sql = 'UPDATE '.MAIN_DB_PREFIX."holiday SET ref='".$this->db->escape($initialref)."' WHERE rowid=".((int) $this->id);
375 if ($this->db->query($sql)) {
376 $this->ref = $initialref;
377
378 if (!$error) {
379 $result = $this->insertExtraFields();
380 if ($result < 0) {
381 $error++;
382 }
383 }
384
385 if (!$error && !$notrigger) {
386 // Call trigger
387 $result = $this->call_trigger('HOLIDAY_CREATE', $user);
388 if ($result < 0) {
389 $error++;
390 }
391 // End call triggers
392 }
393 }
394 }
395 }
396
397 // Commit or rollback
398 if ($error) {
399 foreach ($this->errors as $errmsg) {
400 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
401 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
402 }
403 $this->db->rollback();
404 return -1 * $error;
405 } else {
406 $this->db->commit();
407 return $this->id;
408 }
409 }
410
411
419 public function fetch($id, $ref = '')
420 {
421 $sql = "SELECT";
422 $sql .= " cp.rowid,";
423 $sql .= " cp.ref,";
424 $sql .= " cp.fk_user,";
425 $sql .= " cp.date_create,";
426 $sql .= " cp.description,";
427 $sql .= " cp.date_debut,";
428 $sql .= " cp.date_fin,";
429 $sql .= " cp.halfday,";
430 $sql .= " cp.statut as status,";
431 $sql .= " cp.fk_validator,";
432 $sql .= " cp.date_valid,";
433 $sql .= " cp.fk_user_valid,";
434 $sql .= " cp.date_approval,";
435 $sql .= " cp.fk_user_approve,";
436 $sql .= " cp.date_refuse,";
437 $sql .= " cp.fk_user_refuse,";
438 $sql .= " cp.date_cancel,";
439 $sql .= " cp.fk_user_cancel,";
440 $sql .= " cp.detail_refuse,";
441 $sql .= " cp.note_private,";
442 $sql .= " cp.note_public,";
443 $sql .= " cp.fk_user_create,";
444 $sql .= " cp.fk_type,";
445 $sql .= " cp.entity";
446 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
447 if ($id > 0) {
448 $sql .= " WHERE cp.rowid = ".((int) $id);
449 } else {
450 $sql .= " WHERE cp.ref = '".$this->db->escape($ref)."'";
451 }
452
453 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
454 $resql = $this->db->query($sql);
455 if ($resql) {
456 if ($this->db->num_rows($resql)) {
457 $obj = $this->db->fetch_object($resql);
458
459 $this->id = $obj->rowid;
460 $this->ref = ($obj->ref ? $obj->ref : $obj->rowid);
461 $this->fk_user = $obj->fk_user;
462 $this->date_create = $this->db->jdate($obj->date_create);
463 $this->description = $obj->description;
464 $this->date_debut = $this->db->jdate($obj->date_debut);
465 $this->date_fin = $this->db->jdate($obj->date_fin);
466 $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
467 $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
468 $this->halfday = $obj->halfday;
469 $this->status = $obj->status;
470 $this->statut = $obj->status; // deprecated
471 $this->fk_validator = $obj->fk_validator;
472 $this->date_valid = $this->db->jdate($obj->date_valid);
473 $this->fk_user_valid = $obj->fk_user_valid;
474 $this->user_validation_id = $obj->fk_user_valid;
475 $this->date_approval = $this->db->jdate($obj->date_approval);
476 $this->fk_user_approve = $obj->fk_user_approve;
477 $this->date_refuse = $this->db->jdate($obj->date_refuse);
478 $this->fk_user_refuse = $obj->fk_user_refuse;
479 $this->date_cancel = $this->db->jdate($obj->date_cancel);
480 $this->fk_user_cancel = $obj->fk_user_cancel;
481 $this->detail_refuse = $obj->detail_refuse;
482 $this->note_private = $obj->note_private;
483 $this->note_public = $obj->note_public;
484 $this->fk_user_create = $obj->fk_user_create;
485 $this->fk_type = $obj->fk_type;
486 $this->entity = $obj->entity;
487
488 $this->fetch_optionals();
489
490 $result = 1;
491 } else {
492 $result = 0;
493 }
494 $this->db->free($resql);
495
496 return $result;
497 } else {
498 $this->error = "Error ".$this->db->lasterror();
499 return -1;
500 }
501 }
502
511 public function fetchByUser($user_id, $order = '', $filter = '')
512 {
513 $this->holiday = [];
514 $sql = "SELECT";
515 $sql .= " cp.rowid,";
516 $sql .= " cp.ref,";
517
518 $sql .= " cp.fk_user,";
519 $sql .= " cp.fk_type,";
520 $sql .= " cp.date_create,";
521 $sql .= " cp.description,";
522 $sql .= " cp.date_debut,";
523 $sql .= " cp.date_fin,";
524 $sql .= " cp.halfday,";
525 $sql .= " cp.statut as status,";
526 $sql .= " cp.fk_validator,";
527 $sql .= " cp.date_valid,";
528 $sql .= " cp.fk_user_valid,";
529 $sql .= " cp.date_approval,";
530 $sql .= " cp.fk_user_approve,";
531 $sql .= " cp.date_refuse,";
532 $sql .= " cp.fk_user_refuse,";
533 $sql .= " cp.date_cancel,";
534 $sql .= " cp.fk_user_cancel,";
535 $sql .= " cp.detail_refuse,";
536
537 $sql .= " uu.lastname as user_lastname,";
538 $sql .= " uu.firstname as user_firstname,";
539 $sql .= " uu.login as user_login,";
540 $sql .= " uu.statut as user_status,";
541 $sql .= " uu.photo as user_photo,";
542
543 $sql .= " ua.lastname as validator_lastname,";
544 $sql .= " ua.firstname as validator_firstname,";
545 $sql .= " ua.login as validator_login,";
546 $sql .= " ua.statut as validator_status,";
547 $sql .= " ua.photo as validator_photo";
548
549 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
550 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
551 $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid"; // Hack pour la recherche sur le tableau
552 $sql .= " AND cp.fk_user IN (".$this->db->sanitize($user_id).")";
553
554 // Selection filter
555 if (!empty($filter)) {
556 $sql .= $filter;
557 }
558
559 // Order of display of the result
560 if (!empty($order)) {
561 $sql .= $order;
562 }
563
564 dol_syslog(get_class($this)."::fetchByUser", LOG_DEBUG);
565 $resql = $this->db->query($sql);
566
567 // If no SQL error
568 if ($resql) {
569 $i = 0;
570 $tab_result = $this->holiday;
571 $num = $this->db->num_rows($resql);
572
573 // If no registration
574 if (!$num) {
575 return 2;
576 }
577
578 // List the records and add them to the table
579 while ($i < $num) {
580 $obj = $this->db->fetch_object($resql);
581
582 $tab_result[$i]['rowid'] = $obj->rowid;
583 $tab_result[$i]['id'] = $obj->rowid;
584 $tab_result[$i]['ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
585
586 $tab_result[$i]['fk_user'] = $obj->fk_user;
587 $tab_result[$i]['fk_type'] = $obj->fk_type;
588 $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
589 $tab_result[$i]['description'] = $obj->description;
590 $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
591 $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
592 $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
593 $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
594 $tab_result[$i]['halfday'] = $obj->halfday;
595 $tab_result[$i]['statut'] = $obj->status;
596 $tab_result[$i]['status'] = $obj->status;
597 $tab_result[$i]['fk_validator'] = $obj->fk_validator;
598 $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
599 $tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
600 $tab_result[$i]['date_approval'] = $this->db->jdate($obj->date_approval);
601 $tab_result[$i]['fk_user_approve'] = $obj->fk_user_approve;
602 $tab_result[$i]['date_refuse'] = $this->db->jdate($obj->date_refuse);
603 $tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
604 $tab_result[$i]['date_cancel'] = $this->db->jdate($obj->date_cancel);
605 $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
606 $tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
607
608 $tab_result[$i]['user_firstname'] = $obj->user_firstname;
609 $tab_result[$i]['user_lastname'] = $obj->user_lastname;
610 $tab_result[$i]['user_login'] = $obj->user_login;
611 $tab_result[$i]['user_statut'] = $obj->user_status;
612 $tab_result[$i]['user_status'] = $obj->user_status;
613 $tab_result[$i]['user_photo'] = $obj->user_photo;
614
615 $tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
616 $tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
617 $tab_result[$i]['validator_login'] = $obj->validator_login;
618 $tab_result[$i]['validator_statut'] = $obj->validator_status;
619 $tab_result[$i]['validator_status'] = $obj->validator_status;
620 $tab_result[$i]['validator_photo'] = $obj->validator_photo;
621
622 $i++;
623 }
624
625 // Returns 1 with the filled array
626 $this->holiday = $tab_result;
627 return 1;
628 } else {
629 // SQL Error
630 $this->error = "Error ".$this->db->lasterror();
631 return -1;
632 }
633 }
634
642 public function fetchAll($order, $filter)
643 {
644 $sql = "SELECT";
645 $sql .= " cp.rowid,";
646 $sql .= " cp.ref,";
647 $sql .= " cp.fk_user,";
648 $sql .= " cp.fk_type,";
649 $sql .= " cp.date_create,";
650 $sql .= " cp.tms as date_modification,";
651 $sql .= " cp.description,";
652 $sql .= " cp.date_debut,";
653 $sql .= " cp.date_fin,";
654 $sql .= " cp.halfday,";
655 $sql .= " cp.statut as status,";
656 $sql .= " cp.fk_validator,";
657 $sql .= " cp.date_valid,";
658 $sql .= " cp.fk_user_valid,";
659 $sql .= " cp.date_approval,";
660 $sql .= " cp.fk_user_approve,";
661 $sql .= " cp.date_refuse,";
662 $sql .= " cp.fk_user_refuse,";
663 $sql .= " cp.date_cancel,";
664 $sql .= " cp.fk_user_cancel,";
665 $sql .= " cp.detail_refuse,";
666
667 $sql .= " uu.lastname as user_lastname,";
668 $sql .= " uu.firstname as user_firstname,";
669 $sql .= " uu.login as user_login,";
670 $sql .= " uu.statut as user_status,";
671 $sql .= " uu.photo as user_photo,";
672
673 $sql .= " ua.lastname as validator_lastname,";
674 $sql .= " ua.firstname as validator_firstname,";
675 $sql .= " ua.login as validator_login,";
676 $sql .= " ua.statut as validator_status,";
677 $sql .= " ua.photo as validator_photo";
678
679 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
680 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
681 $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
682
683 // Selection filtering
684 if (!empty($filter)) {
685 $sql .= $filter;
686 }
687
688 // order of display
689 if (!empty($order)) {
690 $sql .= $order;
691 }
692
693 dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
694 $resql = $this->db->query($sql);
695
696 // If no SQL error
697 if ($resql) {
698 $i = 0;
699 $tab_result = $this->holiday;
700 $num = $this->db->num_rows($resql);
701
702 // If no registration
703 if (!$num) {
704 return 2;
705 }
706
707 // List the records and add them to the table
708 while ($i < $num) {
709 $obj = $this->db->fetch_object($resql);
710
711 $tab_result[$i]['rowid'] = $obj->rowid;
712 $tab_result[$i]['id'] = $obj->rowid;
713 $tab_result[$i]['ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
714
715 $tab_result[$i]['fk_user'] = $obj->fk_user;
716 $tab_result[$i]['fk_type'] = $obj->fk_type;
717 $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
718 $tab_result[$i]['date_modification'] = $this->db->jdate($obj->date_modification);
719 $tab_result[$i]['description'] = $obj->description;
720 $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
721 $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
722 $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
723 $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
724 $tab_result[$i]['halfday'] = $obj->halfday;
725 $tab_result[$i]['statut'] = $obj->status;
726 $tab_result[$i]['status'] = $obj->status;
727 $tab_result[$i]['fk_validator'] = $obj->fk_validator;
728 $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
729 $tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
730 $tab_result[$i]['date_approval'] = $this->db->jdate($obj->date_approval);
731 $tab_result[$i]['fk_user_approve'] = $obj->fk_user_approve;
732 $tab_result[$i]['date_refuse'] = $obj->date_refuse;
733 $tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
734 $tab_result[$i]['date_cancel'] = $obj->date_cancel;
735 $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
736 $tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
737
738 $tab_result[$i]['user_firstname'] = $obj->user_firstname;
739 $tab_result[$i]['user_lastname'] = $obj->user_lastname;
740 $tab_result[$i]['user_login'] = $obj->user_login;
741 $tab_result[$i]['user_statut'] = $obj->user_status;
742 $tab_result[$i]['user_status'] = $obj->user_status;
743 $tab_result[$i]['user_photo'] = $obj->user_photo;
744
745 $tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
746 $tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
747 $tab_result[$i]['validator_login'] = $obj->validator_login;
748 $tab_result[$i]['validator_statut'] = $obj->validator_status;
749 $tab_result[$i]['validator_status'] = $obj->validator_status;
750 $tab_result[$i]['validator_photo'] = $obj->validator_photo;
751
752 $i++;
753 }
754 // Returns 1 and adds the array to the variable
755 $this->holiday = $tab_result;
756 return 1;
757 } else {
758 // SQL Error
759 $this->error = "Error ".$this->db->lasterror();
760 return -1;
761 }
762 }
763
764
772 public function validate($user = null, $notrigger = 0)
773 {
774 global $conf, $langs;
775 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
776 $error = 0;
777
778
779 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
780
781 if ($checkBalance > 0) {
782 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
783 // Use the GMT variants: num_public_holiday(), called by num_open_day(), refuses a range whose
784 // length is not a whole number of days, and a range spanning a DST transition is 23h or 25h
785 // long in the server timezone. It then returns a string and the subtraction fatals.
786 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
787 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
788 $daysAsked = num_open_day($datedebutforcount, $datefinforcount, 0, 1, (int) $this->halfday);
789
790 if (($balance - $daysAsked) < 0) {
791 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
792 return -1;
793 }
794 }
795
796 // Define new ref
797 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id)) {
798 $num = $this->getNextNumRef(null);
799 } else {
800 $num = $this->ref;
801 }
802 $this->newref = dol_sanitizeFileName($num);
803
804 // Update status
805 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
806 $sql .= " fk_user_valid = ".((int) $user->id).",";
807 $sql .= " date_valid = '".$this->db->idate(dol_now())."',";
808 if (!empty($this->status) && is_numeric($this->status)) {
809 $sql .= " statut = ".((int) $this->status).",";
810 } else {
811 $this->error = 'Property status must be a numeric value';
812 $error++;
813 }
814 $sql .= " ref = '".$this->db->escape($num)."'";
815 $sql .= " WHERE rowid = ".((int) $this->id);
816
817 $this->db->begin();
818
819 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
820 $resql = $this->db->query($sql);
821 if (!$resql) {
822 $error++;
823 $this->errors[] = "Error ".$this->db->lasterror();
824 }
825
826 if (!$error) {
827 if (!$notrigger) {
828 // Call trigger
829 $result = $this->call_trigger('HOLIDAY_VALIDATE', $user);
830 if ($result < 0) {
831 $error++;
832 }
833 // End call triggers
834 }
835 }
836
837 if (!$error) {
838 $this->oldref = $this->ref;
839
840 // Rename directory if dir was a temporary ref
841 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
842 // Now we rename also files into index
843 $sql = 'UPDATE ' . MAIN_DB_PREFIX . "ecm_files set filename = CONCAT('" . $this->db->escape($this->newref) . "', SUBSTR(filename, " . (strlen($this->ref) + 1) . ")), filepath = 'holiday/" . $this->db->escape($this->newref) . "'";
844 $sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'holiday/" . $this->db->escape($this->ref) . "' and entity = " . ((int) $conf->entity);
845 $resql = $this->db->query($sql);
846 if (!$resql) {
847 $error++;
848 $this->error = $this->db->lasterror();
849 }
850 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'holiday/".$this->db->escape($this->newref)."'";
851 $sql .= " WHERE filepath = 'holiday/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
852 $resql = $this->db->query($sql);
853 if (!$resql) {
854 $error++;
855 $this->error = $this->db->lasterror();
856 }
857
858 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
859 $oldref = dol_sanitizeFileName($this->ref);
860 $newref = dol_sanitizeFileName($num);
861 $dirsource = $conf->holiday->multidir_output[$this->entity] . '/' . $oldref;
862 $dirdest = $conf->holiday->multidir_output[$this->entity] . '/' . $newref;
863 if (!$error && file_exists($dirsource)) {
864 dol_syslog(get_class($this) . "::validate rename dir " . $dirsource . " into " . $dirdest);
865 if (@rename($dirsource, $dirdest)) {
866 dol_syslog("Rename ok");
867 // Rename docs starting with $oldref with $newref
868 $listoffiles = dol_dir_list($dirdest, 'files', 1, '^' . preg_quote($oldref, '/'));
869 foreach ($listoffiles as $fileentry) {
870 $dirsource = $fileentry['name'];
871 $dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource);
872 $dirsource = $fileentry['path'] . '/' . $dirsource;
873 $dirdest = $fileentry['path'] . '/' . $dirdest;
874 @rename($dirsource, $dirdest);
875 }
876 }
877 }
878 }
879 }
880
881
882 // Commit or rollback
883 if ($error) {
884 foreach ($this->errors as $errmsg) {
885 dol_syslog(get_class($this)."::validate ".$errmsg, LOG_ERR);
886 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
887 }
888 $this->db->rollback();
889 return -1 * $error;
890 } else {
891 $this->db->commit();
892 return 1;
893 }
894 }
895
896
904 public function approve($user = null, $notrigger = 0)
905 {
906 $error = 0;
907
908 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
909
910 if ($checkBalance > 0) {
911 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
912 // Use the GMT variants: num_public_holiday(), called by num_open_day(), refuses a range whose
913 // length is not a whole number of days, and a range spanning a DST transition is 23h or 25h
914 // long in the server timezone. It then returns a string and the subtraction fatals.
915 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
916 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
917 $daysAsked = num_open_day($datedebutforcount, $datefinforcount, 0, 1, (int) $this->halfday);
918
919 if (($balance - $daysAsked) < 0) {
920 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
921 return -1;
922 }
923 }
924
925 // Update request
926 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
927 $sql .= " description= '".$this->db->escape($this->description)."',";
928 if (!empty($this->date_debut)) {
929 $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
930 } else {
931 $error++;
932 }
933 if (!empty($this->date_fin)) {
934 $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
935 } else {
936 $error++;
937 }
938 $sql .= " halfday = ".((int) $this->halfday).",";
939 if (!empty($this->status) && is_numeric($this->status)) {
940 $sql .= " statut = ".((int) $this->status).",";
941 } else {
942 $error++;
943 }
944 if (!empty($this->fk_validator)) {
945 $sql .= " fk_validator = ".((int) $this->fk_validator).",";
946 } else {
947 $error++;
948 }
949 if (!empty($this->date_valid)) {
950 $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
951 } else {
952 $sql .= " date_valid = NULL,";
953 }
954 if (!empty($this->fk_user_valid)) {
955 $sql .= " fk_user_valid = ".((int) $this->fk_user_valid).",";
956 } else {
957 $sql .= " fk_user_valid = NULL,";
958 }
959 if (!empty($this->date_approval)) {
960 $sql .= " date_approval = '".$this->db->idate($this->date_approval)."',";
961 } else {
962 $sql .= " date_approval = NULL,";
963 }
964 if (!empty($this->fk_user_approve)) {
965 $sql .= " fk_user_approve = ".((int) $this->fk_user_approve).",";
966 } else {
967 $sql .= " fk_user_approve = NULL,";
968 }
969 if (!empty($this->date_refuse)) {
970 $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
971 } else {
972 $sql .= " date_refuse = NULL,";
973 }
974 if (!empty($this->fk_user_refuse)) {
975 $sql .= " fk_user_refuse = ".((int) $this->fk_user_refuse).",";
976 } else {
977 $sql .= " fk_user_refuse = NULL,";
978 }
979 if (!empty($this->date_cancel)) {
980 $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
981 } else {
982 $sql .= " date_cancel = NULL,";
983 }
984 if (!empty($this->fk_user_cancel)) {
985 $sql .= " fk_user_cancel = ".((int) $this->fk_user_cancel).",";
986 } else {
987 $sql .= " fk_user_cancel = NULL,";
988 }
989 if (!empty($this->detail_refuse)) {
990 $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
991 } else {
992 $sql .= " detail_refuse = NULL";
993 }
994 $sql .= " WHERE rowid = ".((int) $this->id);
995
996 $this->db->begin();
997
998 dol_syslog(get_class($this)."::approve", LOG_DEBUG);
999 $resql = $this->db->query($sql);
1000 if (!$resql) {
1001 $error++;
1002 $this->errors[] = "Error ".$this->db->lasterror();
1003 }
1004
1005 if (!$error) {
1006 if (!$notrigger) {
1007 // Call trigger
1008 $result = $this->call_trigger('HOLIDAY_APPROVE', $user);
1009 if ($result < 0) {
1010 $error++;
1011 }
1012 // End call triggers
1013 }
1014 }
1015
1016 // Commit or rollback
1017 if ($error) {
1018 foreach ($this->errors as $errmsg) {
1019 dol_syslog(get_class($this)."::approve ".$errmsg, LOG_ERR);
1020 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1021 }
1022 $this->db->rollback();
1023 return -1 * $error;
1024 } else {
1025 $this->db->commit();
1026 return 1;
1027 }
1028 }
1029
1037 public function update($user = null, $notrigger = 0)
1038 {
1039 global $conf, $langs;
1040 $error = 0;
1041
1042 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
1043 if ($this->status == self::STATUS_REFUSED || $this->status == self::STATUS_APPROVED) {
1044 $checkBalance = 0; // No balance check to refuse a request, nor on an approved request (its days are already debited)
1045 }
1046
1047 if ($checkBalance > 0 && $this->statut != self::STATUS_DRAFT && $this->statut != self::STATUS_CANCELED) {
1048 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
1049 // Use the GMT variants: num_public_holiday(), called by num_open_day(), refuses a range whose
1050 // length is not a whole number of days, and a range spanning a DST transition is 23h or 25h
1051 // long in the server timezone. It then returns a string and the subtraction fatals.
1052 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
1053 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
1054 $daysAsked = num_open_day($datedebutforcount, $datefinforcount, 0, 1, (int) $this->halfday);
1055
1056 if (($balance - $daysAsked) < 0) {
1057 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1058 return -1;
1059 }
1060 }
1061
1062 // Update request
1063 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
1064
1065 $sql .= " description= '".$this->db->escape($this->description)."',";
1066
1067 if (!empty($this->date_debut)) {
1068 $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
1069 } else {
1070 $error++;
1071 }
1072 if (!empty($this->date_fin)) {
1073 $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
1074 } else {
1075 $error++;
1076 }
1077 $sql .= " halfday = ".((int) $this->halfday).",";
1078 if (!empty($this->status) && is_numeric($this->status)) {
1079 $sql .= " statut = ".((int) $this->status).",";
1080 } else {
1081 $error++;
1082 }
1083 if (!empty($this->fk_validator)) {
1084 $sql .= " fk_validator = ".((int) $this->fk_validator).",";
1085 } else {
1086 $error++;
1087 }
1088 if (!empty($this->date_valid)) {
1089 $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
1090 } else {
1091 $sql .= " date_valid = NULL,";
1092 }
1093 if (!empty($this->fk_user_valid)) {
1094 $sql .= " fk_user_valid = ".((int) $this->fk_user_valid).",";
1095 } else {
1096 $sql .= " fk_user_valid = NULL,";
1097 }
1098 if (!empty($this->date_approval)) {
1099 $sql .= " date_approval = '".$this->db->idate($this->date_approval)."',";
1100 } else {
1101 $sql .= " date_approval = NULL,";
1102 }
1103 if (!empty($this->fk_user_approve)) {
1104 $sql .= " fk_user_approve = ".((int) $this->fk_user_approve).",";
1105 } else {
1106 $sql .= " fk_user_approve = NULL,";
1107 }
1108 if (!empty($this->date_refuse)) {
1109 $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
1110 } else {
1111 $sql .= " date_refuse = NULL,";
1112 }
1113 if (!empty($this->fk_user_refuse)) {
1114 $sql .= " fk_user_refuse = ".((int) $this->fk_user_refuse).",";
1115 } else {
1116 $sql .= " fk_user_refuse = NULL,";
1117 }
1118 if (!empty($this->date_cancel)) {
1119 $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
1120 } else {
1121 $sql .= " date_cancel = NULL,";
1122 }
1123 if (!empty($this->fk_user_cancel)) {
1124 $sql .= " fk_user_cancel = ".((int) $this->fk_user_cancel).",";
1125 } else {
1126 $sql .= " fk_user_cancel = NULL,";
1127 }
1128 if (!empty($this->detail_refuse)) {
1129 $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
1130 } else {
1131 $sql .= " detail_refuse = NULL";
1132 }
1133
1134 $sql .= " WHERE rowid = ".((int) $this->id);
1135
1136 $this->db->begin();
1137
1138 dol_syslog(get_class($this)."::update", LOG_DEBUG);
1139 $resql = $this->db->query($sql);
1140 if (!$resql) {
1141 $error++;
1142 $this->errors[] = "Error ".$this->db->lasterror();
1143 }
1144
1145 if (!$error) {
1146 $result = $this->insertExtraFields();
1147 if ($result < 0) {
1148 $error++;
1149 }
1150 }
1151
1152 if (!$error) {
1153 if (!$notrigger && $user !== null) {
1154 // Call trigger
1155 $result = $this->call_trigger('HOLIDAY_MODIFY', $user);
1156 if ($result < 0) {
1157 $error++;
1158 }
1159 // End call triggers
1160 }
1161 }
1162
1163 // Commit or rollback
1164 if ($error) {
1165 foreach ($this->errors as $errmsg) {
1166 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1167 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1168 }
1169 $this->db->rollback();
1170 return -1 * $error;
1171 } else {
1172 $this->db->commit();
1173 return 1;
1174 }
1175 }
1176
1177
1185 public function delete($user, $notrigger = 0)
1186 {
1187 global $conf, $langs;
1188 $error = 0;
1189
1190 $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday";
1191 $sql .= " WHERE rowid=".((int) $this->id);
1192
1193 $this->db->begin();
1194
1195 // Delete extrafields before the leave request
1196 $result = $this->deleteExtraFields();
1197 if ($result < 0) {
1198 $error++;
1199 }
1200
1201 if (!$error) {
1202 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1203 $resql = $this->db->query($sql);
1204 if (!$resql) {
1205 $error++;
1206 $this->errors[] = "Error ".$this->db->lasterror();
1207 }
1208 }
1209
1210 if (!$error) {
1211 if (!$notrigger) {
1212 // Call trigger
1213 $result = $this->call_trigger('HOLIDAY_DELETE', $user);
1214 if ($result < 0) {
1215 $error++;
1216 }
1217 // End call triggers
1218 }
1219 }
1220
1221 // Commit or rollback
1222 if ($error) {
1223 foreach ($this->errors as $errmsg) {
1224 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
1225 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1226 }
1227 $this->db->rollback();
1228 return -1 * $error;
1229 } else {
1230 $this->db->commit();
1231 return 1;
1232 }
1233 }
1234
1248 public function verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday = 0)
1249 {
1250 $this->fetchByUser($fk_user, '', '');
1251
1252 foreach ($this->holiday as $infos_CP) {
1253 if ($infos_CP['statut'] == Holiday::STATUS_CANCELED) {
1254 continue; // ignore not validated holidays
1255 }
1256 if ($infos_CP['statut'] == Holiday::STATUS_REFUSED) {
1257 continue; // ignore refused holidays
1258 }
1259 //var_dump("--");
1260 //var_dump("old: ".dol_print_date($infos_CP['date_debut'],'dayhour').' '.dol_print_date($infos_CP['date_fin'],'dayhour').' '.$infos_CP['halfday']);
1261 //var_dump("new: ".dol_print_date($dateStart,'dayhour').' '.dol_print_date($dateEnd,'dayhour').' '.$halfday);
1262
1263 if ($halfday == 0) {
1264 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1265 return false;
1266 }
1267 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1268 return false;
1269 }
1270 } elseif ($halfday == -1) {
1271 // new start afternoon, new end afternoon
1272 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1273 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1274 return false;
1275 }
1276 }
1277 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1278 if ($dateStart < $dateEnd) {
1279 return false;
1280 }
1281 if ($dateEnd < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1282 return false;
1283 }
1284 }
1285 } elseif ($halfday == 1) {
1286 // new start morning, new end morning
1287 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1288 if ($dateStart < $dateEnd) {
1289 return false;
1290 }
1291 if ($dateStart > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1292 return false;
1293 }
1294 }
1295 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1296 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1297 return false;
1298 }
1299 }
1300 } elseif ($halfday == 2) {
1301 // new start afternoon, new end morning
1302 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1303 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1304 return false;
1305 }
1306 }
1307 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1308 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1309 return false;
1310 }
1311 }
1312 } else {
1313 dol_print_error(null, 'Bad value of parameter halfday when calling function verifDateHolidayCP');
1314 }
1315 }
1316
1317 return true;
1318 }
1319
1320
1330 public function verifDateHolidayForTimestamp($fk_user, $timestamp, $status = '-1')
1331 {
1332 $isavailablemorning = true;
1333 $isavailableafternoon = true;
1334
1335 // Check into leave requests
1336 $sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1337 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
1338 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
1339 $sql .= " AND cp.fk_user = ".(int) $fk_user;
1340 $sql .= " AND cp.date_debut <= '".$this->db->idate($timestamp)."' AND cp.date_fin >= '".$this->db->idate($timestamp)."'";
1341 if ($status != '-1') {
1342 $sql .= " AND cp.statut IN (".$this->db->sanitize($status).")";
1343 }
1344
1345 $resql = $this->db->query($sql);
1346 if ($resql) {
1347 $num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon
1348 if ($num_rows > 0) {
1349 $arrayofrecord = array();
1350 $i = 0;
1351 while ($i < $num_rows) {
1352 $obj = $this->db->fetch_object($resql);
1353
1354 // Note: $obj->halfday is 0:Full days, 2:Start afternoon end morning, -1:Start afternoon, 1:End morning
1355 $arrayofrecord[$obj->rowid] = array('date_start' => $this->db->jdate($obj->date_start), 'date_end' => $this->db->jdate($obj->date_end), 'halfday' => $obj->halfday, 'status' => $obj->status);
1356 $i++;
1357 }
1358
1359 // We found a record, user is on holiday by default, so is not available is true.
1360 $isavailablemorning = true;
1361 foreach ($arrayofrecord as $record) {
1362 if ($timestamp == $record['date_start'] && $record['halfday'] == 2) {
1363 continue;
1364 }
1365 if ($timestamp == $record['date_start'] && $record['halfday'] == -1) {
1366 continue;
1367 }
1368 $isavailablemorning = false;
1369 break;
1370 }
1371 $isavailableafternoon = true;
1372 foreach ($arrayofrecord as $record) {
1373 if ($timestamp == $record['date_end'] && $record['halfday'] == 2) {
1374 continue;
1375 }
1376 if ($timestamp == $record['date_end'] && $record['halfday'] == 1) {
1377 continue;
1378 }
1379 $isavailableafternoon = false;
1380 break;
1381 }
1382 }
1383 } else {
1384 dol_print_error($this->db);
1385 }
1386
1387 $result = array('morning' => (int) $isavailablemorning, 'afternoon' => (int) $isavailableafternoon);
1388 if (!$isavailablemorning) {
1389 $result['morning_reason'] = 'leave_request';
1390 }
1391 if (!$isavailableafternoon) {
1392 $result['afternoon_reason'] = 'leave_request';
1393 }
1394 return $result;
1395 }
1396
1403 public function getTooltipContentArray($params)
1404 {
1405 global $langs;
1406
1407 $langs->load('holiday');
1408 $nofetch = !empty($params['nofetch']);
1409
1410 $datas = array();
1411 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Holiday").'</u>';
1412 if (isset($this->status)) {
1413 $datas['picto'] .= ' '.$this->getLibStatut(5);
1414 }
1415 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1416 // show type for this record only in ajax to not overload lists
1417 if (!$nofetch && !empty($this->fk_type)) {
1418 $typeleaves = $this->getTypes(1, -1);
1419 if (empty($typeleaves[$this->fk_type])) {
1420 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $this->fk_type);
1421 } else {
1422 $labeltoshow = (($typeleaves[$this->fk_type]['code'] && $langs->trans($typeleaves[$this->fk_type]['code']) != $typeleaves[$this->fk_type]['code']) ? $langs->trans($typeleaves[$this->fk_type]['code']) : $typeleaves[$this->fk_type]['label']);
1423 }
1424 $datas['type'] = '<br><b>'.$langs->trans("Type") . ':</b> ' . $labeltoshow;
1425 }
1426 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1427 $listhalfday = array(
1428 'morning' => $langs->trans("Morning"),
1429 "afternoon" => $langs->trans("Afternoon")
1430 );
1431 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ? 'afternoon' : 'morning';
1432 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ? 'morning' : 'afternoon';
1433 $datas['date_start'] = '<br><b>'.$langs->trans('DateDebCP') . '</b>: '. dol_print_date($this->date_debut, 'day') . '&nbsp;&nbsp;<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
1434 $datas['date_end'] = '<br><b>'.$langs->trans('DateFinCP') . '</b>: '. dol_print_date($this->date_fin, 'day') . '&nbsp;&nbsp;<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
1435 }
1436
1437
1438 return $datas;
1439 }
1440
1450 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
1451 {
1452 global $conf, $langs, $hookmanager;
1453
1454 if (!empty($conf->dol_no_mouse_hover)) {
1455 $notooltip = 1; // Force disable tooltips
1456 }
1457
1458 $result = '';
1459 $params = [
1460 'id' => $this->id,
1461 'objecttype' => $this->element,
1462 'nofetch' => 1,
1463 ];
1464 $classfortooltip = 'classfortooltip';
1465 $dataparams = '';
1466 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1467 $classfortooltip = 'classforajaxtooltip';
1468 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1469 $label = '';
1470 } else {
1471 $label = implode($this->getTooltipContentArray($params));
1472 }
1473
1474 $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
1475
1476 //if ($option != 'nolink')
1477 //{
1478 // Add param to save lastsearch_values or not
1479 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1480 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1481 $add_save_lastsearch_values = 1;
1482 }
1483 if ($add_save_lastsearch_values) {
1484 $url .= '&save_lastsearch_values=1';
1485 }
1486 //}
1487
1488 $linkclose = '';
1489 if (empty($notooltip)) {
1490 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1491 $label = $langs->trans("ShowMyObject");
1492 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1493 }
1494 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1495 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1496 } else {
1497 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1498 }
1499
1500 $linkstart = '<a href="'.$url.'"';
1501 $linkstart .= $linkclose.'>';
1502 $linkend = '</a>';
1503
1504 $result .= $linkstart;
1505
1506 if ($withpicto) {
1507 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1508 }
1509 if ($withpicto != 2) {
1510 $result .= $this->ref;
1511 }
1512 $result .= $linkend;
1513
1514 global $action;
1515 $hookmanager->initHooks(array($this->element . 'dao'));
1516 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1517 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1518 if ($reshook > 0) {
1519 $result = $hookmanager->resPrint;
1520 } else {
1521 $result .= $hookmanager->resPrint;
1522 }
1523 return $result;
1524 }
1525
1526
1533 public function getLibStatut($mode = 0)
1534 {
1535 return $this->LibStatut($this->status, $mode, $this->date_debut);
1536 }
1537
1538 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1547 public function LibStatut($status, $mode = 0, $startdate = '')
1548 {
1549 // phpcs:enable
1550 global $langs;
1551
1552 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1553 global $langs;
1554 //$langs->load("mymodule");
1555 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1556 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1557 $this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1558 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1559 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1560 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1561 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1562 $this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1563 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1564 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1565 }
1566
1567 $params = array();
1568 $statusType = 'status6';
1569 if (!empty($startdate) && $startdate >= dol_now()) { // If not yet passed, we use a green "in live" color
1570 $statusType = 'status4';
1571 $params = array('tooltip' => $this->labelStatus[$status].' - '.$langs->trans("Forthcoming"));
1572 }
1573 if ($status == self::STATUS_DRAFT) {
1574 $statusType = 'status0';
1575 }
1576 if ($status == self::STATUS_VALIDATED) {
1577 $statusType = 'status1';
1578 }
1579 if ($status == self::STATUS_CANCELED) {
1580 $statusType = 'status9';
1581 }
1582 if ($status == self::STATUS_REFUSED) {
1583 $statusType = 'status9';
1584 }
1585
1586 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode, '', $params);
1587 }
1588
1589
1598 public function selectStatutCP($selected = 0, $htmlname = 'select_statut', $morecss = 'minwidth125')
1599 {
1600 global $langs;
1601
1602 // List of status label
1603 $name = array('DraftCP', 'ToReviewCP', 'ApprovedCP', 'CancelCP', 'RefuseCP');
1604 $nb = count($name) + 1;
1605
1606 // Select HTML
1607 $out = '<select name="'.$htmlname.'" id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">'."\n";
1608 $out .= '<option value="-1">&nbsp;</option>'."\n";
1609
1610 // Loop on status
1611 for ($i = 1; $i < $nb; $i++) {
1612 if ($i == $selected) {
1613 $out .= '<option value="'.$i.'" selected>'.$langs->trans($name[$i - 1]).'</option>'."\n";
1614 } else {
1615 $out .= '<option value="'.$i.'">'.$langs->trans($name[$i - 1]).'</option>'."\n";
1616 }
1617 }
1618
1619 $out .= "</select>\n";
1620
1621 $showempty = 0;
1622 $out .= ajax_combobox($htmlname, array(), 0, 0, 'resolve', ($showempty < 0 ? (string) $showempty : '-1'), $morecss);
1623
1624 return $out;
1625 }
1626
1634 public function updateConfCP($name, $value)
1635 {
1636 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1637 $sql .= " value = '".$this->db->escape($value)."'";
1638 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1639
1640 dol_syslog(get_class($this).'::updateConfCP name='.$name, LOG_DEBUG);
1641 $result = $this->db->query($sql);
1642 if ($result) {
1643 return true;
1644 }
1645
1646 return false;
1647 }
1648
1657 public function getConfCP($name, $createifnotfound = '')
1658 {
1659 $sql = "SELECT value";
1660 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_config";
1661 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1662
1663 dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG);
1664 $result = $this->db->query($sql);
1665
1666 if ($result) {
1667 $obj = $this->db->fetch_object($result);
1668 // Return value
1669 if (empty($obj)) {
1670 if ($createifnotfound) {
1671 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)";
1672 $sql .= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
1673 $result = $this->db->query($sql);
1674 if ($result) {
1675 return $createifnotfound;
1676 } else {
1677 $this->error = $this->db->lasterror();
1678 return -2;
1679 }
1680 } else {
1681 return '';
1682 }
1683 } else {
1684 return $obj->value;
1685 }
1686 } else {
1687 // Erreur SQL
1688 $this->error = $this->db->lasterror();
1689 return -1;
1690 }
1691 }
1692
1701 public function updateSoldeCP($userID = 0, $nbHoliday = 0, $fk_type = 0)
1702 {
1703 global $user, $langs;
1704
1705 $error = 0;
1706
1707 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1708 $langs->load("holiday");
1709
1710 $decrease = getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH');
1711
1712 // Si mise à jour pour tout le monde en début de mois
1713 $now = dol_now();
1714
1715 // Get month of last update
1716 $stringInDBForLastUpdate = $this->getConfCP('lastUpdate', dol_print_date($now, '%Y%m%d%H%M%S')); // Example '20200101120000'
1717 // The lastUpdate config row is created empty (value NULL) at install, so getConfCP() returns an empty value
1718 // the first time. Treat an empty value as "start from now" instead of a very old date, otherwise the catch-up
1719 // loop below would credit every user with years of monthly accrual at once. Store it, because the loop is the
1720 // only other place that writes it: an empty value would stay empty and no month would ever be credited.
1721 if (empty($stringInDBForLastUpdate)) {
1722 $stringInDBForLastUpdate = dol_print_date($now, '%Y%m%d%H%M%S');
1723
1724 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1725 $sql .= " value = '".$this->db->escape($stringInDBForLastUpdate)."'";
1726 $sql .= " WHERE name = 'lastUpdate'";
1727 $result = $this->db->query($sql);
1728 if (!$result) {
1729 $this->error = $this->db->lasterror();
1730 return -1;
1731 }
1732 }
1733 // Protection when $lastUpdate has a not valid value
1734 if ($stringInDBForLastUpdate < '20000101000000') {
1735 $stringInDBForLastUpdate = '20000101000000';
1736 }
1737 $lastUpdate = dol_stringtotime($stringInDBForLastUpdate);
1738 //print 'lastUpdate:'.$lastUpdate;exit;
1739
1740 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1741 $yearMonthNow = dol_print_date($now, '%Y%m');
1742 //print 'yearMonthLastUpdate='.$yearMonthLastUpdate.' yearMonthNow='.$yearMonthNow;
1743
1744 // If month date is not same than the one of last update (the one we saved in database), then we update the timestamp and balance of each open user,
1745 // catching up to the current month if a gap is detected
1746 while ($yearMonthLastUpdate < $yearMonthNow) {
1747 $this->db->begin();
1748
1749 $year = dol_print_date($lastUpdate, '%Y');
1750 $month = dol_print_date($lastUpdate, '%m');
1751
1752 $users = $this->fetchUsers(false, false, ' AND u.statut > 0');
1753 $nbUser = count($users);
1754
1755 $typeleaves = $this->getTypes(1, 1);
1756
1757 // Update each user counter
1758 foreach ($users as $userCounter) {
1759 $nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newbymonth']) ? $typeleaves[$userCounter['type']]['newbymonth'] : 0);
1760 if (empty($nbDaysToAdd)) {
1761 continue;
1762 }
1763
1764 dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG);
1765
1766 $nowHoliday = (float) $userCounter['nb_holiday'];
1767 $newSolde = $nowHoliday + $nbDaysToAdd;
1768
1769 // We add a log for each user when its balance gets increased
1770 $this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidayMonthlyCredit'), $newSolde, $userCounter['type']);
1771
1772 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1773
1774 if ($result < 0) {
1775 $this->db->rollback();
1776 return -1;
1777 }
1778
1779 if (empty($decrease)) {
1780 continue;
1781 }
1782
1783 // We fetch a user's holiday in the current month and then calculate the number of days to deduct if he has at least one registered
1784 $filter = " AND cp.statut = ".((int) self::STATUS_APPROVED);
1785 $filter .= " AND cp.date_fin >= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-01')))."'";
1786 $filter .= " AND cp.date_debut <= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-t')))."'";
1787 $filter .= " AND cp.fk_type = ".((int) $userCounter['type']);
1788 $this->fetchByUser($userCounter['id'], '', $filter);
1789
1790 if (empty($this->holiday)) {
1791 continue;
1792 }
1793
1794 $startOfMonth = dol_mktime(0, 0, 0, (int) $month, 1, (int) $year, 1);
1795 $endOfMonth = dol_mktime(0, 0, 0, (int) $month, (int) dol_print_date($lastUpdate, 't'), (int) $year, 1);
1796
1797 foreach ($this->holiday as $obj) {
1798 $startDate = $obj['date_debut_gmt'];
1799 $endDate = $obj['date_fin_gmt'];
1800
1801 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1802 $startDate = $startOfMonth;
1803 }
1804
1805 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1806 $endDate = $endOfMonth;
1807 }
1808
1809 $nbDaysToDeduct = (float) num_open_day($startDate, $endDate, 0, 1, $obj['halfday']);
1810
1811 if ($nbDaysToDeduct <= 0) {
1812 continue;
1813 }
1814
1815 $newSolde -= $nbDaysToDeduct;
1816
1817 // We add a log for each user when its balance gets decreased
1818 $this->addLogCP($user->id, $userCounter['rowid'], $obj['ref'].' - '.$langs->trans('HolidayConsumption'), $newSolde, $userCounter['type']);
1819
1820 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1821
1822 if ($result < 0) {
1823 $this->db->rollback();
1824 return -1;
1825 }
1826 }
1827 }
1828
1829 //updating the date of the last monthly balance update
1830 $newMonth = dol_get_next_month((int) dol_print_date($lastUpdate, '%m'), (int) dol_print_date($lastUpdate, '%Y'));
1831 $lastUpdate = dol_mktime(0, 0, 0, (int) $newMonth['month'], 1, (int) $newMonth['year']);
1832
1833 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1834 $sql .= " value = '".$this->db->escape(dol_print_date($lastUpdate, '%Y%m%d%H%M%S'))."'";
1835 $sql .= " WHERE name = 'lastUpdate'";
1836 $result = $this->db->query($sql);
1837
1838 if (!$result) {
1839 $this->db->rollback();
1840 return -1;
1841 }
1842
1843 $this->db->commit();
1844
1845 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1846 }
1847
1848 if (!$error) {
1849 return 1;
1850 } else {
1851 return 0;
1852 }
1853 } else {
1854 // Mise à jour pour un utilisateur
1855 $nbHoliday = price2num($nbHoliday, 5);
1856
1857 $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
1858 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1859 $resql = $this->db->query($sql);
1860 if ($resql) {
1861 $num = $this->db->num_rows($resql);
1862
1863 if ($num > 0) {
1864 // Update for user
1865 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1866 $sql .= " nb_holiday = ".((float) $nbHoliday);
1867 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1868 $result = $this->db->query($sql);
1869 if (!$result) {
1870 $error++;
1871 $this->errors[] = $this->db->lasterror();
1872 }
1873 } else {
1874 // Insert for user
1875 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1876 $sql .= ((float) $nbHoliday);
1877 $sql .= ", ".(int) $userID.", ".(int) $fk_type.")";
1878 $result = $this->db->query($sql);
1879 if (!$result) {
1880 $error++;
1881 $this->errors[] = $this->db->lasterror();
1882 }
1883 }
1884 } else {
1885 $this->errors[] = $this->db->lasterror();
1886 $error++;
1887 }
1888
1889 if (!$error) {
1890 return 1;
1891 } else {
1892 return -1;
1893 }
1894 }
1895 }
1896
1904 public function createCPusers($single = false, $userid = 0)
1905 {
1906 // do we have to add balance for all users ?
1907 if (!$single) {
1908 dol_syslog(get_class($this).'::createCPusers');
1909 $arrayofusers = $this->fetchUsers(false, true);
1910
1911 foreach ($arrayofusers as $users) {
1912 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1913 $sql .= " (fk_user, nb_holiday)";
1914 $sql .= " VALUES (".((int) $users['rowid'])."', '0')";
1915
1916 $resql = $this->db->query($sql);
1917 if (!$resql) {
1918 dol_print_error($this->db);
1919 }
1920 }
1921 } else {
1922 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1923 $sql .= " (fk_user, nb_holiday)";
1924 $sql .= " VALUES (".((int) $userid)."', '0')";
1925
1926 $resql = $this->db->query($sql);
1927 if (!$resql) {
1928 dol_print_error($this->db);
1929 }
1930 }
1931 }
1932
1940 public function getCPforUser($user_id, $fk_type = 0)
1941 {
1942 $sql = "SELECT nb_holiday";
1943 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users";
1944 $sql .= " WHERE fk_user = ".(int) $user_id;
1945 if ($fk_type > 0) {
1946 $sql .= " AND fk_type = ".(int) $fk_type;
1947 }
1948
1949 dol_syslog(get_class($this).'::getCPforUser user_id='.$user_id.' type_id='.$fk_type, LOG_DEBUG);
1950 $result = $this->db->query($sql);
1951 if ($result) {
1952 $obj = $this->db->fetch_object($result);
1953 //return number_format($obj->nb_holiday,2);
1954 if ($obj) {
1955 return $obj->nb_holiday;
1956 } else {
1957 return null;
1958 }
1959 } else {
1960 return null;
1961 }
1962 }
1963
1972 public function fetchUsers($stringlist = true, $type = true, $filters = '')
1973 {
1974 global $conf;
1975
1976 dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
1977
1978 if ($stringlist) {
1979 if ($type) {
1980 // If user of Dolibarr
1981 $sql = "SELECT";
1982 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1983 $sql .= " DISTINCT";
1984 }
1985 $sql .= " u.rowid";
1986 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
1987
1988 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1989 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1990 $sql .= " WHERE ((ug.fk_user = u.rowid";
1991 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
1992 $sql .= " OR u.entity = 0)"; // Show always superadmin
1993 } else {
1994 $sql .= " WHERE u.entity IN (".getEntity('user').")";
1995 }
1996 $sql .= " AND u.statut > 0";
1997 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
1998 if ($filters) {
1999 $sql .= $filters;
2000 }
2001
2002 $resql = $this->db->query($sql);
2003
2004 // Si pas d'erreur SQL
2005 if ($resql) {
2006 $i = 0;
2007 $num = $this->db->num_rows($resql);
2008 $stringlist = '';
2009
2010 // Boucles du listage des utilisateurs
2011 while ($i < $num) {
2012 $obj = $this->db->fetch_object($resql);
2013
2014 if ($i == 0) {
2015 $stringlist .= $obj->rowid;
2016 } else {
2017 $stringlist .= ', '.$obj->rowid;
2018 }
2019
2020 $i++;
2021 }
2022 // Retoune le tableau des utilisateurs
2023 return $stringlist;
2024 } else {
2025 // Erreur SQL
2026 $this->error = "Error ".$this->db->lasterror();
2027 return -1;
2028 }
2029 } else {
2030 // We want only list of vacation balance for user ids
2031 $sql = "SELECT DISTINCT cpu.fk_user";
2032 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
2033 $sql .= " WHERE cpu.fk_user = u.rowid";
2034 if ($filters) {
2035 $sql .= $filters;
2036 }
2037
2038 $resql = $this->db->query($sql);
2039
2040 // Si pas d'erreur SQL
2041 if ($resql) {
2042 $i = 0;
2043 $num = $this->db->num_rows($resql);
2044 $stringlist = '';
2045
2046 // Boucles du listage des utilisateurs
2047 while ($i < $num) {
2048 $obj = $this->db->fetch_object($resql);
2049
2050 if ($i == 0) {
2051 $stringlist .= $obj->fk_user;
2052 } else {
2053 $stringlist .= ', '.$obj->fk_user;
2054 }
2055
2056 $i++;
2057 }
2058 // Retoune le tableau des utilisateurs
2059 return $stringlist;
2060 } else {
2061 // Erreur SQL
2062 $this->error = "Error ".$this->db->lasterror();
2063 return -1;
2064 }
2065 }
2066 } else {
2067 // Si faux donc return array
2068 // List for Dolibarr users
2069 if ($type) {
2070 // If we need users of Dolibarr
2071 $sql = "SELECT";
2072 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2073 $sql .= " DISTINCT";
2074 }
2075 $sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut as status, u.fk_user";
2076 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
2077
2078 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2079 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
2080 $sql .= " WHERE ((ug.fk_user = u.rowid";
2081 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
2082 $sql .= " OR u.entity = 0)"; // Show always superadmin
2083 } else {
2084 $sql .= " WHERE u.entity IN (".getEntity('user').")";
2085 }
2086
2087 $sql .= " AND u.statut > 0";
2088 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
2089 if ($filters) {
2090 $sql .= $filters;
2091 }
2092
2093 $resql = $this->db->query($sql);
2094
2095 // Si pas d'erreur SQL
2096 if ($resql) {
2097 $i = 0;
2098 $tab_result = $this->holiday;
2099 $num = $this->db->num_rows($resql);
2100
2101 // Boucles du listage des utilisateurs
2102 while ($i < $num) {
2103 $obj = $this->db->fetch_object($resql);
2104
2105 $tab_result[$i]['rowid'] = (int) $obj->rowid; // rowid of user
2106 $tab_result[$i]['id'] = (int) $obj->rowid; // id of user
2107 $tab_result[$i]['name'] = $obj->lastname; // deprecated
2108 $tab_result[$i]['lastname'] = $obj->lastname;
2109 $tab_result[$i]['firstname'] = $obj->firstname;
2110 $tab_result[$i]['gender'] = $obj->gender;
2111 $tab_result[$i]['status'] = (int) $obj->status;
2112 $tab_result[$i]['employee'] = (int) $obj->employee;
2113 $tab_result[$i]['photo'] = $obj->photo;
2114 $tab_result[$i]['fk_user'] = (int) $obj->fk_user; // rowid of manager
2115 //$tab_result[$i]['type'] = $obj->type;
2116 //$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
2117
2118 $i++;
2119 }
2120 // Retoune le tableau des utilisateurs
2121 return $tab_result;
2122 } else {
2123 // Erreur SQL
2124 $this->errors[] = "Error ".$this->db->lasterror();
2125 return -1;
2126 }
2127 } else {
2128 // List of vacation balance users
2129 $sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut as status, u.fk_user";
2130 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
2131 $sql .= " WHERE cpu.fk_user = u.rowid";
2132 if ($filters) {
2133 $sql .= $filters;
2134 }
2135
2136 $resql = $this->db->query($sql);
2137
2138 // Si pas d'erreur SQL
2139 if ($resql) {
2140 $i = 0;
2141 $tab_result = $this->holiday;
2142 $num = $this->db->num_rows($resql);
2143
2144 // Boucles du listage des utilisateurs
2145 while ($i < $num) {
2146 $obj = $this->db->fetch_object($resql);
2147
2148 $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
2149 $tab_result[$i]['id'] = $obj->rowid; // id of user
2150 $tab_result[$i]['name'] = $obj->lastname; // deprecated
2151 $tab_result[$i]['lastname'] = $obj->lastname;
2152 $tab_result[$i]['firstname'] = $obj->firstname;
2153 $tab_result[$i]['gender'] = $obj->gender;
2154 $tab_result[$i]['status'] = $obj->status;
2155 $tab_result[$i]['employee'] = $obj->employee;
2156 $tab_result[$i]['photo'] = $obj->photo;
2157 $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
2158
2159 $tab_result[$i]['type'] = $obj->fk_type;
2160 $tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
2161
2162 $i++;
2163 }
2164 // Retoune le tableau des utilisateurs
2165 return $tab_result;
2166 } else {
2167 // Erreur SQL
2168 $this->error = "Error ".$this->db->lasterror();
2169 return -1;
2170 }
2171 }
2172 }
2173 }
2174
2175
2176 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2184 {
2185 // phpcs:enable
2186 $users_validator = array();
2187
2188 $sql = "SELECT DISTINCT ur.fk_user";
2189 $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
2190 $sql .= " WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve';
2191 $sql .= "UNION";
2192 $sql .= " SELECT DISTINCT ugu.fk_user";
2193 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
2194 $sql .= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve';
2195 //print $sql;
2196
2197 dol_syslog(get_class($this)."::fetch_users_approver_holiday sql=".$sql);
2198 $result = $this->db->query($sql);
2199 if ($result) {
2200 $num_rows = $this->db->num_rows($result);
2201 $i = 0;
2202 while ($i < $num_rows) {
2203 $objp = $this->db->fetch_object($result);
2204 array_push($users_validator, $objp->fk_user);
2205 $i++;
2206 }
2207 return $users_validator;
2208 } else {
2209 $this->error = $this->db->lasterror();
2210 dol_syslog(get_class($this)."::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2211 return -1;
2212 }
2213 }
2214
2215
2221 public function countActiveUsers()
2222 {
2223 $sql = "SELECT count(u.rowid) as compteur";
2224 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
2225 $sql .= " WHERE u.statut > 0";
2226
2227 $result = $this->db->query($sql);
2228 $object = $this->db->fetch_object($result);
2229
2230 return $object->compteur;
2231 }
2238 {
2239 $sql = "SELECT count(u.rowid) as compteur";
2240 $sql .= " FROM ".MAIN_DB_PREFIX."user as u LEFT JOIN ".MAIN_DB_PREFIX."holiday_users hu ON (hu.fk_user=u.rowid)";
2241 $sql .= " WHERE u.statut > 0 AND hu.fk_user IS NULL";
2242
2243 $result = $this->db->query($sql);
2244 $object = $this->db->fetch_object($result);
2245
2246 return $object->compteur;
2247 }
2248
2256 public function verifNbUsers($userDolibarrWithoutCP, $userCP)
2257 {
2258 if (empty($userCP)) {
2259 $userCP = 0;
2260 }
2261 dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
2262 return 1;
2263 }
2264
2265
2276 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2277 {
2278 global $conf, $langs;
2279
2280 $error = 0;
2281
2282 $prev_solde = price2num((float) $this->getCPforUser($fk_user_update, $fk_type), 5);
2283 $new_solde = price2num($new_solde, 5);
2284 //print "$prev_solde == $new_solde";
2285
2286 if ($prev_solde == $new_solde) {
2287 return 0;
2288 }
2289
2290 $this->db->begin();
2291
2292 // Insert request
2293 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
2294 $sql .= "date_action,";
2295 $sql .= "fk_user_action,";
2296 $sql .= "fk_user_update,";
2297 $sql .= "type_action,";
2298 $sql .= "prev_solde,";
2299 $sql .= "new_solde,";
2300 $sql .= "fk_type";
2301 $sql .= ") VALUES (";
2302 $sql .= " '".$this->db->idate(dol_now())."',";
2303 $sql .= " ".((int) $fk_user_action).",";
2304 $sql .= " ".((int) $fk_user_update).",";
2305 $sql .= " '".$this->db->escape($label)."',";
2306 $sql .= " ".((float) $prev_solde).",";
2307 $sql .= " ".((float) $new_solde).",";
2308 $sql .= " ".((int) $fk_type);
2309 $sql .= ")";
2310
2311 $resql = $this->db->query($sql);
2312 if (!$resql) {
2313 $error++;
2314 $this->errors[] = "Error ".$this->db->lasterror();
2315 }
2316
2317 if (!$error) {
2318 $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
2319 }
2320
2321 // Commit or rollback
2322 if ($error) {
2323 foreach ($this->errors as $errmsg) {
2324 dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
2325 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2326 }
2327 $this->db->rollback();
2328 return -1 * $error;
2329 } else {
2330 $this->db->commit();
2331 return $this->optRowid;
2332 }
2333 }
2334
2342 public function fetchLog($sqlorder, $sqlwhere)
2343 {
2344 $sql = "SELECT";
2345 $sql .= " cpl.rowid,";
2346 $sql .= " cpl.date_action,";
2347 $sql .= " cpl.fk_user_action,";
2348 $sql .= " cpl.fk_user_update,";
2349 $sql .= " cpl.type_action,";
2350 $sql .= " cpl.prev_solde,";
2351 $sql .= " cpl.new_solde,";
2352 $sql .= " cpl.fk_type";
2353 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
2354 $sql .= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
2355
2356 // Filter
2357 if (!empty($sqlwhere)) {
2358 $sql .= " ".$sqlwhere;
2359 }
2360
2361 // Order
2362 if (!empty($sqlorder)) {
2363 $sql .= " ".$sqlorder;
2364 }
2365
2366 dol_syslog(get_class($this)."::fetchLog", LOG_DEBUG);
2367 $resql = $this->db->query($sql);
2368
2369 // If no error SQL
2370 if ($resql) {
2371 $i = 0;
2372 $tab_result = $this->logs;
2373 $num = $this->db->num_rows($resql);
2374
2375 // If no record
2376 if (!$num) {
2377 return 2;
2378 }
2379
2380 // Loop on result to fill the array
2381 while ($i < $num) {
2382 $obj = $this->db->fetch_object($resql);
2383
2384 $tab_result[$i]['rowid'] = $obj->rowid;
2385 $tab_result[$i]['id'] = $obj->rowid;
2386 $tab_result[$i]['date_action'] = $obj->date_action;
2387 $tab_result[$i]['fk_user_action'] = $obj->fk_user_action;
2388 $tab_result[$i]['fk_user_update'] = $obj->fk_user_update;
2389 $tab_result[$i]['type_action'] = $obj->type_action;
2390 $tab_result[$i]['prev_solde'] = $obj->prev_solde;
2391 $tab_result[$i]['new_solde'] = $obj->new_solde;
2392 $tab_result[$i]['fk_type'] = $obj->fk_type;
2393
2394 $i++;
2395 }
2396 // Retourne 1 et ajoute le tableau à la variable
2397 $this->logs = $tab_result;
2398 return 1;
2399 } else {
2400 // Erreur SQL
2401 $this->error = "Error ".$this->db->lasterror();
2402 return -1;
2403 }
2404 }
2405
2406
2414 public function getTypes($active = -1, $affect = -1)
2415 {
2416 global $mysoc;
2417
2418 $sql = "SELECT rowid, code, label, affect, delay, newbymonth";
2419 $sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types";
2420 $sql .= " WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).')';
2421 $sql .= " AND entity IN (0, ".getEntity('c_holiday_types').")"; // Need entity 0 (holiday types common to all countries= + current entity).
2422 if ($active >= 0) {
2423 $sql .= " AND active = ".((int) $active);
2424 }
2425 if ($affect >= 0) {
2426 $sql .= " AND affect = ".((int) $affect);
2427 }
2428 $sql .= " ORDER BY sortorder";
2429
2430 $result = $this->db->query($sql);
2431 if ($result) {
2432 $num = $this->db->num_rows($result);
2433 if ($num) {
2434 $types = array();
2435 while ($obj = $this->db->fetch_object($result)) {
2436 $types[$obj->rowid] = array('id' => $obj->rowid, 'rowid' => $obj->rowid, 'code' => $obj->code, 'label' => $obj->label, 'affect' => $obj->affect, 'delay' => $obj->delay, 'newbymonth' => $obj->newbymonth);
2437 }
2438
2439 return $types;
2440 }
2441 } else {
2442 dol_print_error($this->db);
2443 }
2444
2445 return array();
2446 }
2447
2448
2455 public function info($id)
2456 {
2457 global $conf;
2458
2459 $sql = "SELECT f.rowid, f.statut as status,";
2460 $sql .= " f.date_create as datec,";
2461 $sql .= " f.tms as date_modification,";
2462 $sql .= " f.date_valid as datev,";
2463 $sql .= " f.date_approval as datea,";
2464 $sql .= " f.date_refuse as dater,";
2465 $sql .= " f.fk_user_create as fk_user_creation,";
2466 $sql .= " f.fk_user_modif as fk_user_modification,";
2467 $sql .= " f.fk_user_valid as fk_user_validation,";
2468 $sql .= " f.fk_user_approve as fk_user_approval_done,";
2469 $sql .= " f.fk_validator as fk_user_approval_expected,";
2470 $sql .= " f.fk_user_refuse as fk_user_refuse";
2471 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as f";
2472 $sql .= " WHERE f.rowid = ".((int) $id);
2473 $sql .= " AND f.entity = ".$conf->entity;
2474
2475 $resql = $this->db->query($sql);
2476 if ($resql) {
2477 if ($this->db->num_rows($resql)) {
2478 $obj = $this->db->fetch_object($resql);
2479
2480 $this->id = $obj->rowid;
2481
2482 $this->date_creation = $this->db->jdate($obj->datec);
2483 $this->date_modification = $this->db->jdate($obj->date_modification);
2484 $this->date_validation = $this->db->jdate($obj->datev);
2485 $this->date_approval = $this->db->jdate($obj->datea);
2486
2487 $this->user_creation_id = $obj->fk_user_creation;
2488 $this->user_validation_id = $obj->fk_user_validation;
2489 $this->user_modification_id = $obj->fk_user_modification;
2490
2491 if ($obj->status == Holiday::STATUS_APPROVED || $obj->status == Holiday::STATUS_CANCELED) {
2492 if ($obj->fk_user_approval_done) {
2493 $this->fk_user_approve = $obj->fk_user_approval_done;
2494 $this->user_approve_id = $obj->fk_user_approval_done;
2495 }
2496 }
2497 }
2498 $this->db->free($resql);
2499 } else {
2500 dol_print_error($this->db);
2501 }
2502 }
2503
2504
2512 public function initAsSpecimen()
2513 {
2514 global $user, $langs;
2515
2516 // Initialise parameters
2517 $this->id = 0;
2518 $this->specimen = 1;
2519
2520 $this->fk_user = $user->id;
2521 $this->description = 'SPECIMEN description';
2522 $this->date_debut = dol_now();
2523 $this->date_fin = dol_now() + (24 * 3600);
2524 $this->date_valid = dol_now();
2525 $this->fk_validator = $user->id;
2526 $this->halfday = 0;
2527 $this->fk_type = 1;
2529
2530 return 1;
2531 }
2532
2538 public function loadStateBoard()
2539 {
2540 global $user;
2541
2542 $this->nb = array();
2543
2544 $sql = "SELECT count(h.rowid) as nb";
2545 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2546 $sql .= " WHERE h.statut > 1";
2547 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2548 if (!$user->hasRight('holiday', 'readall')) {
2549 $userchildids = $user->getAllChildIds(1);
2550 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2551 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2552 }
2553
2554 $resql = $this->db->query($sql);
2555 if ($resql) {
2556 while ($obj = $this->db->fetch_object($resql)) {
2557 $this->nb["holidays"] = $obj->nb;
2558 }
2559 $this->db->free($resql);
2560 return 1;
2561 } else {
2562 dol_print_error($this->db);
2563 $this->error = $this->db->error();
2564 return -1;
2565 }
2566 }
2567
2568 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2575 public function load_board($user)
2576 {
2577 // phpcs:enable
2578 global $conf, $langs;
2579
2580 if ($user->socid) {
2581 return -1; // protection pour eviter appel par utilisateur externe
2582 }
2583
2584 $now = dol_now();
2585
2586 $sql = "SELECT h.rowid, h.date_debut";
2587 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2588 $sql .= " WHERE h.statut = 2";
2589 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2590 if (!$user->hasRight('holiday', 'read_all')) {
2591 $userchildids = $user->getAllChildIds(1);
2592 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2593 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2594 }
2595
2596 $resql = $this->db->query($sql);
2597 if ($resql) {
2598 $langs->load("members");
2599
2600 $response = new WorkboardResponse();
2601 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2602 $response->label = $langs->trans("HolidaysToApprove");
2603 $response->labelShort = $langs->trans("ToApprove");
2604 $response->url = DOL_URL_ROOT.'/holiday/list.php?search_status=2&amp;mainmenu=hrm&amp;leftmenu=holiday';
2605 $response->img = img_object('', "holiday");
2606
2607 while ($obj = $this->db->fetch_object($resql)) {
2608 $response->nbtodo++;
2609
2610 if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2611 $response->nbtodolate++;
2612 }
2613 }
2614
2615 return $response;
2616 } else {
2617 dol_print_error($this->db);
2618 $this->error = $this->db->error();
2619 return -1;
2620 }
2621 }
2629 public function getKanbanView($option = '', $arraydata = null)
2630 {
2631 global $langs;
2632
2633 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2634
2635 $return = '<div class="box-flex-item box-flex-grow-zero">';
2636 $return .= '<div class="info-box info-box-sm">';
2637 $return .= '<span class="info-box-icon bg-infobox-action">';
2638 $return .= img_picto('', $this->picto);
2639 $return .= '</span>';
2640 $return .= '<div class="info-box-content">';
2641 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().'</span>';
2642 if ($selected >= 0) {
2643 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2644 }
2645 if (property_exists($this, 'fk_type')) {
2646 $return .= '<br>';
2647 //$return .= '<span class="opacitymedium">'.$langs->trans("Type").'</span> : ';
2648 $return .= '<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata['labeltype']).'">'.dol_escape_htmltag($arraydata['labeltype']).'</div>';
2649 }
2650 if (property_exists($this, 'date_debut') && property_exists($this, 'date_fin')) {
2651 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_debut, 'day').'</span>';
2652 $return .= ' <span class="opacitymedium small">'.$langs->trans("To").'</span> ';
2653 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_fin, 'day').'</span>';
2654 if (!empty($arraydata['nbopenedday'])) {
2655 $return .= ' ('.$arraydata['nbopenedday'].')';
2656 }
2657 }
2658 if (method_exists($this, 'getLibStatut')) {
2659 $return .= '<div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2660 }
2661 $return .= '</div>';
2662 $return .= '</div>';
2663 $return .= '</div>';
2664 return $return;
2665 }
2666}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:475
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class of the module paid holiday.
getTypes($active=-1, $affect=-1)
Return array with list of types.
getNomUrl($withpicto=0, $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clickable name (with picto eventually)
verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday=0)
Check if a user is on holiday (partially or completely) into a period.
validate($user=null, $notrigger=0)
Validate leave request.
info($id)
Load information on object.
updateBalance()
Update balance of vacations and check table of users for holidays is complete.
updateConfCP($name, $value)
Met à jour une option du module Holiday Payés.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
fetch($id, $ref='')
Load object in memory from database.
addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
addLogCP
verifNbUsers($userDolibarrWithoutCP, $userCP)
Compare le nombre d'utilisateur actif de Dolibarr à celui des utilisateurs des congés payés.
verifDateHolidayForTimestamp($fk_user, $timestamp, $status='-1')
Check that a user is not on holiday for a particular timestamp.
approve($user=null, $notrigger=0)
Approve leave request.
getNextNumRef($objsoc)
Returns the reference to the following non used Order depending on the active numbering module define...
const STATUS_REFUSED
Refused.
getConfCP($name, $createifnotfound='')
Return value of a conf parameter for leave module TODO Move this into llx_const table.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Créer un congés payés dans la base de données.
selectStatutCP($selected=0, $htmlname='select_statut', $morecss='minwidth125')
Show select with list of leave status.
countActiveUsersWithoutCP()
Compte le nombre d'utilisateur actifs dans Dolibarr sans CP.
updateSoldeCP($userID=0, $nbHoliday=0, $fk_type=0)
Met à jour le timestamp de la dernière mise à jour du solde des CP.
update($user=null, $notrigger=0)
Update database.
getCPforUser($user_id, $fk_type=0)
Return the balance of annual leave of a user.
fetch_users_approver_holiday()
Return list of people with permission to validate leave requests.
__construct($db)
Constructor.
loadStateBoard()
Load this->nb for dashboard.
getLibStatut($mode=0)
Returns the label status.
createCPusers($single=false, $userid=0)
Create entries for each user at setup step.
fetchAll($order, $filter)
List all holidays of all users.
const STATUS_CANCELED
Canceled.
fetchLog($sqlorder, $sqlwhere)
List log of leaves.
countActiveUsers()
Compte le nombre d'utilisateur actifs dans Dolibarr.
fetchByUser($user_id, $order='', $filter='')
List holidays for a particular user or list of users.
const STATUS_APPROVED
Approved.
getTooltipContentArray($params)
getTooltipContentArray
fetchUsers($stringlist=true, $type=true, $filters='')
Get list of Users or list of vacation balance.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
LibStatut($status, $mode=0, $startdate='')
Returns the label of a status.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
dol_get_next_month($month, $year)
Return next month.
Definition date.lib.php:538
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code='')
Function to return number of working days (and text of units) between two dates (working days)
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:431
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.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
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...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79