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';
62 public $date_create =
'';
72 public $date_debut =
'';
77 public $date_fin =
'';
82 public $date_debut_gmt =
'';
87 public $date_fin_gmt =
'';
103 public $fk_validator;
108 public $date_valid = 0;
113 public $fk_user_valid;
118 public $date_approval;
123 public $fk_user_approve;
128 public $date_refuse = 0;
133 public $fk_user_refuse;
138 public $date_cancel = 0;
143 public $fk_user_cancel;
148 public $fk_user_create;
153 public $detail_refuse =
'';
160 public $holiday = array();
161 public $events = array();
162 public $logs = array();
164 public $optName =
'';
165 public $optValue =
'';
166 public $optRowid =
'';
199 $this->ismultientitymanaged = 0;
212 global $langs, $conf;
213 $langs->load(
"order");
216 $conf->global->HOLIDAY_ADDON =
'mod_holiday_madonna';
226 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
227 foreach ($dirmodels as $reldir) {
231 $mybool = ((bool) @include_once $dir.$file) || $mybool;
234 if ($mybool ===
false) {
239 $obj =
new $classname();
240 $numref = $obj->getNextValue($objsoc, $this);
245 $this->error = $obj->error;
250 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_HOLIDAY_ADDON_NotDefined");
274 $this->db->rollback();
286 public function create($user, $notrigger = 0)
294 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
295 $this->error =
"ErrorBadParameterFkUser";
298 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
299 $this->error =
"ErrorBadParameterFkValidator";
302 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
303 $this->error =
"ErrorBadParameterFkType";
308 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday(";
311 $sql .=
"date_create,";
312 $sql .=
"description,";
313 $sql .=
"date_debut,";
317 $sql .=
"fk_validator,";
319 $sql .=
"fk_user_create,";
321 $sql .=
") VALUES (";
323 $sql .=
" ".((int) $this->fk_user).
",";
324 $sql .=
" '".$this->db->idate($now).
"',";
325 $sql .=
" '".$this->db->escape($this->
description).
"',";
326 $sql .=
" '".$this->db->idate($this->date_debut).
"',";
327 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
328 $sql .=
" ".((int) $this->halfday).
",";
330 $sql .=
" ".((int) $this->fk_validator).
",";
331 $sql .=
" ".((int) $this->fk_type).
",";
332 $sql .=
" ".((int) $user->id).
",";
333 $sql .=
" ".((int) $conf->entity);
338 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
339 $resql = $this->db->query($sql);
342 $this->errors[] =
"Error ".$this->db->lasterror();
346 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday");
350 $initialref =
'(PROV'.$this->id.
')';
351 if (!empty($this->
ref)) {
352 $initialref = $this->ref;
355 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"holiday SET ref='".$this->db->escape($initialref).
"' WHERE rowid=".((int) $this->
id);
356 if ($this->db->query($sql)) {
357 $this->
ref = $initialref;
366 if (!$error && !$notrigger) {
380 foreach ($this->errors as $errmsg) {
381 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
382 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
384 $this->db->rollback();
400 public function fetch($id, $ref =
'')
403 $sql .=
" cp.rowid,";
405 $sql .=
" cp.fk_user,";
406 $sql .=
" cp.date_create,";
407 $sql .=
" cp.description,";
408 $sql .=
" cp.date_debut,";
409 $sql .=
" cp.date_fin,";
410 $sql .=
" cp.halfday,";
411 $sql .=
" cp.statut as status,";
412 $sql .=
" cp.fk_validator,";
413 $sql .=
" cp.date_valid,";
414 $sql .=
" cp.fk_user_valid,";
415 $sql .=
" cp.date_approval,";
416 $sql .=
" cp.fk_user_approve,";
417 $sql .=
" cp.date_refuse,";
418 $sql .=
" cp.fk_user_refuse,";
419 $sql .=
" cp.date_cancel,";
420 $sql .=
" cp.fk_user_cancel,";
421 $sql .=
" cp.detail_refuse,";
422 $sql .=
" cp.note_private,";
423 $sql .=
" cp.note_public,";
424 $sql .=
" cp.fk_user_create,";
425 $sql .=
" cp.fk_type,";
426 $sql .=
" cp.entity";
427 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
429 $sql .=
" WHERE cp.rowid = ".((int) $id);
431 $sql .=
" WHERE cp.ref = '".$this->db->escape($ref).
"'";
434 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
435 $resql = $this->db->query($sql);
437 if ($this->db->num_rows($resql)) {
438 $obj = $this->db->fetch_object($resql);
440 $this->
id = $obj->rowid;
441 $this->
ref = ($obj->ref ? $obj->ref : $obj->rowid);
442 $this->fk_user = $obj->fk_user;
443 $this->date_create = $this->db->jdate($obj->date_create);
445 $this->date_debut = $this->db->jdate($obj->date_debut);
446 $this->date_fin = $this->db->jdate($obj->date_fin);
447 $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
448 $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
449 $this->halfday = $obj->halfday;
450 $this->
status = $obj->status;
451 $this->
statut = $obj->status;
452 $this->fk_validator = $obj->fk_validator;
453 $this->date_valid = $this->db->jdate($obj->date_valid);
454 $this->fk_user_valid = $obj->fk_user_valid;
455 $this->user_validation_id = $obj->fk_user_valid;
456 $this->date_approval = $this->db->jdate($obj->date_approval);
457 $this->fk_user_approve = $obj->fk_user_approve;
458 $this->date_refuse = $this->db->jdate($obj->date_refuse);
459 $this->fk_user_refuse = $obj->fk_user_refuse;
460 $this->date_cancel = $this->db->jdate($obj->date_cancel);
461 $this->fk_user_cancel = $obj->fk_user_cancel;
462 $this->detail_refuse = $obj->detail_refuse;
463 $this->note_private = $obj->note_private;
464 $this->note_public = $obj->note_public;
465 $this->fk_user_create = $obj->fk_user_create;
466 $this->fk_type = $obj->fk_type;
467 $this->entity = $obj->entity;
475 $this->db->free($resql);
479 $this->error =
"Error ".$this->db->lasterror();
495 $sql .=
" cp.rowid,";
498 $sql .=
" cp.fk_user,";
499 $sql .=
" cp.fk_type,";
500 $sql .=
" cp.date_create,";
501 $sql .=
" cp.description,";
502 $sql .=
" cp.date_debut,";
503 $sql .=
" cp.date_fin,";
504 $sql .=
" cp.halfday,";
505 $sql .=
" cp.statut as status,";
506 $sql .=
" cp.fk_validator,";
507 $sql .=
" cp.date_valid,";
508 $sql .=
" cp.fk_user_valid,";
509 $sql .=
" cp.date_approval,";
510 $sql .=
" cp.fk_user_approve,";
511 $sql .=
" cp.date_refuse,";
512 $sql .=
" cp.fk_user_refuse,";
513 $sql .=
" cp.date_cancel,";
514 $sql .=
" cp.fk_user_cancel,";
515 $sql .=
" cp.detail_refuse,";
517 $sql .=
" uu.lastname as user_lastname,";
518 $sql .=
" uu.firstname as user_firstname,";
519 $sql .=
" uu.login as user_login,";
520 $sql .=
" uu.statut as user_status,";
521 $sql .=
" uu.photo as user_photo,";
523 $sql .=
" ua.lastname as validator_lastname,";
524 $sql .=
" ua.firstname as validator_firstname,";
525 $sql .=
" ua.login as validator_login,";
526 $sql .=
" ua.statut as validator_status,";
527 $sql .=
" ua.photo as validator_photo";
529 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
530 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
531 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
532 $sql .=
" AND cp.fk_user IN (".$this->db->sanitize($user_id).
")";
535 if (!empty($filter)) {
540 if (!empty($order)) {
544 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
545 $resql = $this->db->query($sql);
550 $tab_result = $this->holiday;
551 $num = $this->db->num_rows($resql);
560 $obj = $this->db->fetch_object($resql);
562 $tab_result[$i][
'rowid'] = $obj->rowid;
563 $tab_result[$i][
'id'] = $obj->rowid;
564 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
566 $tab_result[$i][
'fk_user'] = $obj->fk_user;
567 $tab_result[$i][
'fk_type'] = $obj->fk_type;
568 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
569 $tab_result[$i][
'description'] = $obj->description;
570 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
571 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
572 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
573 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
574 $tab_result[$i][
'halfday'] = $obj->halfday;
575 $tab_result[$i][
'statut'] = $obj->status;
576 $tab_result[$i][
'status'] = $obj->status;
577 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
578 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
579 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
580 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
581 $tab_result[$i][
'fk_user_approve'] = $obj->fk_user_approve;
582 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
583 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
584 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
585 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
586 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
588 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
589 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
590 $tab_result[$i][
'user_login'] = $obj->user_login;
591 $tab_result[$i][
'user_statut'] = $obj->user_status;
592 $tab_result[$i][
'user_status'] = $obj->user_status;
593 $tab_result[$i][
'user_photo'] = $obj->user_photo;
595 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
596 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
597 $tab_result[$i][
'validator_login'] = $obj->validator_login;
598 $tab_result[$i][
'validator_statut'] = $obj->validator_status;
599 $tab_result[$i][
'validator_status'] = $obj->validator_status;
600 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
606 $this->holiday = $tab_result;
610 $this->error =
"Error ".$this->db->lasterror();
625 $sql .=
" cp.rowid,";
627 $sql .=
" cp.fk_user,";
628 $sql .=
" cp.fk_type,";
629 $sql .=
" cp.date_create,";
630 $sql .=
" cp.tms as date_modification,";
631 $sql .=
" cp.description,";
632 $sql .=
" cp.date_debut,";
633 $sql .=
" cp.date_fin,";
634 $sql .=
" cp.halfday,";
635 $sql .=
" cp.statut as status,";
636 $sql .=
" cp.fk_validator,";
637 $sql .=
" cp.date_valid,";
638 $sql .=
" cp.fk_user_valid,";
639 $sql .=
" cp.date_approval,";
640 $sql .=
" cp.fk_user_approve,";
641 $sql .=
" cp.date_refuse,";
642 $sql .=
" cp.fk_user_refuse,";
643 $sql .=
" cp.date_cancel,";
644 $sql .=
" cp.fk_user_cancel,";
645 $sql .=
" cp.detail_refuse,";
647 $sql .=
" uu.lastname as user_lastname,";
648 $sql .=
" uu.firstname as user_firstname,";
649 $sql .=
" uu.login as user_login,";
650 $sql .=
" uu.statut as user_status,";
651 $sql .=
" uu.photo as user_photo,";
653 $sql .=
" ua.lastname as validator_lastname,";
654 $sql .=
" ua.firstname as validator_firstname,";
655 $sql .=
" ua.login as validator_login,";
656 $sql .=
" ua.statut as validator_status,";
657 $sql .=
" ua.photo as validator_photo";
659 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
660 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
661 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
664 if (!empty($filter)) {
669 if (!empty($order)) {
673 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
674 $resql = $this->db->query($sql);
679 $tab_result = $this->holiday;
680 $num = $this->db->num_rows($resql);
689 $obj = $this->db->fetch_object($resql);
691 $tab_result[$i][
'rowid'] = $obj->rowid;
692 $tab_result[$i][
'id'] = $obj->rowid;
693 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
695 $tab_result[$i][
'fk_user'] = $obj->fk_user;
696 $tab_result[$i][
'fk_type'] = $obj->fk_type;
697 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
698 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
699 $tab_result[$i][
'description'] = $obj->description;
700 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
701 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
702 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
703 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
704 $tab_result[$i][
'halfday'] = $obj->halfday;
705 $tab_result[$i][
'statut'] = $obj->status;
706 $tab_result[$i][
'status'] = $obj->status;
707 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
708 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
709 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
710 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
711 $tab_result[$i][
'fk_user_approve'] = $obj->fk_user_approve;
712 $tab_result[$i][
'date_refuse'] = $obj->date_refuse;
713 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
714 $tab_result[$i][
'date_cancel'] = $obj->date_cancel;
715 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
716 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
718 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
719 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
720 $tab_result[$i][
'user_login'] = $obj->user_login;
721 $tab_result[$i][
'user_statut'] = $obj->user_status;
722 $tab_result[$i][
'user_status'] = $obj->user_status;
723 $tab_result[$i][
'user_photo'] = $obj->user_photo;
725 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
726 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
727 $tab_result[$i][
'validator_login'] = $obj->validator_login;
728 $tab_result[$i][
'validator_statut'] = $obj->validator_status;
729 $tab_result[$i][
'validator_status'] = $obj->validator_status;
730 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
735 $this->holiday = $tab_result;
739 $this->error =
"Error ".$this->db->lasterror();
752 public function validate($user =
null, $notrigger = 0)
754 global $conf, $langs;
755 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
758 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
760 if ($checkBalance > 0) {
761 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
764 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
770 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref) || $this->
ref == $this->
id)) {
778 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
779 $sql .=
" fk_user_valid = ".((int) $user->id).
",";
780 $sql .=
" date_valid = '".$this->db->idate(
dol_now()).
"',";
781 if (!empty($this->
status) && is_numeric($this->
status)) {
782 $sql .=
" statut = ".((int) $this->
status).
",";
784 $this->error =
'Property status must be a numeric value';
787 $sql .=
" ref = '".$this->db->escape($num).
"'";
788 $sql .=
" WHERE rowid = ".((int) $this->
id);
792 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
793 $resql = $this->db->query($sql);
796 $this->errors[] =
"Error ".$this->db->lasterror();
802 $result = $this->
call_trigger(
'HOLIDAY_VALIDATE', $user);
811 $this->oldref = $this->ref;
814 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
816 $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) .
"'";
817 $sql .=
" WHERE filename LIKE '" . $this->db->escape($this->
ref) .
"%' AND filepath = 'holiday/" . $this->db->escape($this->
ref) .
"' and entity = " . ((int) $conf->entity);
818 $resql = $this->db->query($sql);
821 $this->error = $this->db->lasterror();
823 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'holiday/".$this->db->escape($this->newref).
"'";
824 $sql .=
" WHERE filepath = 'holiday/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
825 $resql = $this->db->query($sql);
828 $this->error = $this->db->lasterror();
834 $dirsource = $conf->holiday->multidir_output[$this->entity] .
'/' . $oldref;
835 $dirdest = $conf->holiday->multidir_output[$this->entity] .
'/' . $newref;
836 if (!$error && file_exists($dirsource)) {
837 dol_syslog(get_class($this) .
"::validate rename dir " . $dirsource .
" into " . $dirdest);
838 if (@rename($dirsource, $dirdest)) {
841 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^' . preg_quote($oldref,
'/'));
842 foreach ($listoffiles as $fileentry) {
843 $dirsource = $fileentry[
'name'];
844 $dirdest = preg_replace(
'/^' . preg_quote($oldref,
'/') .
'/', $newref, $dirsource);
845 $dirsource = $fileentry[
'path'] .
'/' . $dirsource;
846 $dirdest = $fileentry[
'path'] .
'/' . $dirdest;
847 @rename($dirsource, $dirdest);
857 foreach ($this->errors as $errmsg) {
858 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
859 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
861 $this->db->rollback();
877 public function approve($user =
null, $notrigger = 0)
881 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
883 if ($checkBalance > 0) {
884 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
887 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
893 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
894 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
895 if (!empty($this->date_debut)) {
896 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
900 if (!empty($this->date_fin)) {
901 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
905 $sql .=
" halfday = ".((int) $this->halfday).
",";
906 if (!empty($this->
status) && is_numeric($this->
status)) {
907 $sql .=
" statut = ".((int) $this->
status).
",";
911 if (!empty($this->fk_validator)) {
912 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
916 if (!empty($this->date_valid)) {
917 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
919 $sql .=
" date_valid = NULL,";
921 if (!empty($this->fk_user_valid)) {
922 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
924 $sql .=
" fk_user_valid = NULL,";
926 if (!empty($this->date_approval)) {
927 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
929 $sql .=
" date_approval = NULL,";
931 if (!empty($this->fk_user_approve)) {
932 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
934 $sql .=
" fk_user_approve = NULL,";
936 if (!empty($this->date_refuse)) {
937 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
939 $sql .=
" date_refuse = NULL,";
941 if (!empty($this->fk_user_refuse)) {
942 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
944 $sql .=
" fk_user_refuse = NULL,";
946 if (!empty($this->date_cancel)) {
947 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
949 $sql .=
" date_cancel = NULL,";
951 if (!empty($this->fk_user_cancel)) {
952 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
954 $sql .=
" fk_user_cancel = NULL,";
956 if (!empty($this->detail_refuse)) {
957 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
959 $sql .=
" detail_refuse = NULL";
961 $sql .=
" WHERE rowid = ".((int) $this->
id);
965 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
966 $resql = $this->db->query($sql);
969 $this->errors[] =
"Error ".$this->db->lasterror();
975 $result = $this->
call_trigger(
'HOLIDAY_APPROVE', $user);
985 foreach ($this->errors as $errmsg) {
986 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
987 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
989 $this->db->rollback();
1004 public function update($user =
null, $notrigger = 0)
1006 global $conf, $langs;
1009 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
1011 if ($checkBalance > 0 && $this->
status != self::STATUS_DRAFT) {
1012 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
1015 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1021 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
1023 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
1025 if (!empty($this->date_debut)) {
1026 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
1030 if (!empty($this->date_fin)) {
1031 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
1035 $sql .=
" halfday = ".$this->halfday.
",";
1036 if (!empty($this->
status) && is_numeric($this->
status)) {
1037 $sql .=
" statut = ".$this->status.
",";
1041 if (!empty($this->fk_validator)) {
1042 $sql .=
" fk_validator = '".$this->db->escape($this->fk_validator).
"',";
1046 if (!empty($this->date_valid)) {
1047 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1049 $sql .=
" date_valid = NULL,";
1051 if (!empty($this->fk_user_valid)) {
1052 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
1054 $sql .=
" fk_user_valid = NULL,";
1056 if (!empty($this->date_approval)) {
1057 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
1059 $sql .=
" date_approval = NULL,";
1061 if (!empty($this->fk_user_approve)) {
1062 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
1064 $sql .=
" fk_user_approve = NULL,";
1066 if (!empty($this->date_refuse)) {
1067 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
1069 $sql .=
" date_refuse = NULL,";
1071 if (!empty($this->fk_user_refuse)) {
1072 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
1074 $sql .=
" fk_user_refuse = NULL,";
1076 if (!empty($this->date_cancel)) {
1077 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
1079 $sql .=
" date_cancel = NULL,";
1081 if (!empty($this->fk_user_cancel)) {
1082 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
1084 $sql .=
" fk_user_cancel = NULL,";
1086 if (!empty($this->detail_refuse)) {
1087 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1089 $sql .=
" detail_refuse = NULL";
1092 $sql .=
" WHERE rowid = ".((int) $this->
id);
1096 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1097 $resql = $this->db->query($sql);
1100 $this->errors[] =
"Error ".$this->db->lasterror();
1106 $result = $this->
call_trigger(
'HOLIDAY_MODIFY', $user);
1116 foreach ($this->errors as $errmsg) {
1117 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1118 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1120 $this->db->rollback();
1123 $this->db->commit();
1136 public function delete($user, $notrigger = 0)
1138 global $conf, $langs;
1141 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1142 $sql .=
" WHERE rowid=".((int) $this->
id);
1146 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1147 $resql = $this->db->query($sql);
1150 $this->errors[] =
"Error ".$this->db->lasterror();
1156 $result = $this->
call_trigger(
'HOLIDAY_DELETE', $user);
1166 foreach ($this->errors as $errmsg) {
1167 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1168 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1170 $this->db->rollback();
1173 $this->db->commit();
1195 foreach ($this->holiday as $infos_CP) {
1206 if ($halfday == 0) {
1207 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1210 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1213 } elseif ($halfday == -1) {
1215 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1216 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1220 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1221 if ($dateStart < $dateEnd) {
1224 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1228 } elseif ($halfday == 1) {
1230 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1231 if ($dateStart < $dateEnd) {
1234 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1238 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1239 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1243 } elseif ($halfday == 2) {
1245 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1246 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1250 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1251 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1256 dol_print_error(
null,
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1275 $isavailablemorning =
true;
1276 $isavailableafternoon =
true;
1279 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1280 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1281 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1282 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1283 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->db->idate($timestamp).
"'";
1284 if ($status !=
'-1') {
1285 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1288 $resql = $this->db->query($sql);
1290 $num_rows = $this->db->num_rows($resql);
1291 if ($num_rows > 0) {
1292 $arrayofrecord = array();
1294 while ($i < $num_rows) {
1295 $obj = $this->db->fetch_object($resql);
1298 $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);
1303 $isavailablemorning =
true;
1304 foreach ($arrayofrecord as $record) {
1305 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1308 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1311 $isavailablemorning =
false;
1314 $isavailableafternoon =
true;
1315 foreach ($arrayofrecord as $record) {
1316 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1319 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1322 $isavailableafternoon =
false;
1330 $result = array(
'morning' => $isavailablemorning,
'afternoon' => $isavailableafternoon);
1331 if (!$isavailablemorning) {
1332 $result[
'morning_reason'] =
'leave_request';
1334 if (!$isavailableafternoon) {
1335 $result[
'afternoon_reason'] =
'leave_request';
1351 $langs->load(
'holiday');
1352 $nofetch = !empty($params[
'nofetch']);
1355 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1356 if (isset($this->
status)) {
1357 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1359 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1361 if (!$nofetch && !empty($this->fk_type)) {
1362 $typeleaves = $this->
getTypes(1, -1);
1363 if (empty($typeleaves[$this->fk_type])) {
1364 $labeltoshow = $langs->trans(
"TypeWasDisabledOrRemoved", $this->fk_type);
1366 $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']);
1368 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type") .
':</b> ' . $labeltoshow;
1370 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1371 $listhalfday = array(
1372 'morning' => $langs->trans(
"Morning"),
1373 "afternoon" => $langs->trans(
"Afternoon")
1375 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ?
'afternoon' :
'morning';
1376 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ?
'morning' :
'afternoon';
1377 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateDebCP') .
'</b>: '.
dol_print_date($this->date_debut,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1378 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateFinCP') .
'</b>: '.
dol_print_date($this->date_fin,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1394 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1396 global $conf, $langs, $hookmanager;
1398 if (!empty($conf->dol_no_mouse_hover)) {
1405 'objecttype' => $this->element,
1408 $classfortooltip =
'classfortooltip';
1411 $classfortooltip =
'classforajaxtooltip';
1412 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1418 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1423 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1424 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1425 $add_save_lastsearch_values = 1;
1427 if ($add_save_lastsearch_values) {
1428 $url .=
'&save_lastsearch_values=1';
1433 if (empty($notooltip)) {
1435 $label = $langs->trans(
"ShowMyObject");
1436 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1438 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1439 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1441 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1444 $linkstart =
'<a href="'.$url.
'"';
1445 $linkstart .= $linkclose.
'>';
1448 $result .= $linkstart;
1451 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1453 if ($withpicto != 2) {
1454 $result .= $this->ref;
1456 $result .= $linkend;
1459 $hookmanager->initHooks(array($this->element .
'dao'));
1460 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1461 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1463 $result = $hookmanager->resPrint;
1465 $result .= $hookmanager->resPrint;
1491 public function LibStatut($status, $mode = 0, $startdate =
'')
1496 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1504 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1512 $statusType =
'status6';
1513 if (!empty($startdate) && $startdate >=
dol_now()) {
1514 $statusType =
'status4';
1515 $params = array(
'tooltip' => $this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1517 if ($status == self::STATUS_DRAFT) {
1518 $statusType =
'status0';
1520 if ($status == self::STATUS_VALIDATED) {
1521 $statusType =
'status1';
1523 if ($status == self::STATUS_CANCELED) {
1524 $statusType =
'status9';
1526 if ($status == self::STATUS_REFUSED) {
1527 $statusType =
'status9';
1530 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1542 public function selectStatutCP($selected = 0, $htmlname =
'select_statut', $morecss =
'minwidth125')
1547 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1548 $nb = count($name) + 1;
1551 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1552 $out .=
'<option value="-1"> </option>'.
"\n";
1555 for ($i = 1; $i < $nb; $i++) {
1556 if ($i == $selected) {
1557 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1559 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1563 $out .=
"</select>\n";
1566 $out .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($showempty < 0 ? (
string) $showempty :
'-1'), $morecss);
1580 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1581 $sql .=
" value = '".$this->db->escape($value).
"'";
1582 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1584 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1585 $result = $this->db->query($sql);
1603 $sql =
"SELECT value";
1604 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1605 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1607 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1608 $result = $this->db->query($sql);
1611 $obj = $this->db->fetch_object($result);
1614 if ($createifnotfound) {
1615 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1616 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->db->escape($createifnotfound).
"')";
1617 $result = $this->db->query($sql);
1619 return $createifnotfound;
1621 $this->error = $this->db->lasterror();
1632 $this->error = $this->db->lasterror();
1647 global $user, $langs;
1651 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1652 $langs->load(
"holiday");
1657 $month = date(
'm', $now);
1661 $lastUpdate = $this->
getConfCP(
'lastUpdate', $newdateforlastupdate);
1662 $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
1666 if ($month != $monthLastUpdate) {
1669 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1670 $nbUser = count($users);
1672 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1673 $sql .=
" value = '".$this->db->escape($newdateforlastupdate).
"'";
1674 $sql .=
" WHERE name = 'lastUpdate'";
1675 $result = $this->db->query($sql);
1677 $typeleaves = $this->
getTypes(1, 1);
1680 foreach ($users as $userCounter) {
1681 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1682 if (empty($nbDaysToAdd)) {
1686 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1688 $nowHoliday = $userCounter[
'nb_holiday'];
1689 $newSolde = $nowHoliday + $nbDaysToAdd;
1692 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidaysMonthlyUpdate'), $newSolde, $userCounter[
'type']);
1694 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1703 $this->db->commit();
1706 $this->db->rollback();
1716 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1717 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1718 $resql = $this->db->query($sql);
1720 $num = $this->db->num_rows($resql);
1724 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1725 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1726 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1727 $result = $this->db->query($sql);
1730 $this->errors[] = $this->db->lasterror();
1734 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1735 $sql .= ((float) $nbHoliday);
1736 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1737 $result = $this->db->query($sql);
1740 $this->errors[] = $this->db->lasterror();
1744 $this->errors[] = $this->db->lasterror();
1767 dol_syslog(get_class($this).
'::createCPusers');
1768 $arrayofusers = $this->
fetchUsers(
false,
true);
1770 foreach ($arrayofusers as $users) {
1771 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1772 $sql .=
" (fk_user, nb_holiday)";
1773 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1775 $resql = $this->db->query($sql);
1781 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1782 $sql .=
" (fk_user, nb_holiday)";
1783 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1785 $resql = $this->db->query($sql);
1801 $sql =
"SELECT nb_holiday";
1802 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1803 $sql .=
" WHERE fk_user = ".(int) $user_id;
1805 $sql .=
" AND fk_type = ".(int) $fk_type;
1808 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1809 $result = $this->db->query($sql);
1811 $obj = $this->db->fetch_object($result);
1814 return $obj->nb_holiday;
1831 public function fetchUsers($stringlist =
true, $type =
true, $filters =
'')
1835 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1841 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1842 $sql .=
" DISTINCT";
1845 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1847 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1848 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1849 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1850 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1851 $sql .=
" OR u.entity = 0)";
1853 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1855 $sql .=
" AND u.statut > 0";
1856 $sql .=
" AND u.employee = 1";
1861 $resql = $this->db->query($sql);
1866 $num = $this->db->num_rows($resql);
1871 $obj = $this->db->fetch_object($resql);
1874 $stringlist .= $obj->rowid;
1876 $stringlist .=
', '.$obj->rowid;
1885 $this->error =
"Error ".$this->db->lasterror();
1890 $sql =
"SELECT DISTINCT cpu.fk_user";
1891 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1892 $sql .=
" WHERE cpu.fk_user = u.rowid";
1897 $resql = $this->db->query($sql);
1902 $num = $this->db->num_rows($resql);
1907 $obj = $this->db->fetch_object($resql);
1910 $stringlist .= $obj->fk_user;
1912 $stringlist .=
', '.$obj->fk_user;
1921 $this->error =
"Error ".$this->db->lasterror();
1931 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1932 $sql .=
" DISTINCT";
1934 $sql .=
" u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut as status, u.fk_user";
1935 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1937 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1938 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1939 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1940 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1941 $sql .=
" OR u.entity = 0)";
1943 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1946 $sql .=
" AND u.statut > 0";
1947 $sql .=
" AND u.employee = 1";
1952 $resql = $this->db->query($sql);
1957 $tab_result = $this->holiday;
1958 $num = $this->db->num_rows($resql);
1962 $obj = $this->db->fetch_object($resql);
1964 $tab_result[$i][
'rowid'] = $obj->rowid;
1965 $tab_result[$i][
'id'] = $obj->rowid;
1966 $tab_result[$i][
'name'] = $obj->lastname;
1967 $tab_result[$i][
'lastname'] = $obj->lastname;
1968 $tab_result[$i][
'firstname'] = $obj->firstname;
1969 $tab_result[$i][
'gender'] = $obj->gender;
1970 $tab_result[$i][
'status'] = $obj->status;
1971 $tab_result[$i][
'employee'] = $obj->employee;
1972 $tab_result[$i][
'photo'] = $obj->photo;
1973 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1983 $this->errors[] =
"Error ".$this->db->lasterror();
1988 $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";
1989 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1990 $sql .=
" WHERE cpu.fk_user = u.rowid";
1995 $resql = $this->db->query($sql);
2000 $tab_result = $this->holiday;
2001 $num = $this->db->num_rows($resql);
2005 $obj = $this->db->fetch_object($resql);
2007 $tab_result[$i][
'rowid'] = $obj->rowid;
2008 $tab_result[$i][
'id'] = $obj->rowid;
2009 $tab_result[$i][
'name'] = $obj->lastname;
2010 $tab_result[$i][
'lastname'] = $obj->lastname;
2011 $tab_result[$i][
'firstname'] = $obj->firstname;
2012 $tab_result[$i][
'gender'] = $obj->gender;
2013 $tab_result[$i][
'status'] = $obj->status;
2014 $tab_result[$i][
'employee'] = $obj->employee;
2015 $tab_result[$i][
'photo'] = $obj->photo;
2016 $tab_result[$i][
'fk_user'] = $obj->fk_user;
2018 $tab_result[$i][
'type'] = $obj->fk_type;
2019 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
2027 $this->error =
"Error ".$this->db->lasterror();
2045 $users_validator = array();
2047 $sql =
"SELECT DISTINCT ur.fk_user";
2048 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2049 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2051 $sql .=
" SELECT DISTINCT ugu.fk_user";
2052 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2053 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2056 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
2057 $result = $this->db->query($sql);
2059 $num_rows = $this->db->num_rows($result);
2061 while ($i < $num_rows) {
2062 $objp = $this->db->fetch_object($result);
2063 array_push($users_validator, $objp->fk_user);
2066 return $users_validator;
2068 $this->error = $this->db->lasterror();
2069 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2082 $sql =
"SELECT count(u.rowid) as compteur";
2083 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2084 $sql .=
" WHERE u.statut > 0";
2086 $result = $this->db->query($sql);
2087 $object = $this->db->fetch_object($result);
2098 $sql =
"SELECT count(u.rowid) as compteur";
2099 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2100 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2102 $result = $this->db->query($sql);
2103 $object = $this->db->fetch_object($result);
2117 if (empty($userCP)) {
2120 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2135 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2137 global $conf, $langs;
2145 if ($prev_solde == $new_solde) {
2152 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2153 $sql .=
"date_action,";
2154 $sql .=
"fk_user_action,";
2155 $sql .=
"fk_user_update,";
2156 $sql .=
"type_action,";
2157 $sql .=
"prev_solde,";
2158 $sql .=
"new_solde,";
2160 $sql .=
") VALUES (";
2161 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2162 $sql .=
" ".((int) $fk_user_action).
",";
2163 $sql .=
" ".((int) $fk_user_update).
",";
2164 $sql .=
" '".$this->db->escape($label).
"',";
2165 $sql .=
" ".((float) $prev_solde).
",";
2166 $sql .=
" ".((float) $new_solde).
",";
2167 $sql .=
" ".((int) $fk_type);
2170 $resql = $this->db->query($sql);
2173 $this->errors[] =
"Error ".$this->db->lasterror();
2177 $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2182 foreach ($this->errors as $errmsg) {
2183 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2184 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2186 $this->db->rollback();
2189 $this->db->commit();
2190 return $this->optRowid;
2204 $sql .=
" cpl.rowid,";
2205 $sql .=
" cpl.date_action,";
2206 $sql .=
" cpl.fk_user_action,";
2207 $sql .=
" cpl.fk_user_update,";
2208 $sql .=
" cpl.type_action,";
2209 $sql .=
" cpl.prev_solde,";
2210 $sql .=
" cpl.new_solde,";
2211 $sql .=
" cpl.fk_type";
2212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2213 $sql .=
" WHERE cpl.rowid > 0";
2216 if (!empty($filter)) {
2217 $sql .=
" ".$filter;
2221 if (!empty($order)) {
2225 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2226 $resql = $this->db->query($sql);
2231 $tab_result = $this->logs;
2232 $num = $this->db->num_rows($resql);
2241 $obj = $this->db->fetch_object($resql);
2243 $tab_result[$i][
'rowid'] = $obj->rowid;
2244 $tab_result[$i][
'id'] = $obj->rowid;
2245 $tab_result[$i][
'date_action'] = $obj->date_action;
2246 $tab_result[$i][
'fk_user_action'] = $obj->fk_user_action;
2247 $tab_result[$i][
'fk_user_update'] = $obj->fk_user_update;
2248 $tab_result[$i][
'type_action'] = $obj->type_action;
2249 $tab_result[$i][
'prev_solde'] = $obj->prev_solde;
2250 $tab_result[$i][
'new_solde'] = $obj->new_solde;
2251 $tab_result[$i][
'fk_type'] = $obj->fk_type;
2256 $this->logs = $tab_result;
2260 $this->error =
"Error ".$this->db->lasterror();
2277 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2278 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2279 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).
')';
2280 $sql .=
" AND entity IN (".getEntity(
'c_holiday_types').
")";
2282 $sql .=
" AND active = ".((int) $active);
2285 $sql .=
" AND affect = ".((int) $affect);
2287 $sql .=
" ORDER BY sortorder";
2289 $result = $this->db->query($sql);
2291 $num = $this->db->num_rows($result);
2294 while ($obj = $this->db->fetch_object($result)) {
2295 $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);
2318 $sql =
"SELECT f.rowid, f.statut as status,";
2319 $sql .=
" f.date_create as datec,";
2320 $sql .=
" f.tms as date_modification,";
2321 $sql .=
" f.date_valid as datev,";
2322 $sql .=
" f.date_approval as datea,";
2323 $sql .=
" f.date_refuse as dater,";
2324 $sql .=
" f.fk_user_create as fk_user_creation,";
2325 $sql .=
" f.fk_user_modif as fk_user_modification,";
2326 $sql .=
" f.fk_user_valid as fk_user_validation,";
2327 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2328 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2329 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2330 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2331 $sql .=
" WHERE f.rowid = ".((int) $id);
2332 $sql .=
" AND f.entity = ".$conf->entity;
2334 $resql = $this->db->query($sql);
2336 if ($this->db->num_rows($resql)) {
2337 $obj = $this->db->fetch_object($resql);
2339 $this->
id = $obj->rowid;
2341 $this->date_creation = $this->db->jdate($obj->datec);
2342 $this->date_modification = $this->db->jdate($obj->date_modification);
2343 $this->date_validation = $this->db->jdate($obj->datev);
2344 $this->date_approval = $this->db->jdate($obj->datea);
2346 $this->user_creation_id = $obj->fk_user_creation;
2347 $this->user_validation_id = $obj->fk_user_validation;
2348 $this->user_modification_id = $obj->fk_user_modification;
2351 if ($obj->fk_user_approval_done) {
2352 $this->fk_user_approve = $obj->fk_user_approval_done;
2356 $this->db->free($resql);
2372 global $user, $langs;
2376 $this->specimen = 1;
2378 $this->fk_user = $user->id;
2380 $this->date_debut =
dol_now();
2381 $this->date_fin =
dol_now() + (24 * 3600);
2382 $this->date_valid =
dol_now();
2383 $this->fk_validator = $user->id;
2400 $this->nb = array();
2402 $sql =
"SELECT count(h.rowid) as nb";
2403 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2404 $sql .=
" WHERE h.statut > 1";
2405 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2406 if (!$user->hasRight(
'expensereport',
'readall')) {
2407 $userchildids = $user->getAllChildIds(1);
2408 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2409 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2412 $resql = $this->db->query($sql);
2414 while ($obj = $this->db->fetch_object($resql)) {
2415 $this->nb[
"holidays"] = $obj->nb;
2417 $this->db->free($resql);
2421 $this->error = $this->db->error();
2436 global $conf, $langs;
2444 $sql =
"SELECT h.rowid, h.date_debut";
2445 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2446 $sql .=
" WHERE h.statut = 2";
2447 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2448 if (!$user->hasRight(
'expensereport',
'read_all')) {
2449 $userchildids = $user->getAllChildIds(1);
2450 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2451 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2454 $resql = $this->db->query($sql);
2456 $langs->load(
"members");
2459 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2460 $response->label = $langs->trans(
"HolidaysToApprove");
2461 $response->labelShort = $langs->trans(
"ToApprove");
2462 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2465 while ($obj = $this->db->fetch_object($resql)) {
2466 $response->nbtodo++;
2468 if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2469 $response->nbtodolate++;
2476 $this->error = $this->db->error();
2491 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2493 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2494 $return .=
'<div class="info-box info-box-sm">';
2495 $return .=
'<span class="info-box-icon bg-infobox-action">';
2497 $return .=
'</span>';
2498 $return .=
'<div class="info-box-content">';
2499 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$arraydata[
'user']->getNomUrl(-1).
'</span>';
2500 if ($selected >= 0) {
2501 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2503 if (property_exists($this,
'fk_type')) {
2506 $return .=
'<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata[
'labeltype']).
'">'.
dol_escape_htmltag($arraydata[
'labeltype']).
'</div>';
2508 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2509 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_debut,
'day').
'</span>';
2510 $return .=
' <span class="opacitymedium small">'.$langs->trans(
"To").
'</span> ';
2511 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_fin,
'day').
'</span>';
2512 if (!empty($arraydata[
'nbopenedday'])) {
2513 $return .=
' ('.$arraydata[
'nbopenedday'].
')';
2516 if (method_exists($this,
'getLibStatut')) {
2517 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2519 $return .=
'</div>';
2520 $return .=
'</div>';
2521 $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 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.
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 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($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 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 TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut