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();
1093 $result = $this->
call_trigger(
'HOLIDAY_MODIFY', $user);
1103 foreach ($this->errors as $errmsg) {
1104 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1105 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1107 $this->db->rollback();
1110 $this->db->commit();
1123 public function delete($user, $notrigger = 0)
1125 global $conf, $langs;
1128 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1129 $sql .=
" WHERE rowid=".((int) $this->
id);
1133 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1134 $resql = $this->db->query($sql);
1137 $this->errors[] =
"Error ".$this->db->lasterror();
1143 $result = $this->
call_trigger(
'HOLIDAY_DELETE', $user);
1153 foreach ($this->errors as $errmsg) {
1154 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1155 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1157 $this->db->rollback();
1160 $this->db->commit();
1182 foreach ($this->holiday as $infos_CP) {
1193 if ($halfday == 0) {
1194 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1197 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1200 } elseif ($halfday == -1) {
1202 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1203 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1207 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1208 if ($dateStart < $dateEnd) {
1211 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1215 } elseif ($halfday == 1) {
1217 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1218 if ($dateStart < $dateEnd) {
1221 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1225 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1226 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1230 } elseif ($halfday == 2) {
1232 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1233 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1237 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1238 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1243 dol_print_error(
'',
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1262 global $langs, $conf;
1264 $isavailablemorning =
true;
1265 $isavailableafternoon =
true;
1268 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut";
1269 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1270 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1271 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1272 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->db->idate($timestamp).
"'";
1273 if ($status !=
'-1') {
1274 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1277 $resql = $this->db->query($sql);
1279 $num_rows = $this->db->num_rows($resql);
1280 if ($num_rows > 0) {
1281 $arrayofrecord = array();
1283 while ($i < $num_rows) {
1284 $obj = $this->db->fetch_object($resql);
1287 $arrayofrecord[$obj->rowid] = array(
'date_start'=>$this->db->jdate($obj->date_start),
'date_end'=>$this->db->jdate($obj->date_end),
'halfday'=>$obj->halfday);
1292 $isavailablemorning =
true;
1293 foreach ($arrayofrecord as $record) {
1294 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1297 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1300 $isavailablemorning =
false;
1303 $isavailableafternoon =
true;
1304 foreach ($arrayofrecord as $record) {
1305 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1308 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1311 $isavailableafternoon =
false;
1319 $result = array(
'morning'=>$isavailablemorning,
'afternoon'=>$isavailableafternoon);
1320 if (!$isavailablemorning) {
1321 $result[
'morning_reason'] =
'leave_request';
1323 if (!$isavailableafternoon) {
1324 $result[
'afternoon_reason'] =
'leave_request';
1338 global $conf, $langs;
1340 $langs->load(
'holiday');
1341 $nofetch = !empty($params[
'nofetch']);
1344 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1345 if (isset($this->
statut)) {
1346 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1348 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1350 if (!$nofetch && !empty($this->fk_type)) {
1351 $typeleaves = $this->
getTypes(1, -1);
1352 $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']);
1353 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type") .
':</b> ' . (empty($labeltoshow) ? $langs->trans(
"TypeWasDisabledOrRemoved", $this->fk_type) : $labeltoshow);
1355 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1356 $listhalfday = array(
1357 'morning' => $langs->trans(
"Morning"),
1358 "afternoon" => $langs->trans(
"Afternoon")
1360 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ?
'afternoon' :
'morning';
1361 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ?
'morning' :
'afternoon';
1362 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateDebCP') .
'</b>: '.
dol_print_date($this->date_debut,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1363 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateFinCP') .
'</b>: '.
dol_print_date($this->date_fin,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1379 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1381 global $conf, $langs, $hookmanager;
1383 if (!empty($conf->dol_no_mouse_hover)) {
1390 'objecttype' => $this->element,
1393 $classfortooltip =
'classfortooltip';
1396 $classfortooltip =
'classforajaxtooltip';
1397 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1403 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1408 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1409 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1410 $add_save_lastsearch_values = 1;
1412 if ($add_save_lastsearch_values) {
1413 $url .=
'&save_lastsearch_values=1';
1418 if (empty($notooltip)) {
1420 $label = $langs->trans(
"ShowMyObject");
1421 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1423 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1424 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1426 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1429 $linkstart =
'<a href="'.$url.
'"';
1430 $linkstart .= $linkclose.
'>';
1433 $result .= $linkstart;
1436 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1438 if ($withpicto != 2) {
1439 $result .= $this->ref;
1441 $result .= $linkend;
1444 $hookmanager->initHooks(array($this->element .
'dao'));
1445 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1446 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1448 $result = $hookmanager->resPrint;
1450 $result .= $hookmanager->resPrint;
1476 public function LibStatut($status, $mode = 0, $startdate =
'')
1481 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1489 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1497 $statusType =
'status6';
1498 if (!empty($startdate) && $startdate >=
dol_now()) {
1499 $statusType =
'status4';
1500 $params = array(
'tooltip'=>$this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1502 if ($status == self::STATUS_DRAFT) {
1503 $statusType =
'status0';
1505 if ($status == self::STATUS_VALIDATED) {
1506 $statusType =
'status1';
1508 if ($status == self::STATUS_CANCELED) {
1509 $statusType =
'status9';
1511 if ($status == self::STATUS_REFUSED) {
1512 $statusType =
'status9';
1515 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1527 public function selectStatutCP($selected =
'', $htmlname =
'select_statut', $morecss =
'minwidth125')
1532 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1533 $nb = count($name) + 1;
1536 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1537 $out .=
'<option value="-1"> </option>'.
"\n";
1540 for ($i = 1; $i < $nb; $i++) {
1541 if ($i == $selected) {
1542 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1544 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1548 $out .=
'</select>'.
"\n";
1551 $out .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($showempty < 0 ? (
string) $showempty :
'-1'), $morecss);
1565 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1566 $sql .=
" value = '".$this->db->escape($value).
"'";
1567 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1569 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1570 $result = $this->db->query($sql);
1588 $sql =
"SELECT value";
1589 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1590 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1592 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1593 $result = $this->db->query($sql);
1596 $obj = $this->db->fetch_object($result);
1599 if ($createifnotfound) {
1600 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1601 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->db->escape($createifnotfound).
"')";
1602 $result = $this->db->query($sql);
1604 return $createifnotfound;
1606 $this->error = $this->db->lasterror();
1617 $this->error = $this->db->lasterror();
1632 global $user, $langs;
1636 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1637 $langs->load(
"holiday");
1642 $month = date(
'm', $now);
1646 $lastUpdate = $this->
getConfCP(
'lastUpdate', $newdateforlastupdate);
1647 $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
1651 if ($month != $monthLastUpdate) {
1654 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1655 $nbUser = count($users);
1657 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1658 $sql .=
" value = '".$this->db->escape($newdateforlastupdate).
"'";
1659 $sql .=
" WHERE name = 'lastUpdate'";
1660 $result = $this->db->query($sql);
1662 $typeleaves = $this->
getTypes(1, 1);
1665 foreach ($users as $userCounter) {
1666 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1667 if (empty($nbDaysToAdd)) {
1671 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1673 $nowHoliday = $userCounter[
'nb_holiday'];
1674 $newSolde = $nowHoliday + $nbDaysToAdd;
1677 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidaysMonthlyUpdate'), $newSolde, $userCounter[
'type']);
1679 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1688 $this->db->commit();
1691 $this->db->rollback();
1701 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1702 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1703 $resql = $this->db->query($sql);
1705 $num = $this->db->num_rows($resql);
1709 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1710 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1711 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1712 $result = $this->db->query($sql);
1715 $this->errors[] = $this->db->lasterror();
1719 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1720 $sql .= ((float) $nbHoliday);
1721 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1722 $result = $this->db->query($sql);
1725 $this->errors[] = $this->db->lasterror();
1729 $this->errors[] = $this->db->lasterror();
1752 dol_syslog(get_class($this).
'::createCPusers');
1753 $arrayofusers = $this->
fetchUsers(
false,
true);
1755 foreach ($arrayofusers as $users) {
1756 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1757 $sql .=
" (fk_user, nb_holiday)";
1758 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1760 $resql = $this->db->query($sql);
1766 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1767 $sql .=
" (fk_user, nb_holiday)";
1768 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1770 $resql = $this->db->query($sql);
1786 $sql =
"SELECT nb_holiday";
1787 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1788 $sql .=
" WHERE fk_user = ".(int) $user_id;
1790 $sql .=
" AND fk_type = ".(int) $fk_type;
1793 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1794 $result = $this->db->query($sql);
1796 $obj = $this->db->fetch_object($result);
1799 return $obj->nb_holiday;
1816 public function fetchUsers($stringlist =
true, $type =
true, $filters =
'')
1820 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1826 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1827 $sql .=
" DISTINCT";
1830 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1832 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1833 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1834 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1835 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1836 $sql .=
" OR u.entity = 0)";
1838 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1840 $sql .=
" AND u.statut > 0";
1841 $sql .=
" AND u.employee = 1";
1846 $resql = $this->db->query($sql);
1851 $num = $this->db->num_rows($resql);
1856 $obj = $this->db->fetch_object($resql);
1859 $stringlist .= $obj->rowid;
1861 $stringlist .=
', '.$obj->rowid;
1870 $this->error =
"Error ".$this->db->lasterror();
1875 $sql =
"SELECT DISTINCT cpu.fk_user";
1876 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1877 $sql .=
" WHERE cpu.fk_user = u.rowid";
1882 $resql = $this->db->query($sql);
1887 $num = $this->db->num_rows($resql);
1892 $obj = $this->db->fetch_object($resql);
1895 $stringlist .= $obj->fk_user;
1897 $stringlist .=
', '.$obj->fk_user;
1906 $this->error =
"Error ".$this->db->lasterror();
1916 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1917 $sql .=
" DISTINCT";
1919 $sql .=
" u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1920 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1922 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1923 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1924 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1925 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1926 $sql .=
" OR u.entity = 0)";
1928 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1931 $sql .=
" AND u.statut > 0";
1932 $sql .=
" AND u.employee = 1";
1937 $resql = $this->db->query($sql);
1942 $tab_result = $this->holiday;
1943 $num = $this->db->num_rows($resql);
1947 $obj = $this->db->fetch_object($resql);
1949 $tab_result[$i][
'rowid'] = $obj->rowid;
1950 $tab_result[$i][
'id'] = $obj->rowid;
1951 $tab_result[$i][
'name'] = $obj->lastname;
1952 $tab_result[$i][
'lastname'] = $obj->lastname;
1953 $tab_result[$i][
'firstname'] = $obj->firstname;
1954 $tab_result[$i][
'gender'] = $obj->gender;
1955 $tab_result[$i][
'status'] = $obj->statut;
1956 $tab_result[$i][
'employee'] = $obj->employee;
1957 $tab_result[$i][
'photo'] = $obj->photo;
1958 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1968 $this->errors[] =
"Error ".$this->db->lasterror();
1973 $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";
1974 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1975 $sql .=
" WHERE cpu.fk_user = u.rowid";
1980 $resql = $this->db->query($sql);
1985 $tab_result = $this->holiday;
1986 $num = $this->db->num_rows($resql);
1990 $obj = $this->db->fetch_object($resql);
1992 $tab_result[$i][
'rowid'] = $obj->rowid;
1993 $tab_result[$i][
'id'] = $obj->rowid;
1994 $tab_result[$i][
'name'] = $obj->lastname;
1995 $tab_result[$i][
'lastname'] = $obj->lastname;
1996 $tab_result[$i][
'firstname'] = $obj->firstname;
1997 $tab_result[$i][
'gender'] = $obj->gender;
1998 $tab_result[$i][
'status'] = $obj->statut;
1999 $tab_result[$i][
'employee'] = $obj->employee;
2000 $tab_result[$i][
'photo'] = $obj->photo;
2001 $tab_result[$i][
'fk_user'] = $obj->fk_user;
2003 $tab_result[$i][
'type'] = $obj->fk_type;
2004 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
2012 $this->error =
"Error ".$this->db->lasterror();
2030 $users_validator = array();
2032 $sql =
"SELECT DISTINCT ur.fk_user";
2033 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2034 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2036 $sql .=
" SELECT DISTINCT ugu.fk_user";
2037 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2038 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2041 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
2042 $result = $this->db->query($sql);
2044 $num_rows = $this->db->num_rows($result);
2046 while ($i < $num_rows) {
2047 $objp = $this->db->fetch_object($result);
2048 array_push($users_validator, $objp->fk_user);
2051 return $users_validator;
2053 $this->error = $this->db->lasterror();
2054 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2067 $sql =
"SELECT count(u.rowid) as compteur";
2068 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2069 $sql .=
" WHERE u.statut > 0";
2071 $result = $this->db->query($sql);
2072 $objet = $this->db->fetch_object($result);
2074 return $objet->compteur;
2083 $sql =
"SELECT count(u.rowid) as compteur";
2084 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2085 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2087 $result = $this->db->query($sql);
2088 $objet = $this->db->fetch_object($result);
2090 return $objet->compteur;
2102 if (empty($userCP)) {
2105 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2120 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2122 global $conf, $langs;
2130 if ($prev_solde == $new_solde) {
2137 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2138 $sql .=
"date_action,";
2139 $sql .=
"fk_user_action,";
2140 $sql .=
"fk_user_update,";
2141 $sql .=
"type_action,";
2142 $sql .=
"prev_solde,";
2143 $sql .=
"new_solde,";
2145 $sql .=
") VALUES (";
2146 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2147 $sql .=
" ".((int) $fk_user_action).
",";
2148 $sql .=
" ".((int) $fk_user_update).
",";
2149 $sql .=
" '".$this->db->escape($label).
"',";
2150 $sql .=
" ".((float) $prev_solde).
",";
2151 $sql .=
" ".((float) $new_solde).
",";
2152 $sql .=
" ".((int) $fk_type);
2155 $resql = $this->db->query($sql);
2158 $this->errors[] =
"Error ".$this->db->lasterror();
2162 $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2167 foreach ($this->errors as $errmsg) {
2168 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2169 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2171 $this->db->rollback();
2174 $this->db->commit();
2175 return $this->optRowid;
2189 $sql .=
" cpl.rowid,";
2190 $sql .=
" cpl.date_action,";
2191 $sql .=
" cpl.fk_user_action,";
2192 $sql .=
" cpl.fk_user_update,";
2193 $sql .=
" cpl.type_action,";
2194 $sql .=
" cpl.prev_solde,";
2195 $sql .=
" cpl.new_solde,";
2196 $sql .=
" cpl.fk_type";
2197 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2198 $sql .=
" WHERE cpl.rowid > 0";
2201 if (!empty($filter)) {
2202 $sql .=
" ".$filter;
2206 if (!empty($order)) {
2210 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2211 $resql = $this->db->query($sql);
2216 $tab_result = $this->logs;
2217 $num = $this->db->num_rows($resql);
2226 $obj = $this->db->fetch_object($resql);
2228 $tab_result[$i][
'rowid'] = $obj->rowid;
2229 $tab_result[$i][
'id'] = $obj->rowid;
2230 $tab_result[$i][
'date_action'] = $obj->date_action;
2231 $tab_result[$i][
'fk_user_action'] = $obj->fk_user_action;
2232 $tab_result[$i][
'fk_user_update'] = $obj->fk_user_update;
2233 $tab_result[$i][
'type_action'] = $obj->type_action;
2234 $tab_result[$i][
'prev_solde'] = $obj->prev_solde;
2235 $tab_result[$i][
'new_solde'] = $obj->new_solde;
2236 $tab_result[$i][
'fk_type'] = $obj->fk_type;
2241 $this->logs = $tab_result;
2245 $this->error =
"Error ".$this->db->lasterror();
2262 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2263 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2264 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).
')';
2266 $sql .=
" AND active = ".((int) $active);
2269 $sql .=
" AND affect = ".((int) $affect);
2271 $sql .=
" ORDER BY sortorder";
2273 $result = $this->db->query($sql);
2275 $num = $this->db->num_rows($result);
2277 while ($obj = $this->db->fetch_object($result)) {
2278 $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);
2301 $sql =
"SELECT f.rowid, f.statut as status,";
2302 $sql .=
" f.date_create as datec,";
2303 $sql .=
" f.tms as date_modification,";
2304 $sql .=
" f.date_valid as datev,";
2305 $sql .=
" f.date_approval as datea,";
2306 $sql .=
" f.date_refuse as dater,";
2307 $sql .=
" f.fk_user_create as fk_user_creation,";
2308 $sql .=
" f.fk_user_modif as fk_user_modification,";
2309 $sql .=
" f.fk_user_valid as fk_user_validation,";
2310 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2311 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2312 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2313 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2314 $sql .=
" WHERE f.rowid = ".((int) $id);
2315 $sql .=
" AND f.entity = ".$conf->entity;
2317 $resql = $this->db->query($sql);
2319 if ($this->db->num_rows($resql)) {
2320 $obj = $this->db->fetch_object($resql);
2322 $this->
id = $obj->rowid;
2324 $this->date_creation = $this->db->jdate($obj->datec);
2325 $this->date_modification = $this->db->jdate($obj->date_modification);
2326 $this->date_validation = $this->db->jdate($obj->datev);
2327 $this->date_approval = $this->db->jdate($obj->datea);
2329 $this->user_creation_id = $obj->fk_user_creation;
2330 $this->user_validation_id = $obj->fk_user_valid;
2331 $this->user_modification_id = $obj->fk_user_modification;
2334 if ($obj->fk_user_approval_done) {
2335 $this->fk_user_approve = $obj->fk_user_approval_done;
2339 $this->db->free($resql);
2355 global $user, $langs;
2359 $this->specimen = 1;
2361 $this->fk_user = $user->id;
2363 $this->date_debut =
dol_now();
2364 $this->date_fin =
dol_now() + (24 * 3600);
2365 $this->date_valid =
dol_now();
2366 $this->fk_validator = $user->id;
2383 $this->nb = array();
2385 $sql =
"SELECT count(h.rowid) as nb";
2386 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2387 $sql .=
" WHERE h.statut > 1";
2388 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2389 if (!$user->hasRight(
'expensereport',
'readall')) {
2390 $userchildids = $user->getAllChildIds(1);
2391 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(join(
',', $userchildids)).
")";
2392 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(join(
',', $userchildids)).
"))";
2395 $resql = $this->db->query($sql);
2397 while ($obj = $this->db->fetch_object($resql)) {
2398 $this->nb[
"holidays"] = $obj->nb;
2400 $this->db->free($resql);
2404 $this->error = $this->db->error();
2419 global $conf, $langs;
2427 $sql =
"SELECT h.rowid, h.date_debut";
2428 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2429 $sql .=
" WHERE h.statut = 2";
2430 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2431 if (!$user->hasRight(
'expensereport',
'read_all')) {
2432 $userchildids = $user->getAllChildIds(1);
2433 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(join(
',', $userchildids)).
")";
2434 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(join(
',', $userchildids)).
"))";
2437 $resql = $this->db->query($sql);
2439 $langs->load(
"members");
2442 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2443 $response->label = $langs->trans(
"HolidaysToApprove");
2444 $response->labelShort = $langs->trans(
"ToApprove");
2445 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2448 while ($obj = $this->db->fetch_object($resql)) {
2449 $response->nbtodo++;
2451 if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2452 $response->nbtodolate++;
2459 $this->error = $this->db->error();
2474 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2476 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2477 $return .=
'<div class="info-box info-box-sm">';
2478 $return .=
'<span class="info-box-icon bg-infobox-action">';
2480 $return .=
'</span>';
2481 $return .=
'<div class="info-box-content">';
2482 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$arraydata[
'user']->getNomUrl(-1).
'</span>';
2483 if ($selected >= 0) {
2484 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2486 if (property_exists($this,
'fk_type')) {
2489 $return .=
'<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata[
'labeltype']).
'">'.
dol_escape_htmltag($arraydata[
'labeltype']).
'</div>';
2491 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2492 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_debut,
'day').
'</span>';
2493 $return .=
' <span class="opacitymedium small">'.$langs->trans(
"To").
'</span> ';
2494 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_fin,
'day').
'</span>';
2495 if (!empty($arraydata[
'nbopenedday'])) {
2496 $return .=
' ('.$arraydata[
'nbopenedday'].
')';
2499 if (method_exists($this,
'getLibStatut')) {
2500 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2502 $return .=
'</div>';
2503 $return .=
'</div>';
2504 $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