28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'holiday';
44 public $table_element =
'holiday';
50 public $ismultientitymanaged = 0;
55 public $fk_element =
'fk_holiday';
60 public $picto =
'holiday';
67 public $date_create =
'';
74 public $date_debut =
'';
75 public $date_fin =
'';
76 public $date_debut_gmt =
'';
77 public $date_fin_gmt =
'';
89 public $date_valid =
'';
94 public $fk_user_valid;
99 public $date_approval;
104 public $fk_user_approve;
109 public $date_refuse =
'';
114 public $fk_user_refuse;
119 public $date_cancel =
'';
124 public $fk_user_cancel;
129 public $fk_user_create;
132 public $detail_refuse =
'';
139 public $holiday = array();
140 public $events = array();
141 public $logs = array();
143 public $optName =
'';
144 public $optValue =
'';
145 public $optRowid =
'';
189 global $langs, $conf;
190 $langs->load(
"order");
193 $conf->global->HOLIDAY_ADDON =
'mod_holiday_madonna';
200 $classname = $conf->global->HOLIDAY_ADDON;
203 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
204 foreach ($dirmodels as $reldir) {
208 $mybool |= @include_once $dir.$file;
211 if ($mybool ===
false) {
216 $obj =
new $classname();
217 $numref = $obj->getNextValue($objsoc, $this);
222 $this->error = $obj->error;
227 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_HOLIDAY_ADDON_NotDefined");
251 $this->db->rollback();
263 public function create($user, $notrigger = 0)
271 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
272 $this->error =
"ErrorBadParameterFkUser";
275 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
276 $this->error =
"ErrorBadParameterFkValidator";
279 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
280 $this->error =
"ErrorBadParameterFkType";
285 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday(";
288 $sql .=
"date_create,";
289 $sql .=
"description,";
290 $sql .=
"date_debut,";
294 $sql .=
"fk_validator,";
296 $sql .=
"fk_user_create,";
298 $sql .=
") VALUES (";
300 $sql .=
" ".((int) $this->fk_user).
",";
301 $sql .=
" '".$this->db->idate($now).
"',";
302 $sql .=
" '".$this->db->escape($this->
description).
"',";
303 $sql .=
" '".$this->db->idate($this->date_debut).
"',";
304 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
305 $sql .=
" ".((int) $this->halfday).
",";
307 $sql .=
" ".((int) $this->fk_validator).
",";
308 $sql .=
" ".((int) $this->fk_type).
",";
309 $sql .=
" ".((int) $user->id).
",";
310 $sql .=
" ".((int) $conf->entity);
315 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
316 $resql = $this->db->query($sql);
319 $this->errors[] =
"Error ".$this->db->lasterror();
323 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday");
327 $initialref =
'(PROV'.$this->id.
')';
328 if (!empty($this->
ref)) {
329 $initialref = $this->ref;
332 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"holiday SET ref='".$this->db->escape($initialref).
"' WHERE rowid=".((int) $this->
id);
333 if ($this->db->query($sql)) {
334 $this->
ref = $initialref;
343 if (!$error && !$notrigger) {
357 foreach ($this->errors as $errmsg) {
358 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
359 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
361 $this->db->rollback();
377 public function fetch($id, $ref =
'')
382 $sql .=
" cp.rowid,";
384 $sql .=
" cp.fk_user,";
385 $sql .=
" cp.date_create,";
386 $sql .=
" cp.description,";
387 $sql .=
" cp.date_debut,";
388 $sql .=
" cp.date_fin,";
389 $sql .=
" cp.halfday,";
390 $sql .=
" cp.statut,";
391 $sql .=
" cp.fk_validator,";
392 $sql .=
" cp.date_valid,";
393 $sql .=
" cp.fk_user_valid,";
394 $sql .=
" cp.date_approval,";
395 $sql .=
" cp.fk_user_approve,";
396 $sql .=
" cp.date_refuse,";
397 $sql .=
" cp.fk_user_refuse,";
398 $sql .=
" cp.date_cancel,";
399 $sql .=
" cp.fk_user_cancel,";
400 $sql .=
" cp.detail_refuse,";
401 $sql .=
" cp.note_private,";
402 $sql .=
" cp.note_public,";
403 $sql .=
" cp.fk_user_create,";
404 $sql .=
" cp.fk_type,";
405 $sql .=
" cp.entity";
406 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
408 $sql .=
" WHERE cp.rowid = ".((int) $id);
410 $sql .=
" WHERE cp.ref = '".$this->db->escape($ref).
"'";
413 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
414 $resql = $this->db->query($sql);
416 if ($this->db->num_rows($resql)) {
417 $obj = $this->db->fetch_object($resql);
419 $this->
id = $obj->rowid;
420 $this->
ref = ($obj->ref ? $obj->ref : $obj->rowid);
421 $this->fk_user = $obj->fk_user;
422 $this->date_create = $this->db->jdate($obj->date_create);
424 $this->date_debut = $this->db->jdate($obj->date_debut);
425 $this->date_fin = $this->db->jdate($obj->date_fin);
426 $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
427 $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
428 $this->halfday = $obj->halfday;
429 $this->
statut = $obj->statut;
430 $this->fk_validator = $obj->fk_validator;
431 $this->date_valid = $this->db->jdate($obj->date_valid);
432 $this->fk_user_valid = $obj->fk_user_valid;
433 $this->user_validation_id = $obj->fk_user_valid;
434 $this->date_approval = $this->db->jdate($obj->date_approval);
435 $this->fk_user_approve = $obj->fk_user_approve;
436 $this->date_refuse = $this->db->jdate($obj->date_refuse);
437 $this->fk_user_refuse = $obj->fk_user_refuse;
438 $this->date_cancel = $this->db->jdate($obj->date_cancel);
439 $this->fk_user_cancel = $obj->fk_user_cancel;
440 $this->detail_refuse = $obj->detail_refuse;
441 $this->note_private = $obj->note_private;
442 $this->note_public = $obj->note_public;
443 $this->fk_user_create = $obj->fk_user_create;
444 $this->fk_type = $obj->fk_type;
445 $this->entity = $obj->entity;
453 $this->db->free($resql);
457 $this->error =
"Error ".$this->db->lasterror();
472 global $langs, $conf;
475 $sql .=
" cp.rowid,";
478 $sql .=
" cp.fk_user,";
479 $sql .=
" cp.fk_type,";
480 $sql .=
" cp.date_create,";
481 $sql .=
" cp.description,";
482 $sql .=
" cp.date_debut,";
483 $sql .=
" cp.date_fin,";
484 $sql .=
" cp.halfday,";
485 $sql .=
" cp.statut,";
486 $sql .=
" cp.fk_validator,";
487 $sql .=
" cp.date_valid,";
488 $sql .=
" cp.fk_user_valid,";
489 $sql .=
" cp.date_approval,";
490 $sql .=
" cp.fk_user_approve,";
491 $sql .=
" cp.date_refuse,";
492 $sql .=
" cp.fk_user_refuse,";
493 $sql .=
" cp.date_cancel,";
494 $sql .=
" cp.fk_user_cancel,";
495 $sql .=
" cp.detail_refuse,";
497 $sql .=
" uu.lastname as user_lastname,";
498 $sql .=
" uu.firstname as user_firstname,";
499 $sql .=
" uu.login as user_login,";
500 $sql .=
" uu.statut as user_statut,";
501 $sql .=
" uu.photo as user_photo,";
503 $sql .=
" ua.lastname as validator_lastname,";
504 $sql .=
" ua.firstname as validator_firstname,";
505 $sql .=
" ua.login as validator_login,";
506 $sql .=
" ua.statut as validator_statut,";
507 $sql .=
" ua.photo as validator_photo";
509 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
510 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
511 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
512 $sql .=
" AND cp.fk_user IN (".$this->db->sanitize($user_id).
")";
515 if (!empty($filter)) {
520 if (!empty($order)) {
524 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
525 $resql = $this->db->query($sql);
530 $tab_result = $this->holiday;
531 $num = $this->db->num_rows($resql);
540 $obj = $this->db->fetch_object($resql);
542 $tab_result[$i][
'rowid'] = $obj->rowid;
543 $tab_result[$i][
'id'] = $obj->rowid;
544 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
546 $tab_result[$i][
'fk_user'] = $obj->fk_user;
547 $tab_result[$i][
'fk_type'] = $obj->fk_type;
548 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
549 $tab_result[$i][
'description'] = $obj->description;
550 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
551 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
552 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
553 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
554 $tab_result[$i][
'halfday'] = $obj->halfday;
555 $tab_result[$i][
'statut'] = $obj->statut;
556 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
557 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
558 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
559 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
560 $tab_result[$i][
'fk_user_approve'] = $obj->fk_user_approve;
561 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
562 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
563 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
564 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
565 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
567 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
568 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
569 $tab_result[$i][
'user_login'] = $obj->user_login;
570 $tab_result[$i][
'user_statut'] = $obj->user_statut;
571 $tab_result[$i][
'user_photo'] = $obj->user_photo;
573 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
574 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
575 $tab_result[$i][
'validator_login'] = $obj->validator_login;
576 $tab_result[$i][
'validator_statut'] = $obj->validator_statut;
577 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
583 $this->holiday = $tab_result;
587 $this->error =
"Error ".$this->db->lasterror();
604 $sql .=
" cp.rowid,";
607 $sql .=
" cp.fk_user,";
608 $sql .=
" cp.fk_type,";
609 $sql .=
" cp.date_create,";
610 $sql .=
" cp.tms as date_update,";
611 $sql .=
" cp.description,";
612 $sql .=
" cp.date_debut,";
613 $sql .=
" cp.date_fin,";
614 $sql .=
" cp.halfday,";
615 $sql .=
" cp.statut,";
616 $sql .=
" cp.fk_validator,";
617 $sql .=
" cp.date_valid,";
618 $sql .=
" cp.fk_user_valid,";
619 $sql .=
" cp.date_approval,";
620 $sql .=
" cp.fk_user_approve,";
621 $sql .=
" cp.date_refuse,";
622 $sql .=
" cp.fk_user_refuse,";
623 $sql .=
" cp.date_cancel,";
624 $sql .=
" cp.fk_user_cancel,";
625 $sql .=
" cp.detail_refuse,";
627 $sql .=
" uu.lastname as user_lastname,";
628 $sql .=
" uu.firstname as user_firstname,";
629 $sql .=
" uu.login as user_login,";
630 $sql .=
" uu.statut as user_statut,";
631 $sql .=
" uu.photo as user_photo,";
633 $sql .=
" ua.lastname as validator_lastname,";
634 $sql .=
" ua.firstname as validator_firstname,";
635 $sql .=
" ua.login as validator_login,";
636 $sql .=
" ua.statut as validator_statut,";
637 $sql .=
" ua.photo as validator_photo";
639 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
640 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
641 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
644 if (!empty($filter)) {
649 if (!empty($order)) {
653 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
654 $resql = $this->db->query($sql);
659 $tab_result = $this->holiday;
660 $num = $this->db->num_rows($resql);
669 $obj = $this->db->fetch_object($resql);
671 $tab_result[$i][
'rowid'] = $obj->rowid;
672 $tab_result[$i][
'id'] = $obj->rowid;
673 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
675 $tab_result[$i][
'fk_user'] = $obj->fk_user;
676 $tab_result[$i][
'fk_type'] = $obj->fk_type;
677 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
678 $tab_result[$i][
'date_update'] = $this->db->jdate($obj->date_update);
679 $tab_result[$i][
'description'] = $obj->description;
680 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
681 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
682 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
683 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
684 $tab_result[$i][
'halfday'] = $obj->halfday;
685 $tab_result[$i][
'statut'] = $obj->statut;
686 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
687 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
688 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
689 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
690 $tab_result[$i][
'fk_user_approve'] = $obj->fk_user_approve;
691 $tab_result[$i][
'date_refuse'] = $obj->date_refuse;
692 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
693 $tab_result[$i][
'date_cancel'] = $obj->date_cancel;
694 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
695 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
697 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
698 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
699 $tab_result[$i][
'user_login'] = $obj->user_login;
700 $tab_result[$i][
'user_statut'] = $obj->user_statut;
701 $tab_result[$i][
'user_photo'] = $obj->user_photo;
703 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
704 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
705 $tab_result[$i][
'validator_login'] = $obj->validator_login;
706 $tab_result[$i][
'validator_statut'] = $obj->validator_statut;
707 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
712 $this->holiday = $tab_result;
716 $this->error =
"Error ".$this->db->lasterror();
729 public function validate($user =
null, $notrigger = 0)
731 global $conf, $langs;
732 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
735 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type);
737 if ($checkBalance > 0) {
738 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
741 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
747 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref) || $this->
ref == $this->
id)) {
755 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
756 $sql .=
" fk_user_valid = ".((int) $user->id).
",";
757 $sql .=
" date_valid = '".$this->db->idate(
dol_now()).
"',";
758 if (!empty($this->
statut) && is_numeric($this->
statut)) {
759 $sql .=
" statut = ".((int) $this->
statut).
",";
761 $this->error =
'Property status must be a numeric value';
764 $sql .=
" ref = '".$this->db->escape($num).
"'";
765 $sql .=
" WHERE rowid = ".((int) $this->
id);
769 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
770 $resql = $this->db->query($sql);
773 $this->errors[] =
"Error ".$this->db->lasterror();
779 $result = $this->
call_trigger(
'HOLIDAY_VALIDATE', $user);
788 $this->oldref = $this->ref;
791 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
793 $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) .
"'";
794 $sql .=
" WHERE filename LIKE '" . $this->db->escape($this->
ref) .
"%' AND filepath = 'holiday/" . $this->db->escape($this->
ref) .
"' and entity = " . ((int) $conf->entity);
795 $resql = $this->db->query($sql);
798 $this->error = $this->db->lasterror();
800 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'holiday/".$this->db->escape($this->newref).
"'";
801 $sql .=
" WHERE filepath = 'holiday/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
802 $resql = $this->db->query($sql);
805 $this->error = $this->db->lasterror();
811 $dirsource = $conf->holiday->multidir_output[$this->entity] .
'/' . $oldref;
812 $dirdest = $conf->holiday->multidir_output[$this->entity] .
'/' . $newref;
813 if (!$error && file_exists($dirsource)) {
814 dol_syslog(get_class($this) .
"::validate rename dir " . $dirsource .
" into " . $dirdest);
815 if (@rename($dirsource, $dirdest)) {
818 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^' . preg_quote($oldref,
'/'));
819 foreach ($listoffiles as $fileentry) {
820 $dirsource = $fileentry[
'name'];
821 $dirdest = preg_replace(
'/^' . preg_quote($oldref,
'/') .
'/', $newref, $dirsource);
822 $dirsource = $fileentry[
'path'] .
'/' . $dirsource;
823 $dirdest = $fileentry[
'path'] .
'/' . $dirdest;
824 @rename($dirsource, $dirdest);
834 foreach ($this->errors as $errmsg) {
835 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
836 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
838 $this->db->rollback();
854 public function approve($user =
null, $notrigger = 0)
856 global $conf, $langs;
859 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type);
861 if ($checkBalance > 0) {
862 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
865 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
871 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
873 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
875 if (!empty($this->date_debut)) {
876 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
880 if (!empty($this->date_fin)) {
881 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
885 $sql .=
" halfday = ".((int) $this->halfday).
",";
886 if (!empty($this->
statut) && is_numeric($this->
statut)) {
887 $sql .=
" statut = ".((int) $this->
statut).
",";
891 if (!empty($this->fk_validator)) {
892 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
896 if (!empty($this->date_valid)) {
897 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
899 $sql .=
" date_valid = NULL,";
901 if (!empty($this->fk_user_valid)) {
902 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
904 $sql .=
" fk_user_valid = NULL,";
906 if (!empty($this->date_approval)) {
907 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
909 $sql .=
" date_approval = NULL,";
911 if (!empty($this->fk_user_approve)) {
912 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
914 $sql .=
" fk_user_approve = NULL,";
916 if (!empty($this->date_refuse)) {
917 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
919 $sql .=
" date_refuse = NULL,";
921 if (!empty($this->fk_user_refuse)) {
922 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
924 $sql .=
" fk_user_refuse = NULL,";
926 if (!empty($this->date_cancel)) {
927 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
929 $sql .=
" date_cancel = NULL,";
931 if (!empty($this->fk_user_cancel)) {
932 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
934 $sql .=
" fk_user_cancel = NULL,";
936 if (!empty($this->detail_refuse)) {
937 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
939 $sql .=
" detail_refuse = NULL";
941 $sql .=
" WHERE rowid = ".((int) $this->
id);
945 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
946 $resql = $this->db->query($sql);
949 $this->errors[] =
"Error ".$this->db->lasterror();
955 $result = $this->
call_trigger(
'HOLIDAY_APPROVE', $user);
965 foreach ($this->errors as $errmsg) {
966 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
967 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
969 $this->db->rollback();
984 public function update($user =
null, $notrigger = 0)
986 global $conf, $langs;
989 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type);
991 if ($checkBalance > 0 && $this->
statut != self::STATUS_DRAFT) {
992 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
995 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1001 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
1003 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
1005 if (!empty($this->date_debut)) {
1006 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
1010 if (!empty($this->date_fin)) {
1011 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
1015 $sql .=
" halfday = ".$this->halfday.
",";
1016 if (!empty($this->
statut) && is_numeric($this->
statut)) {
1017 $sql .=
" statut = ".$this->statut.
",";
1021 if (!empty($this->fk_validator)) {
1022 $sql .=
" fk_validator = '".$this->db->escape($this->fk_validator).
"',";
1026 if (!empty($this->date_valid)) {
1027 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1029 $sql .=
" date_valid = NULL,";
1031 if (!empty($this->fk_user_valid)) {
1032 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
1034 $sql .=
" fk_user_valid = NULL,";
1036 if (!empty($this->date_approval)) {
1037 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
1039 $sql .=
" date_approval = NULL,";
1041 if (!empty($this->fk_user_approve)) {
1042 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
1044 $sql .=
" fk_user_approve = NULL,";
1046 if (!empty($this->date_refuse)) {
1047 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
1049 $sql .=
" date_refuse = NULL,";
1051 if (!empty($this->fk_user_refuse)) {
1052 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
1054 $sql .=
" fk_user_refuse = NULL,";
1056 if (!empty($this->date_cancel)) {
1057 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
1059 $sql .=
" date_cancel = NULL,";
1061 if (!empty($this->fk_user_cancel)) {
1062 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
1064 $sql .=
" fk_user_cancel = NULL,";
1066 if (!empty($this->detail_refuse)) {
1067 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1069 $sql .=
" detail_refuse = NULL";
1072 $sql .=
" WHERE rowid = ".((int) $this->
id);
1076 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1077 $resql = $this->db->query($sql);
1080 $this->errors[] =
"Error ".$this->db->lasterror();
1086 $result = $this->
call_trigger(
'HOLIDAY_MODIFY', $user);
1096 foreach ($this->errors as $errmsg) {
1097 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1098 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1100 $this->db->rollback();
1103 $this->db->commit();
1116 public function delete($user, $notrigger = 0)
1118 global $conf, $langs;
1121 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1122 $sql .=
" WHERE rowid=".((int) $this->
id);
1126 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1127 $resql = $this->db->query($sql);
1130 $this->errors[] =
"Error ".$this->db->lasterror();
1136 $result = $this->
call_trigger(
'HOLIDAY_DELETE', $user);
1146 foreach ($this->errors as $errmsg) {
1147 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1148 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1150 $this->db->rollback();
1153 $this->db->commit();
1175 foreach ($this->holiday as $infos_CP) {
1186 if ($halfday == 0) {
1187 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1190 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1193 } elseif ($halfday == -1) {
1195 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1196 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1200 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1201 if ($dateStart < $dateEnd) {
1204 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1208 } elseif ($halfday == 1) {
1210 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1211 if ($dateStart < $dateEnd) {
1214 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1218 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1219 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1223 } elseif ($halfday == 2) {
1225 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1226 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1230 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1231 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1236 dol_print_error(
'',
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1255 global $langs, $conf;
1257 $isavailablemorning =
true;
1258 $isavailableafternoon =
true;
1261 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut";
1262 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1263 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1264 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1265 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->db->idate($timestamp).
"'";
1266 if ($status !=
'-1') {
1267 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1270 $resql = $this->db->query($sql);
1272 $num_rows = $this->db->num_rows($resql);
1273 if ($num_rows > 0) {
1274 $arrayofrecord = array();
1276 while ($i < $num_rows) {
1277 $obj = $this->db->fetch_object($resql);
1280 $arrayofrecord[$obj->rowid] = array(
'date_start'=>$this->db->jdate($obj->date_start),
'date_end'=>$this->db->jdate($obj->date_end),
'halfday'=>$obj->halfday);
1285 $isavailablemorning =
true;
1286 foreach ($arrayofrecord as $record) {
1287 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1290 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1293 $isavailablemorning =
false;
1296 $isavailableafternoon =
true;
1297 foreach ($arrayofrecord as $record) {
1298 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1301 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1304 $isavailableafternoon =
false;
1312 $result = array(
'morning'=>$isavailablemorning,
'afternoon'=>$isavailableafternoon);
1313 if (!$isavailablemorning) {
1314 $result[
'morning_reason'] =
'leave_request';
1316 if (!$isavailableafternoon) {
1317 $result[
'afternoon_reason'] =
'leave_request';
1331 global $conf, $langs;
1333 $langs->load(
'holiday');
1334 $nofetch = !empty($params[
'nofetch']);
1337 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1338 if (isset($this->
statut)) {
1339 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1341 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1343 if (!$nofetch && !empty($this->fk_type)) {
1344 $typeleaves = $this->
getTypes(1, -1);
1345 $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']);
1346 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type") .
':</b> ' . (empty($labeltoshow) ? $langs->trans(
"TypeWasDisabledOrRemoved", $this->fk_type) : $labeltoshow);
1348 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1349 $listhalfday = array(
1350 'morning' => $langs->trans(
"Morning"),
1351 "afternoon" => $langs->trans(
"Afternoon")
1353 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ?
'afternoon' :
'morning';
1354 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ?
'morning' :
'afternoon';
1355 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateDebCP') .
'</b>: '.
dol_print_date($this->date_debut,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1356 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateFinCP') .
'</b>: '.
dol_print_date($this->date_fin,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1372 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1374 global $conf, $langs, $hookmanager;
1376 if (!empty($conf->dol_no_mouse_hover)) {
1383 'objecttype' => $this->element,
1386 $classfortooltip =
'classfortooltip';
1389 $classfortooltip =
'classforajaxtooltip';
1390 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1396 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1401 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1402 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1403 $add_save_lastsearch_values = 1;
1405 if ($add_save_lastsearch_values) {
1406 $url .=
'&save_lastsearch_values=1';
1411 if (empty($notooltip)) {
1413 $label = $langs->trans(
"ShowMyObject");
1414 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1416 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1417 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1419 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1422 $linkstart =
'<a href="'.$url.
'"';
1423 $linkstart .= $linkclose.
'>';
1426 $result .= $linkstart;
1429 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1431 if ($withpicto != 2) {
1432 $result .= $this->ref;
1434 $result .= $linkend;
1437 $hookmanager->initHooks(array($this->element .
'dao'));
1438 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1439 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1441 $result = $hookmanager->resPrint;
1443 $result .= $hookmanager->resPrint;
1469 public function LibStatut($status, $mode = 0, $startdate =
'')
1474 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1482 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1490 $statusType =
'status6';
1491 if (!empty($startdate) && $startdate >=
dol_now()) {
1492 $statusType =
'status4';
1493 $params = array(
'tooltip'=>$this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1495 if ($status == self::STATUS_DRAFT) {
1496 $statusType =
'status0';
1498 if ($status == self::STATUS_VALIDATED) {
1499 $statusType =
'status1';
1501 if ($status == self::STATUS_CANCELED) {
1502 $statusType =
'status9';
1504 if ($status == self::STATUS_REFUSED) {
1505 $statusType =
'status9';
1508 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1520 public function selectStatutCP($selected =
'', $htmlname =
'select_statut', $morecss =
'minwidth125')
1525 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1526 $nb = count($name) + 1;
1529 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1530 $out .=
'<option value="-1"> </option>'.
"\n";
1533 for ($i = 1; $i < $nb; $i++) {
1534 if ($i == $selected) {
1535 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1537 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1541 $out .=
'</select>'.
"\n";
1544 $out .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($showempty < 0 ? (
string) $showempty :
'-1'), $morecss);
1558 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1559 $sql .=
" value = '".$this->db->escape($value).
"'";
1560 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1562 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1563 $result = $this->db->query($sql);
1581 $sql =
"SELECT value";
1582 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1583 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1585 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1586 $result = $this->db->query($sql);
1589 $obj = $this->db->fetch_object($result);
1592 if ($createifnotfound) {
1593 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1594 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->db->escape($createifnotfound).
"')";
1595 $result = $this->db->query($sql);
1597 return $createifnotfound;
1599 $this->error = $this->db->lasterror();
1610 $this->error = $this->db->lasterror();
1625 global $user, $langs;
1629 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1630 $langs->load(
"holiday");
1635 $month = date(
'm', $now);
1639 $lastUpdate = $this->
getConfCP(
'lastUpdate', $newdateforlastupdate);
1640 $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
1644 if ($month != $monthLastUpdate) {
1647 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1648 $nbUser = count($users);
1650 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1651 $sql .=
" value = '".$this->db->escape($newdateforlastupdate).
"'";
1652 $sql .=
" WHERE name = 'lastUpdate'";
1653 $result = $this->db->query($sql);
1655 $typeleaves = $this->
getTypes(1, 1);
1658 foreach ($users as $userCounter) {
1659 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1660 if (empty($nbDaysToAdd)) {
1664 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1666 $nowHoliday = $userCounter[
'nb_holiday'];
1667 $newSolde = $nowHoliday + $nbDaysToAdd;
1670 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidaysMonthlyUpdate'), $newSolde, $userCounter[
'type']);
1672 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1681 $this->db->commit();
1684 $this->db->rollback();
1694 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1695 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1696 $resql = $this->db->query($sql);
1698 $num = $this->db->num_rows($resql);
1702 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1703 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1704 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1705 $result = $this->db->query($sql);
1708 $this->errors[] = $this->db->lasterror();
1712 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1713 $sql .= ((float) $nbHoliday);
1714 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1715 $result = $this->db->query($sql);
1718 $this->errors[] = $this->db->lasterror();
1722 $this->errors[] = $this->db->lasterror();
1745 dol_syslog(get_class($this).
'::createCPusers');
1746 $arrayofusers = $this->
fetchUsers(
false,
true);
1748 foreach ($arrayofusers as $users) {
1749 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1750 $sql .=
" (fk_user, nb_holiday)";
1751 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1753 $resql = $this->db->query($sql);
1759 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1760 $sql .=
" (fk_user, nb_holiday)";
1761 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1763 $resql = $this->db->query($sql);
1779 $sql =
"SELECT nb_holiday";
1780 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1781 $sql .=
" WHERE fk_user = ".(int) $user_id;
1783 $sql .=
" AND fk_type = ".(int) $fk_type;
1786 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1787 $result = $this->db->query($sql);
1789 $obj = $this->db->fetch_object($result);
1792 return $obj->nb_holiday;
1809 public function fetchUsers($stringlist =
true, $type =
true, $filters =
'')
1813 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1819 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1820 $sql .=
" DISTINCT";
1823 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1825 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1826 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1827 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1828 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1829 $sql .=
" OR u.entity = 0)";
1831 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1833 $sql .=
" AND u.statut > 0";
1834 $sql .=
" AND u.employee = 1";
1839 $resql = $this->db->query($sql);
1844 $num = $this->db->num_rows($resql);
1849 $obj = $this->db->fetch_object($resql);
1852 $stringlist .= $obj->rowid;
1854 $stringlist .=
', '.$obj->rowid;
1863 $this->error =
"Error ".$this->db->lasterror();
1868 $sql =
"SELECT DISTINCT cpu.fk_user";
1869 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1870 $sql .=
" WHERE cpu.fk_user = u.rowid";
1875 $resql = $this->db->query($sql);
1880 $num = $this->db->num_rows($resql);
1885 $obj = $this->db->fetch_object($resql);
1888 $stringlist .= $obj->fk_user;
1890 $stringlist .=
', '.$obj->fk_user;
1899 $this->error =
"Error ".$this->db->lasterror();
1909 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1910 $sql .=
" DISTINCT";
1912 $sql .=
" u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1913 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1915 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1916 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1917 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1918 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1919 $sql .=
" OR u.entity = 0)";
1921 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1924 $sql .=
" AND u.statut > 0";
1925 $sql .=
" AND u.employee = 1";
1930 $resql = $this->db->query($sql);
1935 $tab_result = $this->holiday;
1936 $num = $this->db->num_rows($resql);
1940 $obj = $this->db->fetch_object($resql);
1942 $tab_result[$i][
'rowid'] = $obj->rowid;
1943 $tab_result[$i][
'id'] = $obj->rowid;
1944 $tab_result[$i][
'name'] = $obj->lastname;
1945 $tab_result[$i][
'lastname'] = $obj->lastname;
1946 $tab_result[$i][
'firstname'] = $obj->firstname;
1947 $tab_result[$i][
'gender'] = $obj->gender;
1948 $tab_result[$i][
'status'] = $obj->statut;
1949 $tab_result[$i][
'employee'] = $obj->employee;
1950 $tab_result[$i][
'photo'] = $obj->photo;
1951 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1961 $this->errors[] =
"Error ".$this->db->lasterror();
1966 $sql =
"SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1967 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1968 $sql .=
" WHERE cpu.fk_user = u.rowid";
1973 $resql = $this->db->query($sql);
1978 $tab_result = $this->holiday;
1979 $num = $this->db->num_rows($resql);
1983 $obj = $this->db->fetch_object($resql);
1985 $tab_result[$i][
'rowid'] = $obj->rowid;
1986 $tab_result[$i][
'id'] = $obj->rowid;
1987 $tab_result[$i][
'name'] = $obj->lastname;
1988 $tab_result[$i][
'lastname'] = $obj->lastname;
1989 $tab_result[$i][
'firstname'] = $obj->firstname;
1990 $tab_result[$i][
'gender'] = $obj->gender;
1991 $tab_result[$i][
'status'] = $obj->statut;
1992 $tab_result[$i][
'employee'] = $obj->employee;
1993 $tab_result[$i][
'photo'] = $obj->photo;
1994 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1996 $tab_result[$i][
'type'] = $obj->fk_type;
1997 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
2005 $this->error =
"Error ".$this->db->lasterror();
2023 $users_validator = array();
2025 $sql =
"SELECT DISTINCT ur.fk_user";
2026 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2027 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2029 $sql .=
" SELECT DISTINCT ugu.fk_user";
2030 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2031 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2034 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
2035 $result = $this->db->query($sql);
2037 $num_rows = $this->db->num_rows($result);
2039 while ($i < $num_rows) {
2040 $objp = $this->db->fetch_object($result);
2041 array_push($users_validator, $objp->fk_user);
2044 return $users_validator;
2046 $this->error = $this->db->lasterror();
2047 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2060 $sql =
"SELECT count(u.rowid) as compteur";
2061 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2062 $sql .=
" WHERE u.statut > 0";
2064 $result = $this->db->query($sql);
2065 $objet = $this->db->fetch_object($result);
2067 return $objet->compteur;
2076 $sql =
"SELECT count(u.rowid) as compteur";
2077 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2078 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2080 $result = $this->db->query($sql);
2081 $objet = $this->db->fetch_object($result);
2083 return $objet->compteur;
2095 if (empty($userCP)) {
2098 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2113 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2115 global $conf, $langs;
2123 if ($prev_solde == $new_solde) {
2130 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2131 $sql .=
"date_action,";
2132 $sql .=
"fk_user_action,";
2133 $sql .=
"fk_user_update,";
2134 $sql .=
"type_action,";
2135 $sql .=
"prev_solde,";
2136 $sql .=
"new_solde,";
2138 $sql .=
") VALUES (";
2139 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2140 $sql .=
" ".((int) $fk_user_action).
",";
2141 $sql .=
" ".((int) $fk_user_update).
",";
2142 $sql .=
" '".$this->db->escape($label).
"',";
2143 $sql .=
" ".((float) $prev_solde).
",";
2144 $sql .=
" ".((float) $new_solde).
",";
2145 $sql .=
" ".((int) $fk_type);
2148 $resql = $this->db->query($sql);
2151 $this->errors[] =
"Error ".$this->db->lasterror();
2155 $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2160 foreach ($this->errors as $errmsg) {
2161 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2162 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2164 $this->db->rollback();
2167 $this->db->commit();
2168 return $this->optRowid;
2182 $sql .=
" cpl.rowid,";
2183 $sql .=
" cpl.date_action,";
2184 $sql .=
" cpl.fk_user_action,";
2185 $sql .=
" cpl.fk_user_update,";
2186 $sql .=
" cpl.type_action,";
2187 $sql .=
" cpl.prev_solde,";
2188 $sql .=
" cpl.new_solde,";
2189 $sql .=
" cpl.fk_type";
2190 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2191 $sql .=
" WHERE cpl.rowid > 0";
2194 if (!empty($filter)) {
2195 $sql .=
" ".$filter;
2199 if (!empty($order)) {
2203 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2204 $resql = $this->db->query($sql);
2209 $tab_result = $this->logs;
2210 $num = $this->db->num_rows($resql);
2219 $obj = $this->db->fetch_object($resql);
2221 $tab_result[$i][
'rowid'] = $obj->rowid;
2222 $tab_result[$i][
'id'] = $obj->rowid;
2223 $tab_result[$i][
'date_action'] = $obj->date_action;
2224 $tab_result[$i][
'fk_user_action'] = $obj->fk_user_action;
2225 $tab_result[$i][
'fk_user_update'] = $obj->fk_user_update;
2226 $tab_result[$i][
'type_action'] = $obj->type_action;
2227 $tab_result[$i][
'prev_solde'] = $obj->prev_solde;
2228 $tab_result[$i][
'new_solde'] = $obj->new_solde;
2229 $tab_result[$i][
'fk_type'] = $obj->fk_type;
2234 $this->logs = $tab_result;
2238 $this->error =
"Error ".$this->db->lasterror();
2255 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2256 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2257 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).
')';
2259 $sql .=
" AND active = ".((int) $active);
2262 $sql .=
" AND affect = ".((int) $affect);
2264 $sql .=
" ORDER BY sortorder";
2266 $result = $this->db->query($sql);
2268 $num = $this->db->num_rows($result);
2270 while ($obj = $this->db->fetch_object($result)) {
2271 $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);
2294 $sql =
"SELECT f.rowid, f.statut as status,";
2295 $sql .=
" f.date_create as datec,";
2296 $sql .=
" f.tms as date_modification,";
2297 $sql .=
" f.date_valid as datev,";
2298 $sql .=
" f.date_approval as datea,";
2299 $sql .=
" f.date_refuse as dater,";
2300 $sql .=
" f.fk_user_create as fk_user_creation,";
2301 $sql .=
" f.fk_user_modif as fk_user_modification,";
2302 $sql .=
" f.fk_user_valid as fk_user_validation,";
2303 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2304 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2305 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2306 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2307 $sql .=
" WHERE f.rowid = ".((int) $id);
2308 $sql .=
" AND f.entity = ".$conf->entity;
2310 $resql = $this->db->query($sql);
2312 if ($this->db->num_rows($resql)) {
2313 $obj = $this->db->fetch_object($resql);
2315 $this->
id = $obj->rowid;
2317 $this->date_creation = $this->db->jdate($obj->datec);
2318 $this->date_modification = $this->db->jdate($obj->date_modification);
2319 $this->date_validation = $this->db->jdate($obj->datev);
2320 $this->date_approval = $this->db->jdate($obj->datea);
2322 $this->user_creation_id = $obj->fk_user_creation;
2323 $this->user_validation_id = $obj->fk_user_valid;
2324 $this->user_modification_id = $obj->fk_user_modification;
2327 if ($obj->fk_user_approval_done) {
2328 $this->fk_user_approve = $obj->fk_user_approval_done;
2332 $this->db->free($resql);
2348 global $user, $langs;
2352 $this->specimen = 1;
2354 $this->fk_user = $user->id;
2356 $this->date_debut =
dol_now();
2357 $this->date_fin =
dol_now() + (24 * 3600);
2358 $this->date_valid =
dol_now();
2359 $this->fk_validator = $user->id;
2376 $this->nb = array();
2378 $sql =
"SELECT count(h.rowid) as nb";
2379 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2380 $sql .=
" WHERE h.statut > 1";
2381 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2382 if (!$user->hasRight(
'expensereport',
'readall')) {
2383 $userchildids = $user->getAllChildIds(1);
2384 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(join(
',', $userchildids)).
")";
2385 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(join(
',', $userchildids)).
"))";
2388 $resql = $this->db->query($sql);
2390 while ($obj = $this->db->fetch_object($resql)) {
2391 $this->nb[
"holidays"] = $obj->nb;
2393 $this->db->free($resql);
2397 $this->error = $this->db->error();
2412 global $conf, $langs;
2420 $sql =
"SELECT h.rowid, h.date_debut";
2421 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2422 $sql .=
" WHERE h.statut = 2";
2423 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2424 if (!$user->hasRight(
'expensereport',
'read_all')) {
2425 $userchildids = $user->getAllChildIds(1);
2426 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(join(
',', $userchildids)).
")";
2427 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(join(
',', $userchildids)).
"))";
2430 $resql = $this->db->query($sql);
2432 $langs->load(
"members");
2435 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2436 $response->label = $langs->trans(
"HolidaysToApprove");
2437 $response->labelShort = $langs->trans(
"ToApprove");
2438 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2441 while ($obj = $this->db->fetch_object($resql)) {
2442 $response->nbtodo++;
2444 if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2445 $response->nbtodolate++;
2452 $this->error = $this->db->error();
2467 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2469 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2470 $return .=
'<div class="info-box info-box-sm">';
2471 $return .=
'<span class="info-box-icon bg-infobox-action">';
2473 $return .=
'</span>';
2474 $return .=
'<div class="info-box-content">';
2475 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$arraydata[
'user']->getNomUrl(-1).
'</span>';
2476 if ($selected >= 0) {
2477 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2479 if (property_exists($this,
'fk_type')) {
2482 $return .=
'<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata[
'labeltype']).
'">'.
dol_escape_htmltag($arraydata[
'labeltype']).
'</div>';
2484 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2485 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_debut,
'day').
'</span>';
2486 $return .=
' <span class="opacitymedium small">'.$langs->trans(
"To").
'</span> ';
2487 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_fin,
'day').
'</span>';
2488 if (!empty($arraydata[
'nbopenedday'])) {
2489 $return .=
' ('.$arraydata[
'nbopenedday'].
')';
2492 if (method_exists($this,
'getLibStatut')) {
2493 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2495 $return .=
'</div>';
2496 $return .=
'</div>';
2497 $return .=
'</div>';
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
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...
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 clicable 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.
load_state_board()
Load this->nb for dashboard.
const STATUS_DRAFT
Draft status.
createCPusers($single=false, $userid='')
Create entries for each user at setup step.
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.
updateSoldeCP($userID='', $nbHoliday='', $fk_type='')
Met à jour le timestamp de la dernière mise à jour du solde des CP.
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.
selectStatutCP($selected='', $htmlname='select_statut', $morecss='minwidth125')
Show select with list of leave status.
create($user, $notrigger=0)
Créer un congés payés dans la base de données.
countActiveUsersWithoutCP()
Compte le nombre d'utilisateur actifs dans Dolibarr sans CP.
fetchLog($order, $filter)
Liste le log des congés payés.
update($user=null, $notrigger=0)
Update database.
getCPforUser($user_id, $fk_type=0)
Return balance of holiday for one user.
fetch_users_approver_holiday()
Return list of people with permission to validate leave requests.
__construct($db)
Constructor.
getLibStatut($mode=0)
Returns the label status.
fetchAll($order, $filter)
List all holidays of all users.
const STATUS_CANCELED
Canceled.
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 clicable link of object (with eventually picto)
LibStatut($status, $mode=0, $startdate='')
Returns the label of a status.
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($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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return 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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut