29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'holiday';
45 public $table_element =
'holiday';
50 public $fk_element =
'fk_holiday';
55 public $picto =
'holiday';
65 public $date_create =
'';
75 public $date_debut =
'';
80 public $date_fin =
'';
85 public $date_debut_gmt =
'';
90 public $date_fin_gmt =
'';
106 public $fk_validator;
111 public $date_valid = 0;
116 public $fk_user_valid;
121 public $date_approval;
126 public $fk_user_approve;
131 public $date_refuse = 0;
136 public $fk_user_refuse;
141 public $date_cancel = 0;
146 public $fk_user_cancel;
151 public $fk_user_create;
156 public $detail_refuse =
'';
163 public $holiday = array();
164 public $events = array();
165 public $logs = array();
171 public $optName =
'';
175 public $optValue =
'';
179 public $optRowid = 0;
212 $this->ismultientitymanaged = 0;
225 global $langs, $conf;
226 $langs->load(
"order");
229 $conf->global->HOLIDAY_ADDON =
'mod_holiday_madonna';
239 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
240 foreach ($dirmodels as $reldir) {
244 $mybool = ((bool) @include_once $dir.$file) || $mybool;
252 $obj =
new $classname();
253 '@phan-var-force ModelNumRefHolidays $obj';
254 $numref = $obj->getNextValue($objsoc, $this);
259 $this->error = $obj->error;
264 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_HOLIDAY_ADDON_NotDefined");
288 $this->db->rollback();
300 public function create($user, $notrigger = 0)
308 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
309 $this->error =
"ErrorBadParameterFkUser";
312 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
313 $this->error =
"ErrorBadParameterFkValidator";
316 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
317 $this->error =
"ErrorBadParameterFkType";
322 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday(";
325 $sql .=
"date_create,";
326 $sql .=
"description,";
327 $sql .=
"date_debut,";
331 $sql .=
"fk_validator,";
333 $sql .=
"fk_user_create,";
335 $sql .=
") VALUES (";
337 $sql .=
" ".((int) $this->fk_user).
",";
338 $sql .=
" '".$this->db->idate($now).
"',";
339 $sql .=
" '".$this->db->escape($this->
description).
"',";
340 $sql .=
" '".$this->db->idate($this->date_debut).
"',";
341 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
342 $sql .=
" ".((int) $this->halfday).
",";
344 $sql .=
" ".((int) $this->fk_validator).
",";
345 $sql .=
" ".((int) $this->fk_type).
",";
346 $sql .=
" ".((int) $user->id).
",";
347 $sql .=
" ".((int) $conf->entity);
352 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
353 $resql = $this->db->query($sql);
356 $this->errors[] =
"Error ".$this->db->lasterror();
360 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday");
364 $initialref =
'(PROV'.$this->id.
')';
365 if (!empty($this->
ref)) {
366 $initialref = $this->ref;
369 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"holiday SET ref='".$this->db->escape($initialref).
"' WHERE rowid=".((int) $this->
id);
370 if ($this->db->query($sql)) {
371 $this->
ref = $initialref;
380 if (!$error && !$notrigger) {
394 foreach ($this->errors as $errmsg) {
395 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
396 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
398 $this->db->rollback();
414 public function fetch($id, $ref =
'')
417 $sql .=
" cp.rowid,";
419 $sql .=
" cp.fk_user,";
420 $sql .=
" cp.date_create,";
421 $sql .=
" cp.description,";
422 $sql .=
" cp.date_debut,";
423 $sql .=
" cp.date_fin,";
424 $sql .=
" cp.halfday,";
425 $sql .=
" cp.statut as status,";
426 $sql .=
" cp.fk_validator,";
427 $sql .=
" cp.date_valid,";
428 $sql .=
" cp.fk_user_valid,";
429 $sql .=
" cp.date_approval,";
430 $sql .=
" cp.fk_user_approve,";
431 $sql .=
" cp.date_refuse,";
432 $sql .=
" cp.fk_user_refuse,";
433 $sql .=
" cp.date_cancel,";
434 $sql .=
" cp.fk_user_cancel,";
435 $sql .=
" cp.detail_refuse,";
436 $sql .=
" cp.note_private,";
437 $sql .=
" cp.note_public,";
438 $sql .=
" cp.fk_user_create,";
439 $sql .=
" cp.fk_type,";
440 $sql .=
" cp.entity";
441 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
443 $sql .=
" WHERE cp.rowid = ".((int) $id);
445 $sql .=
" WHERE cp.ref = '".$this->db->escape($ref).
"'";
448 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
449 $resql = $this->db->query($sql);
451 if ($this->db->num_rows($resql)) {
452 $obj = $this->db->fetch_object($resql);
454 $this->
id = $obj->rowid;
455 $this->
ref = ($obj->ref ? $obj->ref : $obj->rowid);
456 $this->fk_user = $obj->fk_user;
457 $this->date_create = $this->db->jdate($obj->date_create);
459 $this->date_debut = $this->db->jdate($obj->date_debut);
460 $this->date_fin = $this->db->jdate($obj->date_fin);
461 $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
462 $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
463 $this->halfday = $obj->halfday;
464 $this->
status = $obj->status;
465 $this->statut = $obj->status;
466 $this->fk_validator = $obj->fk_validator;
467 $this->date_valid = $this->db->jdate($obj->date_valid);
468 $this->fk_user_valid = $obj->fk_user_valid;
469 $this->user_validation_id = $obj->fk_user_valid;
470 $this->date_approval = $this->db->jdate($obj->date_approval);
471 $this->fk_user_approve = $obj->fk_user_approve;
472 $this->date_refuse = $this->db->jdate($obj->date_refuse);
473 $this->fk_user_refuse = $obj->fk_user_refuse;
474 $this->date_cancel = $this->db->jdate($obj->date_cancel);
475 $this->fk_user_cancel = $obj->fk_user_cancel;
476 $this->detail_refuse = $obj->detail_refuse;
477 $this->note_private = $obj->note_private;
478 $this->note_public = $obj->note_public;
479 $this->fk_user_create = $obj->fk_user_create;
480 $this->fk_type = $obj->fk_type;
481 $this->entity = $obj->entity;
489 $this->db->free($resql);
493 $this->error =
"Error ".$this->db->lasterror();
509 $sql .=
" cp.rowid,";
512 $sql .=
" cp.fk_user,";
513 $sql .=
" cp.fk_type,";
514 $sql .=
" cp.date_create,";
515 $sql .=
" cp.description,";
516 $sql .=
" cp.date_debut,";
517 $sql .=
" cp.date_fin,";
518 $sql .=
" cp.halfday,";
519 $sql .=
" cp.statut as status,";
520 $sql .=
" cp.fk_validator,";
521 $sql .=
" cp.date_valid,";
522 $sql .=
" cp.fk_user_valid,";
523 $sql .=
" cp.date_approval,";
524 $sql .=
" cp.fk_user_approve,";
525 $sql .=
" cp.date_refuse,";
526 $sql .=
" cp.fk_user_refuse,";
527 $sql .=
" cp.date_cancel,";
528 $sql .=
" cp.fk_user_cancel,";
529 $sql .=
" cp.detail_refuse,";
531 $sql .=
" uu.lastname as user_lastname,";
532 $sql .=
" uu.firstname as user_firstname,";
533 $sql .=
" uu.login as user_login,";
534 $sql .=
" uu.statut as user_status,";
535 $sql .=
" uu.photo as user_photo,";
537 $sql .=
" ua.lastname as validator_lastname,";
538 $sql .=
" ua.firstname as validator_firstname,";
539 $sql .=
" ua.login as validator_login,";
540 $sql .=
" ua.statut as validator_status,";
541 $sql .=
" ua.photo as validator_photo";
543 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
544 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
545 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
546 $sql .=
" AND cp.fk_user IN (".$this->db->sanitize($user_id).
")";
549 if (!empty($filter)) {
554 if (!empty($order)) {
558 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
559 $resql = $this->db->query($sql);
564 $tab_result = $this->holiday;
565 $num = $this->db->num_rows($resql);
574 $obj = $this->db->fetch_object($resql);
576 $tab_result[$i][
'rowid'] = $obj->rowid;
577 $tab_result[$i][
'id'] = $obj->rowid;
578 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
580 $tab_result[$i][
'fk_user'] = $obj->fk_user;
581 $tab_result[$i][
'fk_type'] = $obj->fk_type;
582 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
583 $tab_result[$i][
'description'] = $obj->description;
584 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
585 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
586 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
587 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
588 $tab_result[$i][
'halfday'] = $obj->halfday;
589 $tab_result[$i][
'statut'] = $obj->status;
590 $tab_result[$i][
'status'] = $obj->status;
591 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
592 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
593 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
594 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
595 $tab_result[$i][
'fk_user_approve'] = $obj->fk_user_approve;
596 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
597 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
598 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
599 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
600 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
602 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
603 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
604 $tab_result[$i][
'user_login'] = $obj->user_login;
605 $tab_result[$i][
'user_statut'] = $obj->user_status;
606 $tab_result[$i][
'user_status'] = $obj->user_status;
607 $tab_result[$i][
'user_photo'] = $obj->user_photo;
609 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
610 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
611 $tab_result[$i][
'validator_login'] = $obj->validator_login;
612 $tab_result[$i][
'validator_statut'] = $obj->validator_status;
613 $tab_result[$i][
'validator_status'] = $obj->validator_status;
614 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
620 $this->holiday = $tab_result;
624 $this->error =
"Error ".$this->db->lasterror();
639 $sql .=
" cp.rowid,";
641 $sql .=
" cp.fk_user,";
642 $sql .=
" cp.fk_type,";
643 $sql .=
" cp.date_create,";
644 $sql .=
" cp.tms as date_modification,";
645 $sql .=
" cp.description,";
646 $sql .=
" cp.date_debut,";
647 $sql .=
" cp.date_fin,";
648 $sql .=
" cp.halfday,";
649 $sql .=
" cp.statut as status,";
650 $sql .=
" cp.fk_validator,";
651 $sql .=
" cp.date_valid,";
652 $sql .=
" cp.fk_user_valid,";
653 $sql .=
" cp.date_approval,";
654 $sql .=
" cp.fk_user_approve,";
655 $sql .=
" cp.date_refuse,";
656 $sql .=
" cp.fk_user_refuse,";
657 $sql .=
" cp.date_cancel,";
658 $sql .=
" cp.fk_user_cancel,";
659 $sql .=
" cp.detail_refuse,";
661 $sql .=
" uu.lastname as user_lastname,";
662 $sql .=
" uu.firstname as user_firstname,";
663 $sql .=
" uu.login as user_login,";
664 $sql .=
" uu.statut as user_status,";
665 $sql .=
" uu.photo as user_photo,";
667 $sql .=
" ua.lastname as validator_lastname,";
668 $sql .=
" ua.firstname as validator_firstname,";
669 $sql .=
" ua.login as validator_login,";
670 $sql .=
" ua.statut as validator_status,";
671 $sql .=
" ua.photo as validator_photo";
673 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
674 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
675 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
678 if (!empty($filter)) {
683 if (!empty($order)) {
687 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
688 $resql = $this->db->query($sql);
693 $tab_result = $this->holiday;
694 $num = $this->db->num_rows($resql);
703 $obj = $this->db->fetch_object($resql);
705 $tab_result[$i][
'rowid'] = $obj->rowid;
706 $tab_result[$i][
'id'] = $obj->rowid;
707 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
709 $tab_result[$i][
'fk_user'] = $obj->fk_user;
710 $tab_result[$i][
'fk_type'] = $obj->fk_type;
711 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
712 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
713 $tab_result[$i][
'description'] = $obj->description;
714 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
715 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
716 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
717 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
718 $tab_result[$i][
'halfday'] = $obj->halfday;
719 $tab_result[$i][
'statut'] = $obj->status;
720 $tab_result[$i][
'status'] = $obj->status;
721 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
722 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
723 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
724 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
725 $tab_result[$i][
'fk_user_approve'] = $obj->fk_user_approve;
726 $tab_result[$i][
'date_refuse'] = $obj->date_refuse;
727 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
728 $tab_result[$i][
'date_cancel'] = $obj->date_cancel;
729 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
730 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
732 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
733 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
734 $tab_result[$i][
'user_login'] = $obj->user_login;
735 $tab_result[$i][
'user_statut'] = $obj->user_status;
736 $tab_result[$i][
'user_status'] = $obj->user_status;
737 $tab_result[$i][
'user_photo'] = $obj->user_photo;
739 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
740 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
741 $tab_result[$i][
'validator_login'] = $obj->validator_login;
742 $tab_result[$i][
'validator_statut'] = $obj->validator_status;
743 $tab_result[$i][
'validator_status'] = $obj->validator_status;
744 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
749 $this->holiday = $tab_result;
753 $this->error =
"Error ".$this->db->lasterror();
766 public function validate($user =
null, $notrigger = 0)
768 global $conf, $langs;
769 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
772 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
774 if ($checkBalance > 0) {
775 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
778 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
784 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref) || $this->
ref == $this->
id)) {
792 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
793 $sql .=
" fk_user_valid = ".((int) $user->id).
",";
794 $sql .=
" date_valid = '".$this->db->idate(
dol_now()).
"',";
795 if (!empty($this->
status) && is_numeric($this->
status)) {
796 $sql .=
" statut = ".((int) $this->
status).
",";
798 $this->error =
'Property status must be a numeric value';
801 $sql .=
" ref = '".$this->db->escape($num).
"'";
802 $sql .=
" WHERE rowid = ".((int) $this->
id);
806 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
807 $resql = $this->db->query($sql);
810 $this->errors[] =
"Error ".$this->db->lasterror();
816 $result = $this->
call_trigger(
'HOLIDAY_VALIDATE', $user);
825 $this->oldref = $this->ref;
828 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
830 $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) .
"'";
831 $sql .=
" WHERE filename LIKE '" . $this->db->escape($this->
ref) .
"%' AND filepath = 'holiday/" . $this->db->escape($this->
ref) .
"' and entity = " . ((int) $conf->entity);
832 $resql = $this->db->query($sql);
835 $this->error = $this->db->lasterror();
837 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'holiday/".$this->db->escape($this->newref).
"'";
838 $sql .=
" WHERE filepath = 'holiday/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
839 $resql = $this->db->query($sql);
842 $this->error = $this->db->lasterror();
848 $dirsource = $conf->holiday->multidir_output[$this->entity] .
'/' . $oldref;
849 $dirdest = $conf->holiday->multidir_output[$this->entity] .
'/' . $newref;
850 if (!$error && file_exists($dirsource)) {
851 dol_syslog(get_class($this) .
"::validate rename dir " . $dirsource .
" into " . $dirdest);
852 if (@rename($dirsource, $dirdest)) {
855 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^' . preg_quote($oldref,
'/'));
856 foreach ($listoffiles as $fileentry) {
857 $dirsource = $fileentry[
'name'];
858 $dirdest = preg_replace(
'/^' . preg_quote($oldref,
'/') .
'/', $newref, $dirsource);
859 $dirsource = $fileentry[
'path'] .
'/' . $dirsource;
860 $dirdest = $fileentry[
'path'] .
'/' . $dirdest;
861 @rename($dirsource, $dirdest);
871 foreach ($this->errors as $errmsg) {
872 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
873 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
875 $this->db->rollback();
891 public function approve($user =
null, $notrigger = 0)
895 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
897 if ($checkBalance > 0) {
898 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
901 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
907 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
908 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
909 if (!empty($this->date_debut)) {
910 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
914 if (!empty($this->date_fin)) {
915 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
919 $sql .=
" halfday = ".((int) $this->halfday).
",";
920 if (!empty($this->
status) && is_numeric($this->
status)) {
921 $sql .=
" statut = ".((int) $this->
status).
",";
925 if (!empty($this->fk_validator)) {
926 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
930 if (!empty($this->date_valid)) {
931 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
933 $sql .=
" date_valid = NULL,";
935 if (!empty($this->fk_user_valid)) {
936 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
938 $sql .=
" fk_user_valid = NULL,";
940 if (!empty($this->date_approval)) {
941 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
943 $sql .=
" date_approval = NULL,";
945 if (!empty($this->fk_user_approve)) {
946 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
948 $sql .=
" fk_user_approve = NULL,";
950 if (!empty($this->date_refuse)) {
951 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
953 $sql .=
" date_refuse = NULL,";
955 if (!empty($this->fk_user_refuse)) {
956 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
958 $sql .=
" fk_user_refuse = NULL,";
960 if (!empty($this->date_cancel)) {
961 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
963 $sql .=
" date_cancel = NULL,";
965 if (!empty($this->fk_user_cancel)) {
966 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
968 $sql .=
" fk_user_cancel = NULL,";
970 if (!empty($this->detail_refuse)) {
971 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
973 $sql .=
" detail_refuse = NULL";
975 $sql .=
" WHERE rowid = ".((int) $this->
id);
979 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
980 $resql = $this->db->query($sql);
983 $this->errors[] =
"Error ".$this->db->lasterror();
989 $result = $this->
call_trigger(
'HOLIDAY_APPROVE', $user);
999 foreach ($this->errors as $errmsg) {
1000 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
1001 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1003 $this->db->rollback();
1006 $this->db->commit();
1018 public function update($user =
null, $notrigger = 0)
1020 global $conf, $langs;
1023 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
1025 if ($checkBalance > 0 && $this->
status != self::STATUS_DRAFT) {
1026 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
1029 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1035 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
1037 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
1039 if (!empty($this->date_debut)) {
1040 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
1044 if (!empty($this->date_fin)) {
1045 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
1049 $sql .=
" halfday = ".$this->halfday.
",";
1050 if (!empty($this->
status) && is_numeric($this->
status)) {
1051 $sql .=
" statut = ".$this->status.
",";
1055 if (!empty($this->fk_validator)) {
1056 $sql .=
" fk_validator = '".$this->db->escape($this->fk_validator).
"',";
1060 if (!empty($this->date_valid)) {
1061 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1063 $sql .=
" date_valid = NULL,";
1065 if (!empty($this->fk_user_valid)) {
1066 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
1068 $sql .=
" fk_user_valid = NULL,";
1070 if (!empty($this->date_approval)) {
1071 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
1073 $sql .=
" date_approval = NULL,";
1075 if (!empty($this->fk_user_approve)) {
1076 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
1078 $sql .=
" fk_user_approve = NULL,";
1080 if (!empty($this->date_refuse)) {
1081 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
1083 $sql .=
" date_refuse = NULL,";
1085 if (!empty($this->fk_user_refuse)) {
1086 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
1088 $sql .=
" fk_user_refuse = NULL,";
1090 if (!empty($this->date_cancel)) {
1091 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
1093 $sql .=
" date_cancel = NULL,";
1095 if (!empty($this->fk_user_cancel)) {
1096 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
1098 $sql .=
" fk_user_cancel = NULL,";
1100 if (!empty($this->detail_refuse)) {
1101 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1103 $sql .=
" detail_refuse = NULL";
1106 $sql .=
" WHERE rowid = ".((int) $this->
id);
1110 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1111 $resql = $this->db->query($sql);
1114 $this->errors[] =
"Error ".$this->db->lasterror();
1120 $result = $this->
call_trigger(
'HOLIDAY_MODIFY', $user);
1130 foreach ($this->errors as $errmsg) {
1131 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1132 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1134 $this->db->rollback();
1137 $this->db->commit();
1150 public function delete($user, $notrigger = 0)
1152 global $conf, $langs;
1155 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1156 $sql .=
" WHERE rowid=".((int) $this->
id);
1160 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1161 $resql = $this->db->query($sql);
1164 $this->errors[] =
"Error ".$this->db->lasterror();
1170 $result = $this->
call_trigger(
'HOLIDAY_DELETE', $user);
1180 foreach ($this->errors as $errmsg) {
1181 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1182 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1184 $this->db->rollback();
1187 $this->db->commit();
1209 foreach ($this->holiday as $infos_CP) {
1220 if ($halfday == 0) {
1221 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1224 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1227 } elseif ($halfday == -1) {
1229 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1230 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1234 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1235 if ($dateStart < $dateEnd) {
1238 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1242 } elseif ($halfday == 1) {
1244 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1245 if ($dateStart < $dateEnd) {
1248 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1252 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1253 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1257 } elseif ($halfday == 2) {
1259 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1260 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1264 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1265 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1270 dol_print_error(
null,
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1289 $isavailablemorning =
true;
1290 $isavailableafternoon =
true;
1293 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1294 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1295 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1296 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1297 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->db->idate($timestamp).
"'";
1298 if ($status !=
'-1') {
1299 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1302 $resql = $this->db->query($sql);
1304 $num_rows = $this->db->num_rows($resql);
1305 if ($num_rows > 0) {
1306 $arrayofrecord = array();
1308 while ($i < $num_rows) {
1309 $obj = $this->db->fetch_object($resql);
1312 $arrayofrecord[$obj->rowid] = array(
'date_start' => $this->db->jdate($obj->date_start),
'date_end' => $this->db->jdate($obj->date_end),
'halfday' => $obj->halfday,
'status' => $obj->status);
1317 $isavailablemorning =
true;
1318 foreach ($arrayofrecord as $record) {
1319 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1322 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1325 $isavailablemorning =
false;
1328 $isavailableafternoon =
true;
1329 foreach ($arrayofrecord as $record) {
1330 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1333 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1336 $isavailableafternoon =
false;
1344 $result = array(
'morning' => $isavailablemorning,
'afternoon' => $isavailableafternoon);
1345 if (!$isavailablemorning) {
1346 $result[
'morning_reason'] =
'leave_request';
1348 if (!$isavailableafternoon) {
1349 $result[
'afternoon_reason'] =
'leave_request';
1364 $langs->load(
'holiday');
1365 $nofetch = !empty($params[
'nofetch']);
1368 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1369 if (isset($this->
status)) {
1370 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1372 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1374 if (!$nofetch && !empty($this->fk_type)) {
1375 $typeleaves = $this->
getTypes(1, -1);
1376 if (empty($typeleaves[$this->fk_type])) {
1377 $labeltoshow = $langs->trans(
"TypeWasDisabledOrRemoved", $this->fk_type);
1379 $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']);
1381 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type") .
':</b> ' . $labeltoshow;
1383 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1384 $listhalfday = array(
1385 'morning' => $langs->trans(
"Morning"),
1386 "afternoon" => $langs->trans(
"Afternoon")
1388 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ?
'afternoon' :
'morning';
1389 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ?
'morning' :
'afternoon';
1390 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateDebCP') .
'</b>: '.
dol_print_date($this->date_debut,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1391 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateFinCP') .
'</b>: '.
dol_print_date($this->date_fin,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1407 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1409 global $conf, $langs, $hookmanager;
1411 if (!empty($conf->dol_no_mouse_hover)) {
1418 'objecttype' => $this->element,
1421 $classfortooltip =
'classfortooltip';
1424 $classfortooltip =
'classforajaxtooltip';
1425 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1431 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1436 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1437 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1438 $add_save_lastsearch_values = 1;
1440 if ($add_save_lastsearch_values) {
1441 $url .=
'&save_lastsearch_values=1';
1446 if (empty($notooltip)) {
1448 $label = $langs->trans(
"ShowMyObject");
1449 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1451 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1452 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1454 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1457 $linkstart =
'<a href="'.$url.
'"';
1458 $linkstart .= $linkclose.
'>';
1461 $result .= $linkstart;
1464 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1466 if ($withpicto != 2) {
1467 $result .= $this->ref;
1469 $result .= $linkend;
1472 $hookmanager->initHooks(array($this->element .
'dao'));
1473 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1474 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1476 $result = $hookmanager->resPrint;
1478 $result .= $hookmanager->resPrint;
1504 public function LibStatut($status, $mode = 0, $startdate =
'')
1509 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1517 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1525 $statusType =
'status6';
1526 if (!empty($startdate) && $startdate >=
dol_now()) {
1527 $statusType =
'status4';
1528 $params = array(
'tooltip' => $this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1530 if ($status == self::STATUS_DRAFT) {
1531 $statusType =
'status0';
1533 if ($status == self::STATUS_VALIDATED) {
1534 $statusType =
'status1';
1536 if ($status == self::STATUS_CANCELED) {
1537 $statusType =
'status9';
1539 if ($status == self::STATUS_REFUSED) {
1540 $statusType =
'status9';
1543 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1555 public function selectStatutCP($selected = 0, $htmlname =
'select_statut', $morecss =
'minwidth125')
1560 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1561 $nb = count($name) + 1;
1564 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1565 $out .=
'<option value="-1"> </option>'.
"\n";
1568 for ($i = 1; $i < $nb; $i++) {
1569 if ($i == $selected) {
1570 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1572 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1576 $out .=
"</select>\n";
1579 $out .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($showempty < 0 ? (
string) $showempty :
'-1'), $morecss);
1593 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1594 $sql .=
" value = '".$this->db->escape($value).
"'";
1595 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1597 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1598 $result = $this->db->query($sql);
1616 $sql =
"SELECT value";
1617 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1618 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1620 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1621 $result = $this->db->query($sql);
1624 $obj = $this->db->fetch_object($result);
1627 if ($createifnotfound) {
1628 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1629 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->db->escape($createifnotfound).
"')";
1630 $result = $this->db->query($sql);
1632 return $createifnotfound;
1634 $this->error = $this->db->lasterror();
1645 $this->error = $this->db->lasterror();
1660 global $user, $langs;
1664 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1665 $langs->load(
"holiday");
1670 $month = date(
'm', $now);
1674 $lastUpdate = $this->
getConfCP(
'lastUpdate', $newdateforlastupdate);
1675 $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
1679 if ($month != $monthLastUpdate) {
1682 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1683 $nbUser = count($users);
1685 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1686 $sql .=
" value = '".$this->db->escape($newdateforlastupdate).
"'";
1687 $sql .=
" WHERE name = 'lastUpdate'";
1688 $result = $this->db->query($sql);
1690 $typeleaves = $this->
getTypes(1, 1);
1693 foreach ($users as $userCounter) {
1694 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1695 if (empty($nbDaysToAdd)) {
1699 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1701 $nowHoliday = (float) $userCounter[
'nb_holiday'];
1702 $newSolde = $nowHoliday + $nbDaysToAdd;
1705 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidaysMonthlyUpdate'), $newSolde, $userCounter[
'type']);
1707 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1716 $this->db->commit();
1719 $this->db->rollback();
1729 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1730 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1731 $resql = $this->db->query($sql);
1733 $num = $this->db->num_rows($resql);
1737 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1738 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1739 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1740 $result = $this->db->query($sql);
1743 $this->errors[] = $this->db->lasterror();
1747 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1748 $sql .= ((float) $nbHoliday);
1749 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1750 $result = $this->db->query($sql);
1753 $this->errors[] = $this->db->lasterror();
1757 $this->errors[] = $this->db->lasterror();
1780 dol_syslog(get_class($this).
'::createCPusers');
1781 $arrayofusers = $this->
fetchUsers(
false,
true);
1783 foreach ($arrayofusers as $users) {
1784 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1785 $sql .=
" (fk_user, nb_holiday)";
1786 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1788 $resql = $this->db->query($sql);
1794 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1795 $sql .=
" (fk_user, nb_holiday)";
1796 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1798 $resql = $this->db->query($sql);
1814 $sql =
"SELECT nb_holiday";
1815 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1816 $sql .=
" WHERE fk_user = ".(int) $user_id;
1818 $sql .=
" AND fk_type = ".(int) $fk_type;
1821 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1822 $result = $this->db->query($sql);
1824 $obj = $this->db->fetch_object($result);
1827 return $obj->nb_holiday;
1844 public function fetchUsers($stringlist =
true, $type =
true, $filters =
'')
1848 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1854 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1855 $sql .=
" DISTINCT";
1858 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1860 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1861 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1862 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1863 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1864 $sql .=
" OR u.entity = 0)";
1866 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1868 $sql .=
" AND u.statut > 0";
1869 $sql .=
" AND u.employee = 1";
1874 $resql = $this->db->query($sql);
1879 $num = $this->db->num_rows($resql);
1884 $obj = $this->db->fetch_object($resql);
1887 $stringlist .= $obj->rowid;
1889 $stringlist .=
', '.$obj->rowid;
1898 $this->error =
"Error ".$this->db->lasterror();
1903 $sql =
"SELECT DISTINCT cpu.fk_user";
1904 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1905 $sql .=
" WHERE cpu.fk_user = u.rowid";
1910 $resql = $this->db->query($sql);
1915 $num = $this->db->num_rows($resql);
1920 $obj = $this->db->fetch_object($resql);
1923 $stringlist .= $obj->fk_user;
1925 $stringlist .=
', '.$obj->fk_user;
1934 $this->error =
"Error ".$this->db->lasterror();
1944 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1945 $sql .=
" DISTINCT";
1947 $sql .=
" u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut as status, u.fk_user";
1948 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1950 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1951 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1952 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1953 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1954 $sql .=
" OR u.entity = 0)";
1956 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1959 $sql .=
" AND u.statut > 0";
1960 $sql .=
" AND u.employee = 1";
1965 $resql = $this->db->query($sql);
1970 $tab_result = $this->holiday;
1971 $num = $this->db->num_rows($resql);
1975 $obj = $this->db->fetch_object($resql);
1977 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
1978 $tab_result[$i][
'id'] = (int) $obj->rowid;
1979 $tab_result[$i][
'name'] = $obj->lastname;
1980 $tab_result[$i][
'lastname'] = $obj->lastname;
1981 $tab_result[$i][
'firstname'] = $obj->firstname;
1982 $tab_result[$i][
'gender'] = $obj->gender;
1983 $tab_result[$i][
'status'] = (int) $obj->status;
1984 $tab_result[$i][
'employee'] = $obj->employee;
1985 $tab_result[$i][
'photo'] = $obj->photo;
1986 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
1996 $this->errors[] =
"Error ".$this->db->lasterror();
2001 $sql =
"SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut as status, u.fk_user";
2002 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
2003 $sql .=
" WHERE cpu.fk_user = u.rowid";
2008 $resql = $this->db->query($sql);
2013 $tab_result = $this->holiday;
2014 $num = $this->db->num_rows($resql);
2018 $obj = $this->db->fetch_object($resql);
2020 $tab_result[$i][
'rowid'] = $obj->rowid;
2021 $tab_result[$i][
'id'] = $obj->rowid;
2022 $tab_result[$i][
'name'] = $obj->lastname;
2023 $tab_result[$i][
'lastname'] = $obj->lastname;
2024 $tab_result[$i][
'firstname'] = $obj->firstname;
2025 $tab_result[$i][
'gender'] = $obj->gender;
2026 $tab_result[$i][
'status'] = $obj->status;
2027 $tab_result[$i][
'employee'] = $obj->employee;
2028 $tab_result[$i][
'photo'] = $obj->photo;
2029 $tab_result[$i][
'fk_user'] = $obj->fk_user;
2031 $tab_result[$i][
'type'] = $obj->fk_type;
2032 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
2040 $this->error =
"Error ".$this->db->lasterror();
2058 $users_validator = array();
2060 $sql =
"SELECT DISTINCT ur.fk_user";
2061 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2062 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2064 $sql .=
" SELECT DISTINCT ugu.fk_user";
2065 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2066 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2069 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
2070 $result = $this->db->query($sql);
2072 $num_rows = $this->db->num_rows($result);
2074 while ($i < $num_rows) {
2075 $objp = $this->db->fetch_object($result);
2076 array_push($users_validator, $objp->fk_user);
2079 return $users_validator;
2081 $this->error = $this->db->lasterror();
2082 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2095 $sql =
"SELECT count(u.rowid) as compteur";
2096 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2097 $sql .=
" WHERE u.statut > 0";
2099 $result = $this->db->query($sql);
2100 $object = $this->db->fetch_object($result);
2111 $sql =
"SELECT count(u.rowid) as compteur";
2112 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2113 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2115 $result = $this->db->query($sql);
2116 $object = $this->db->fetch_object($result);
2130 if (empty($userCP)) {
2133 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2148 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2150 global $conf, $langs;
2158 if ($prev_solde == $new_solde) {
2165 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2166 $sql .=
"date_action,";
2167 $sql .=
"fk_user_action,";
2168 $sql .=
"fk_user_update,";
2169 $sql .=
"type_action,";
2170 $sql .=
"prev_solde,";
2171 $sql .=
"new_solde,";
2173 $sql .=
") VALUES (";
2174 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2175 $sql .=
" ".((int) $fk_user_action).
",";
2176 $sql .=
" ".((int) $fk_user_update).
",";
2177 $sql .=
" '".$this->db->escape($label).
"',";
2178 $sql .=
" ".((float) $prev_solde).
",";
2179 $sql .=
" ".((float) $new_solde).
",";
2180 $sql .=
" ".((int) $fk_type);
2183 $resql = $this->db->query($sql);
2186 $this->errors[] =
"Error ".$this->db->lasterror();
2190 $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2195 foreach ($this->errors as $errmsg) {
2196 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2197 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2199 $this->db->rollback();
2202 $this->db->commit();
2203 return $this->optRowid;
2217 $sql .=
" cpl.rowid,";
2218 $sql .=
" cpl.date_action,";
2219 $sql .=
" cpl.fk_user_action,";
2220 $sql .=
" cpl.fk_user_update,";
2221 $sql .=
" cpl.type_action,";
2222 $sql .=
" cpl.prev_solde,";
2223 $sql .=
" cpl.new_solde,";
2224 $sql .=
" cpl.fk_type";
2225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2226 $sql .=
" WHERE cpl.rowid > 0";
2229 if (!empty($filter)) {
2230 $sql .=
" ".$filter;
2234 if (!empty($order)) {
2238 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2239 $resql = $this->db->query($sql);
2244 $tab_result = $this->logs;
2245 $num = $this->db->num_rows($resql);
2254 $obj = $this->db->fetch_object($resql);
2256 $tab_result[$i][
'rowid'] = $obj->rowid;
2257 $tab_result[$i][
'id'] = $obj->rowid;
2258 $tab_result[$i][
'date_action'] = $obj->date_action;
2259 $tab_result[$i][
'fk_user_action'] = $obj->fk_user_action;
2260 $tab_result[$i][
'fk_user_update'] = $obj->fk_user_update;
2261 $tab_result[$i][
'type_action'] = $obj->type_action;
2262 $tab_result[$i][
'prev_solde'] = $obj->prev_solde;
2263 $tab_result[$i][
'new_solde'] = $obj->new_solde;
2264 $tab_result[$i][
'fk_type'] = $obj->fk_type;
2269 $this->logs = $tab_result;
2273 $this->error =
"Error ".$this->db->lasterror();
2290 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2291 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2292 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).
')';
2293 $sql .=
" AND entity IN (".getEntity(
'c_holiday_types').
")";
2295 $sql .=
" AND active = ".((int) $active);
2298 $sql .=
" AND affect = ".((int) $affect);
2300 $sql .=
" ORDER BY sortorder";
2302 $result = $this->db->query($sql);
2304 $num = $this->db->num_rows($result);
2307 while ($obj = $this->db->fetch_object($result)) {
2308 $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);
2331 $sql =
"SELECT f.rowid, f.statut as status,";
2332 $sql .=
" f.date_create as datec,";
2333 $sql .=
" f.tms as date_modification,";
2334 $sql .=
" f.date_valid as datev,";
2335 $sql .=
" f.date_approval as datea,";
2336 $sql .=
" f.date_refuse as dater,";
2337 $sql .=
" f.fk_user_create as fk_user_creation,";
2338 $sql .=
" f.fk_user_modif as fk_user_modification,";
2339 $sql .=
" f.fk_user_valid as fk_user_validation,";
2340 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2341 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2342 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2343 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2344 $sql .=
" WHERE f.rowid = ".((int) $id);
2345 $sql .=
" AND f.entity = ".$conf->entity;
2347 $resql = $this->db->query($sql);
2349 if ($this->db->num_rows($resql)) {
2350 $obj = $this->db->fetch_object($resql);
2352 $this->
id = $obj->rowid;
2354 $this->date_creation = $this->db->jdate($obj->datec);
2355 $this->date_modification = $this->db->jdate($obj->date_modification);
2356 $this->date_validation = $this->db->jdate($obj->datev);
2357 $this->date_approval = $this->db->jdate($obj->datea);
2359 $this->user_creation_id = $obj->fk_user_creation;
2360 $this->user_validation_id = $obj->fk_user_validation;
2361 $this->user_modification_id = $obj->fk_user_modification;
2364 if ($obj->fk_user_approval_done) {
2365 $this->fk_user_approve = $obj->fk_user_approval_done;
2369 $this->db->free($resql);
2385 global $user, $langs;
2389 $this->specimen = 1;
2391 $this->fk_user = $user->id;
2393 $this->date_debut =
dol_now();
2394 $this->date_fin =
dol_now() + (24 * 3600);
2395 $this->date_valid =
dol_now();
2396 $this->fk_validator = $user->id;
2413 $this->nb = array();
2415 $sql =
"SELECT count(h.rowid) as nb";
2416 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2417 $sql .=
" WHERE h.statut > 1";
2418 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2419 if (!$user->hasRight(
'expensereport',
'readall')) {
2420 $userchildids = $user->getAllChildIds(1);
2421 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2422 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2425 $resql = $this->db->query($sql);
2427 while ($obj = $this->db->fetch_object($resql)) {
2428 $this->nb[
"holidays"] = $obj->nb;
2430 $this->db->free($resql);
2434 $this->error = $this->db->error();
2449 global $conf, $langs;
2457 $sql =
"SELECT h.rowid, h.date_debut";
2458 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2459 $sql .=
" WHERE h.statut = 2";
2460 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2461 if (!$user->hasRight(
'expensereport',
'read_all')) {
2462 $userchildids = $user->getAllChildIds(1);
2463 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2464 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2467 $resql = $this->db->query($sql);
2469 $langs->load(
"members");
2472 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2473 $response->label = $langs->trans(
"HolidaysToApprove");
2474 $response->labelShort = $langs->trans(
"ToApprove");
2475 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2478 while ($obj = $this->db->fetch_object($resql)) {
2479 $response->nbtodo++;
2481 if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2482 $response->nbtodolate++;
2489 $this->error = $this->db->error();
2504 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2506 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2507 $return .=
'<div class="info-box info-box-sm">';
2508 $return .=
'<span class="info-box-icon bg-infobox-action">';
2510 $return .=
'</span>';
2511 $return .=
'<div class="info-box-content">';
2512 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().
'</span>';
2513 if ($selected >= 0) {
2514 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2516 if (property_exists($this,
'fk_type')) {
2519 $return .=
'<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata[
'labeltype']).
'">'.
dol_escape_htmltag($arraydata[
'labeltype']).
'</div>';
2521 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2522 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_debut,
'day').
'</span>';
2523 $return .=
' <span class="opacitymedium small">'.$langs->trans(
"To").
'</span> ';
2524 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_fin,
'day').
'</span>';
2525 if (!empty($arraydata[
'nbopenedday'])) {
2526 $return .=
' ('.$arraydata[
'nbopenedday'].
')';
2529 if (method_exists($this,
'getLibStatut')) {
2530 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2532 $return .=
'</div>';
2533 $return .=
'</div>';
2534 $return .=
'</div>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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 clickable name (with picto eventually)
verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday=0)
Check if a user is on holiday (partially or completely) into a period.
validate($user=null, $notrigger=0)
Validate leave request.
info($id)
Load information on object.
updateBalance()
Update balance of vacations and check table of users for holidays is complete.
updateConfCP($name, $value)
Met à jour une option du module Holiday Payés.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
fetch($id, $ref='')
Load object in memory from database.
addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
addLogCP
verifNbUsers($userDolibarrWithoutCP, $userCP)
Compare le nombre d'utilisateur actif de Dolibarr à celui des utilisateurs des congés payés.
verifDateHolidayForTimestamp($fk_user, $timestamp, $status='-1')
Check that a user is not on holiday for a particular timestamp.
approve($user=null, $notrigger=0)
Approve leave request.
getNextNumRef($objsoc)
Returns the reference to the following non used Order depending on the active numbering module define...
const STATUS_REFUSED
Refused.
getConfCP($name, $createifnotfound='')
Return value of a conf parameter for leave module TODO Move this into llx_const table.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Créer un congés payés dans la base de données.
selectStatutCP($selected=0, $htmlname='select_statut', $morecss='minwidth125')
Show select with list of leave status.
countActiveUsersWithoutCP()
Compte le nombre d'utilisateur actifs dans Dolibarr sans CP.
updateSoldeCP($userID=0, $nbHoliday=0, $fk_type=0)
Met à jour le timestamp de la dernière mise à jour du solde des CP.
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 the balance of annual leave of a user.
fetch_users_approver_holiday()
Return list of people with permission to validate leave requests.
__construct($db)
Constructor.
loadStateBoard()
Load this->nb for dashboard.
getLibStatut($mode=0)
Returns the label status.
createCPusers($single=false, $userid=0)
Create entries for each user at setup step.
fetchAll($order, $filter)
List all holidays of all users.
const STATUS_CANCELED
Canceled.
countActiveUsers()
Compte le nombre d'utilisateur actifs dans Dolibarr.
fetchByUser($user_id, $order='', $filter='')
List holidays for a particular user or list of users.
const STATUS_APPROVED
Approved.
getTooltipContentArray($params)
getTooltipContentArray
fetchUsers($stringlist=true, $type=true, $filters='')
Get list of Users or list of vacation balance.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
LibStatut($status, $mode=0, $startdate='')
Returns the label of a status.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...