30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $element =
'holiday';
47 public $TRIGGER_PREFIX =
'HOLIDAY';
52 public $table_element =
'holiday';
57 public $fk_element =
'fk_holiday';
62 public $picto =
'holiday';
72 public $date_create =
'';
82 public $date_debut =
'';
87 public $date_fin =
'';
92 public $date_debut_gmt =
'';
97 public $date_fin_gmt =
'';
102 public $halfday =
'';
113 public $fk_validator;
118 public $date_valid = 0;
123 public $fk_user_valid;
128 public $date_approval;
133 public $fk_user_approve;
138 public $user_approve_id;
143 public $date_refuse = 0;
148 public $fk_user_refuse;
153 public $date_cancel = 0;
158 public $fk_user_cancel;
163 public $fk_user_create;
168 public $detail_refuse =
'';
178 public $holiday = array();
183 public $events = array();
188 public $logs = array();
222 $this->ismultientitymanaged = 0;
233 public function getNextNumRef($objsoc)
235 global $langs,
$conf;
236 $langs->load(
"order");
239 $conf->global->HOLIDAY_ADDON =
'mod_holiday_madonna';
249 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
250 foreach ($dirmodels as $reldir) {
254 $mybool = ((bool) @include_once $dir.$file) || $mybool;
258 dol_print_error(
null,
"Failed to include file ".$file);
262 $obj =
new $classname();
263 '@phan-var-force ModelNumRefHolidays $obj';
265 $numref = $obj->getNextValue($objsoc, $this);
270 $this->error = $obj->error;
275 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_HOLIDAY_ADDON_NotDefined");
299 $this->db->rollback();
311 public function create($user, $notrigger = 0)
319 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
320 $this->error =
"ErrorBadParameterFkUser";
323 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
324 $this->error =
"ErrorBadParameterFkValidator";
327 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
328 $this->error =
"ErrorBadParameterFkType";
333 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday(";
336 $sql .=
"date_create,";
337 $sql .=
"description,";
338 $sql .=
"date_debut,";
342 $sql .=
"fk_validator,";
344 $sql .=
"fk_user_create,";
346 $sql .=
") VALUES (";
348 $sql .=
" ".((int) $this->fk_user).
",";
349 $sql .=
" '".$this->db->idate($now).
"',";
350 $sql .=
" '".$this->db->escape($this->
description).
"',";
351 $sql .=
" '".$this->db->idate($this->date_debut).
"',";
352 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
353 $sql .=
" ".((int) $this->halfday).
",";
355 $sql .=
" ".((int) $this->fk_validator).
",";
356 $sql .=
" ".((int) $this->fk_type).
",";
357 $sql .=
" ".((int) $user->id).
",";
358 $sql .=
" ".((int)
$conf->entity);
363 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
364 $resql = $this->db->query($sql);
367 $this->errors[] =
"Error ".$this->db->lasterror();
371 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday");
375 $initialref =
'(PROV'.$this->id.
')';
376 if (!empty($this->
ref)) {
377 $initialref = $this->ref;
380 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"holiday SET ref='".$this->db->escape($initialref).
"' WHERE rowid=".((int) $this->
id);
381 if ($this->db->query($sql)) {
382 $this->
ref = $initialref;
388 if (!$error && !$notrigger) {
390 $result = $this->call_trigger(
'HOLIDAY_CREATE', $user);
402 foreach ($this->errors as $errmsg) {
403 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
404 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
406 $this->db->rollback();
422 public function fetch($id, $ref =
'')
425 $sql .=
" cp.rowid,";
427 $sql .=
" cp.fk_user,";
428 $sql .=
" cp.date_create,";
429 $sql .=
" cp.description,";
430 $sql .=
" cp.date_debut,";
431 $sql .=
" cp.date_fin,";
432 $sql .=
" cp.halfday,";
433 $sql .=
" cp.statut as status,";
434 $sql .=
" cp.fk_validator,";
435 $sql .=
" cp.date_valid,";
436 $sql .=
" cp.fk_user_valid,";
437 $sql .=
" cp.date_approval,";
438 $sql .=
" cp.fk_user_approve,";
439 $sql .=
" cp.date_refuse,";
440 $sql .=
" cp.fk_user_refuse,";
441 $sql .=
" cp.date_cancel,";
442 $sql .=
" cp.fk_user_cancel,";
443 $sql .=
" cp.detail_refuse,";
444 $sql .=
" cp.note_private,";
445 $sql .=
" cp.note_public,";
446 $sql .=
" cp.fk_user_create,";
447 $sql .=
" cp.fk_type,";
448 $sql .=
" cp.entity";
449 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
451 $sql .=
" WHERE cp.rowid = ".((int) $id);
453 $sql .=
" WHERE cp.ref = '".$this->db->escape($ref).
"'";
456 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
457 $resql = $this->db->query($sql);
459 if ($this->db->num_rows($resql)) {
460 $obj = $this->db->fetch_object($resql);
462 $this->
id = (int) $obj->rowid;
463 $this->
ref = (string) ($obj->ref ? $obj->ref : $obj->rowid);
464 $this->fk_user = (int) $obj->fk_user;
465 $this->date_create = $this->db->jdate($obj->date_create);
468 $this->date_debut = $this->db->jdate($obj->date_debut);
469 $this->date_fin = $this->db->jdate($obj->date_fin);
470 $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
471 $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
473 $this->halfday = (int) $obj->halfday;
474 $this->
status = (int) $obj->status;
475 $this->statut = (int) $obj->status;
476 $this->fk_validator = $obj->fk_validator;
477 $this->date_valid = $this->db->jdate($obj->date_valid);
478 $this->fk_user_valid = $obj->fk_user_valid;
479 $this->user_validation_id = $obj->fk_user_valid;
480 $this->date_approval = $this->db->jdate($obj->date_approval);
481 $this->fk_user_approve = $obj->fk_user_approve;
482 $this->date_refuse = $this->db->jdate($obj->date_refuse);
483 $this->fk_user_refuse = $obj->fk_user_refuse;
484 $this->date_cancel = $this->db->jdate($obj->date_cancel);
485 $this->fk_user_cancel = $obj->fk_user_cancel;
486 $this->detail_refuse = $obj->detail_refuse;
487 $this->note_private = $obj->note_private;
488 $this->note_public = $obj->note_public;
489 $this->fk_user_create = $obj->fk_user_create;
490 $this->fk_type = $obj->fk_type;
491 $this->entity = $obj->entity;
499 $this->db->free($resql);
503 $this->error =
"Error ".$this->db->lasterror();
520 $sql .=
" cp.rowid,";
523 $sql .=
" cp.fk_user,";
524 $sql .=
" cp.fk_type,";
525 $sql .=
" cp.date_create,";
526 $sql .=
" cp.tms as date_modification,";
527 $sql .=
" cp.description,";
528 $sql .=
" cp.date_debut,";
529 $sql .=
" cp.date_fin,";
530 $sql .=
" cp.halfday,";
531 $sql .=
" cp.statut as status,";
532 $sql .=
" cp.fk_validator,";
533 $sql .=
" cp.date_valid,";
534 $sql .=
" cp.fk_user_valid,";
535 $sql .=
" cp.date_approval,";
536 $sql .=
" cp.fk_user_approve,";
537 $sql .=
" cp.date_refuse,";
538 $sql .=
" cp.fk_user_refuse,";
539 $sql .=
" cp.date_cancel,";
540 $sql .=
" cp.fk_user_cancel,";
541 $sql .=
" cp.detail_refuse,";
543 $sql .=
" uu.lastname as user_lastname,";
544 $sql .=
" uu.firstname as user_firstname,";
545 $sql .=
" uu.login as user_login,";
546 $sql .=
" uu.statut as user_status,";
547 $sql .=
" uu.photo as user_photo,";
548 $sql .=
" uu.fk_country as country_id,";
550 $sql .=
" ua.lastname as validator_lastname,";
551 $sql .=
" ua.firstname as validator_firstname,";
552 $sql .=
" ua.login as validator_login,";
553 $sql .=
" ua.statut as validator_status,";
554 $sql .=
" ua.photo as validator_photo";
556 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
557 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
558 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
559 $sql .=
" AND cp.fk_user IN (".$this->db->sanitize($user_id).
")";
562 if (!empty($filter)) {
567 if (!empty($order)) {
571 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
572 $resql = $this->db->query($sql);
577 $tab_result = $this->holiday;
578 $num = $this->db->num_rows($resql);
587 $obj = $this->db->fetch_object($resql);
589 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
590 $tab_result[$i][
'id'] = (int) $obj->rowid;
591 $tab_result[$i][
'ref'] = (string) ($obj->ref ? $obj->ref : $obj->rowid);
593 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
594 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
595 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
596 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
597 $tab_result[$i][
'description'] = (string) $obj->description;
598 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
599 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
600 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
601 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
602 $tab_result[$i][
'halfday'] = (int) $obj->halfday;
603 $tab_result[$i][
'statut'] = (int) $obj->status;
604 $tab_result[$i][
'status'] = (int) $obj->status;
605 $tab_result[$i][
'fk_validator'] = (int) $obj->fk_validator;
606 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
607 $tab_result[$i][
'fk_user_valid'] = (int) $obj->fk_user_valid;
608 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
609 $tab_result[$i][
'fk_user_approve'] = (int) $obj->fk_user_approve;
610 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
611 $tab_result[$i][
'fk_user_refuse'] = (int) $obj->fk_user_refuse;
612 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
613 $tab_result[$i][
'fk_user_cancel'] = (int) $obj->fk_user_cancel;
614 $tab_result[$i][
'detail_refuse'] = (string) $obj->detail_refuse;
616 $tab_result[$i][
'user_firstname'] = (string) $obj->user_firstname;
617 $tab_result[$i][
'user_lastname'] = (string) $obj->user_lastname;
618 $tab_result[$i][
'user_login'] = (string) $obj->user_login;
619 $tab_result[$i][
'user_statut'] = (int) $obj->user_status;
620 $tab_result[$i][
'user_status'] = (int) $obj->user_status;
621 $tab_result[$i][
'user_photo'] = (string) $obj->user_photo;
623 $tab_result[$i][
'validator_firstname'] = (string) $obj->validator_firstname;
624 $tab_result[$i][
'validator_lastname'] = (string) $obj->validator_lastname;
625 $tab_result[$i][
'validator_login'] = (string) $obj->validator_login;
626 $tab_result[$i][
'validator_statut'] = (int) $obj->validator_status;
627 $tab_result[$i][
'validator_status'] = (int) $obj->validator_status;
628 $tab_result[$i][
'validator_photo'] = (string) $obj->validator_photo;
630 $tab_result[$i][
'country_id'] = (int) $obj->country_id;
636 $this->holiday = $tab_result;
640 $this->error =
"Error ".$this->db->lasterror();
655 $sql .=
" cp.rowid,";
657 $sql .=
" cp.fk_user,";
658 $sql .=
" cp.fk_type,";
659 $sql .=
" cp.date_create,";
660 $sql .=
" cp.tms as date_modification,";
661 $sql .=
" cp.description,";
662 $sql .=
" cp.date_debut,";
663 $sql .=
" cp.date_fin,";
664 $sql .=
" cp.halfday,";
665 $sql .=
" cp.statut as status,";
666 $sql .=
" cp.fk_validator,";
667 $sql .=
" cp.date_valid,";
668 $sql .=
" cp.fk_user_valid,";
669 $sql .=
" cp.date_approval,";
670 $sql .=
" cp.fk_user_approve,";
671 $sql .=
" cp.date_refuse,";
672 $sql .=
" cp.fk_user_refuse,";
673 $sql .=
" cp.date_cancel,";
674 $sql .=
" cp.fk_user_cancel,";
675 $sql .=
" cp.detail_refuse,";
677 $sql .=
" uu.lastname as user_lastname,";
678 $sql .=
" uu.firstname as user_firstname,";
679 $sql .=
" uu.login as user_login,";
680 $sql .=
" uu.statut as user_status,";
681 $sql .=
" uu.photo as user_photo,";
683 $sql .=
" ua.lastname as validator_lastname,";
684 $sql .=
" ua.firstname as validator_firstname,";
685 $sql .=
" ua.login as validator_login,";
686 $sql .=
" ua.statut as validator_status,";
687 $sql .=
" ua.photo as validator_photo";
689 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
690 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
691 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
694 if (!empty($sqlFilter)) {
699 if (!empty($sqlOrder)) {
703 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
704 $resql = $this->db->query($sql);
709 $tab_result = $this->holiday;
710 $num = $this->db->num_rows($resql);
719 $obj = $this->db->fetch_object($resql);
721 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
722 $tab_result[$i][
'id'] = (int) $obj->rowid;
723 $tab_result[$i][
'ref'] = (string) ($obj->ref ? $obj->ref : $obj->rowid);
725 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
726 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
727 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
728 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
729 $tab_result[$i][
'description'] = (string) $obj->description;
730 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
731 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
732 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
733 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
734 $tab_result[$i][
'halfday'] = (int) $obj->halfday;
735 $tab_result[$i][
'statut'] = (int) $obj->status;
736 $tab_result[$i][
'status'] = (int) $obj->status;
737 $tab_result[$i][
'fk_validator'] = (int) $obj->fk_validator;
738 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
739 $tab_result[$i][
'fk_user_valid'] = (int) $obj->fk_user_valid;
740 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
741 $tab_result[$i][
'fk_user_approve'] = (int) $obj->fk_user_approve;
742 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
743 $tab_result[$i][
'fk_user_refuse'] = (int) $obj->fk_user_refuse;
744 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
745 $tab_result[$i][
'fk_user_cancel'] = (int) $obj->fk_user_cancel;
746 $tab_result[$i][
'detail_refuse'] = (string) $obj->detail_refuse;
748 $tab_result[$i][
'user_firstname'] = (string) $obj->user_firstname;
749 $tab_result[$i][
'user_lastname'] = (string) $obj->user_lastname;
750 $tab_result[$i][
'user_login'] = (string) $obj->user_login;
751 $tab_result[$i][
'user_statut'] = (int) $obj->user_status;
752 $tab_result[$i][
'user_status'] = (int) $obj->user_status;
753 $tab_result[$i][
'user_photo'] = (string) $obj->user_photo;
755 $tab_result[$i][
'validator_firstname'] = (string) $obj->validator_firstname;
756 $tab_result[$i][
'validator_lastname'] = (string) $obj->validator_lastname;
757 $tab_result[$i][
'validator_login'] = (string) $obj->validator_login;
758 $tab_result[$i][
'validator_statut'] = (int) $obj->validator_status;
759 $tab_result[$i][
'validator_status'] = (int) $obj->validator_status;
760 $tab_result[$i][
'validator_photo'] = (string) $obj->validator_photo;
765 $this->holiday = $tab_result;
769 $this->error =
"Error ".$this->db->lasterror();
782 public function validate($user =
null, $notrigger = 0)
784 global
$conf, $langs;
785 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
789 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
791 if ($checkBalance > 0) {
792 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
797 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
798 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
799 $daysAsked =
num_open_day($datedebutforcount, $datefinforcount, 0, 1, (
int) $this->halfday,
'', $this->fk_user);
801 if (($balance - $daysAsked) < 0) {
802 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
808 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref) || $this->
ref == $this->
id) {
809 $num = $this->getNextNumRef(
null);
811 $num = (string) $this->
ref;
816 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
817 $sql .=
" fk_user_valid = ".((int) $user->id).
",";
818 $sql .=
" date_valid = '".$this->db->idate(
dol_now()).
"',";
819 if (!empty($this->
status) && is_numeric($this->
status)) {
820 $sql .=
" statut = ".((int) $this->
status).
",";
822 $this->error =
'Property status must be a numeric value';
825 $sql .=
" ref = '".$this->db->escape($num).
"'";
826 $sql .=
" WHERE rowid = ".((int) $this->
id);
830 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
831 $resql = $this->db->query($sql);
834 $this->errors[] =
"Error ".$this->db->lasterror();
840 $result = $this->call_trigger(
'HOLIDAY_VALIDATE', $user);
849 $this->oldref = $this->ref;
852 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
854 $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) .
"'";
855 $sql .=
" WHERE filename LIKE '" . $this->db->escape($this->
ref) .
"%' AND filepath = 'holiday/" . $this->db->escape($this->
ref) .
"' and entity = " . ((int)
$conf->entity);
856 $resql = $this->db->query($sql);
859 $this->error = $this->db->lasterror();
861 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'holiday/".$this->db->escape($this->newref).
"'";
862 $sql .=
" WHERE filepath = 'holiday/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
863 $resql = $this->db->query($sql);
866 $this->error = $this->db->lasterror();
872 $dirsource =
$conf->holiday->multidir_output[$this->entity] .
'/' . $oldref;
873 $dirdest =
$conf->holiday->multidir_output[$this->entity] .
'/' . $newref;
874 if (!$error && file_exists($dirsource)) {
875 dol_syslog(get_class($this) .
"::validate rename dir " . $dirsource .
" into " . $dirdest);
876 if (@rename($dirsource, $dirdest)) {
879 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^' . preg_quote($oldref,
'/'));
880 foreach ($listoffiles as $fileentry) {
881 $dirsource = $fileentry[
'name'];
882 $dirdest = preg_replace(
'/^' . preg_quote($oldref,
'/') .
'/', $newref, $dirsource);
883 $dirsource = $fileentry[
'path'] .
'/' . $dirsource;
884 $dirdest = $fileentry[
'path'] .
'/' . $dirdest;
885 @rename($dirsource, $dirdest);
895 foreach ($this->errors as $errmsg) {
896 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
897 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
899 $this->db->rollback();
915 public function approve($user =
null, $notrigger = 0)
919 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
921 if ($checkBalance > 0) {
922 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
927 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
928 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
929 $daysAsked =
num_open_day($datedebutforcount, $datefinforcount, 0, 1, (
int) $this->halfday,
'', $this->fk_user);
931 if (($balance - $daysAsked) < 0) {
932 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
938 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
939 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
940 if (!empty($this->date_debut)) {
941 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
945 if (!empty($this->date_fin)) {
946 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
950 $sql .=
" halfday = ".((int) $this->halfday).
",";
951 if (!empty($this->
status) && is_numeric($this->
status)) {
952 $sql .=
" statut = ".((int) $this->
status).
",";
956 if (!empty($this->fk_validator)) {
957 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
961 if (!empty($this->date_valid)) {
962 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
964 $sql .=
" date_valid = NULL,";
966 if (!empty($this->fk_user_valid)) {
967 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
969 $sql .=
" fk_user_valid = NULL,";
971 if (!empty($this->date_approval)) {
972 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
974 $sql .=
" date_approval = NULL,";
976 if (!empty($this->fk_user_approve)) {
977 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
979 $sql .=
" fk_user_approve = NULL,";
981 if (!empty($this->date_refuse)) {
982 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
984 $sql .=
" date_refuse = NULL,";
986 if (!empty($this->fk_user_refuse)) {
987 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
989 $sql .=
" fk_user_refuse = NULL,";
991 if (!empty($this->date_cancel)) {
992 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
994 $sql .=
" date_cancel = NULL,";
996 if (!empty($this->fk_user_cancel)) {
997 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
999 $sql .=
" fk_user_cancel = NULL,";
1001 if (!empty($this->detail_refuse)) {
1002 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1004 $sql .=
" detail_refuse = NULL";
1006 $sql .=
" WHERE rowid = ".((int) $this->
id);
1010 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
1011 $resql = $this->db->query($sql);
1014 $this->errors[] =
"Error ".$this->db->lasterror();
1020 $result = $this->call_trigger(
'HOLIDAY_APPROVE', $user);
1030 foreach ($this->errors as $errmsg) {
1031 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
1032 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1034 $this->db->rollback();
1037 $this->db->commit();
1051 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1053 $langs->load(
'holiday');
1055 $recipient =
new User($this->db);
1056 $recipient->fetch($this->fk_user);
1057 if (empty($recipient->email)) {
1058 dol_syslog(get_class($this).
"::sendApprovalEmail user that requested the leave has no email, so no email is sent");
1062 $validator =
new User($this->db);
1063 $validator->fetch($this->fk_validator);
1072 $subject =
'['.$societeName.
'] '.$langs->transnoentitiesnoconv(
"HolidaysValidated");
1074 $link =
dol_buildpath(
'/holiday/card.php', 3).
'?id='.$this->id;
1076 $message =
"<p>".$langs->transnoentitiesnoconv(
"Hello").
" ".
dol_escape_htmltag($recipient->firstname).
",</p>\n";
1077 $message .=
"<p>".$langs->transnoentities(
"HolidaysValidatedBody",
dol_print_date($this->date_debut,
'day'),
dol_print_date($this->date_fin,
'day')).
"</p>\n";
1078 $message .=
"<ul>\n";
1080 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Link").
' : <a href="'.$link.
'" target="_blank">'.$link.
"</a></li>\n";
1081 $message .=
"</ul>\n";
1084 $trackid =
'leav'.$this->id;
1086 $mail =
new CMailFile($subject, $recipient->email, $emailFrom, $message, array(), array(), array(),
'', $sendtobcc, 0, 1,
'',
'', $trackid);
1087 if (!$mail->sendfile()) {
1088 $this->error = $mail->error;
1089 $this->errors = $mail->errors;
1090 dol_syslog(get_class($this).
"::sendApprovalEmail id=".$this->
id.
" ".$this->error, LOG_WARNING);
1104 public function update($user =
null, $notrigger = 0)
1108 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
1109 if ($this->
status == self::STATUS_REFUSED || $this->
status == self::STATUS_APPROVED) {
1113 if ($checkBalance > 0 && $this->
status != self::STATUS_DRAFT && $this->
status != self::STATUS_CANCELED) {
1114 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
1119 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
1120 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
1121 $daysAsked =
num_open_day($datedebutforcount, $datefinforcount, 0, 1, (
int) $this->halfday,
'', $this->fk_user);
1123 if (($balance - $daysAsked) < 0) {
1124 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1130 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
1132 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
1134 if (!empty($this->date_create)) {
1135 $sql .=
" date_create = '".$this->db->idate($this->date_create).
"',";
1139 if (!empty($this->date_debut)) {
1140 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
1144 if (!empty($this->date_fin)) {
1145 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
1149 $sql .=
" halfday = ".((int) $this->halfday).
",";
1150 if (!empty($this->
status) && is_numeric($this->
status)) {
1151 $sql .=
" statut = ".((int) $this->
status).
",";
1155 if (!empty($this->fk_validator)) {
1156 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
1160 if (!empty($this->date_valid)) {
1161 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1163 $sql .=
" date_valid = NULL,";
1165 if (!empty($this->fk_user_valid)) {
1166 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
1168 $sql .=
" fk_user_valid = NULL,";
1170 if (!empty($this->date_approval)) {
1171 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
1173 $sql .=
" date_approval = NULL,";
1175 if (!empty($this->fk_user_approve)) {
1176 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
1178 $sql .=
" fk_user_approve = NULL,";
1180 if (!empty($this->date_refuse)) {
1181 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
1183 $sql .=
" date_refuse = NULL,";
1185 if (!empty($this->fk_user_refuse)) {
1186 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
1188 $sql .=
" fk_user_refuse = NULL,";
1190 if (!empty($this->date_cancel)) {
1191 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
1193 $sql .=
" date_cancel = NULL,";
1195 if (!empty($this->fk_user_cancel)) {
1196 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
1198 $sql .=
" fk_user_cancel = NULL,";
1200 if (!empty($this->detail_refuse)) {
1201 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1203 $sql .=
" detail_refuse = NULL";
1206 $sql .=
" WHERE rowid = ".((int) $this->
id);
1210 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1211 $resql = $this->db->query($sql);
1214 $this->errors[] =
"Error ".$this->db->lasterror();
1225 if (!$notrigger && $user !==
null) {
1227 $result = $this->call_trigger(
'HOLIDAY_MODIFY', $user);
1237 foreach ($this->errors as $errmsg) {
1238 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1239 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1241 $this->db->rollback();
1244 $this->db->commit();
1257 public function delete($user, $notrigger = 0)
1259 global
$conf, $langs;
1262 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1263 $sql .=
" WHERE rowid=".((int) $this->
id);
1274 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1275 $resql = $this->db->query($sql);
1278 $this->errors[] =
"Error ".$this->db->lasterror();
1285 $result = $this->call_trigger(
'HOLIDAY_DELETE', $user);
1295 foreach ($this->errors as $errmsg) {
1296 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1297 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1299 $this->db->rollback();
1302 $this->db->commit();
1324 foreach ($this->holiday as $infos_CP) {
1336 if ($dateStart < $infos_CP[
'date_debut'] && $dateEnd > $infos_CP[
'date_fin']) {
1340 if ($halfday == 0) {
1341 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1344 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1347 } elseif ($halfday == -1) {
1349 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1350 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1354 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1355 if ($dateStart < $dateEnd) {
1358 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1362 } elseif ($halfday == 1) {
1364 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1365 if ($dateStart < $dateEnd) {
1368 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1372 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1373 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1377 } elseif ($halfday == 2) {
1379 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1380 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1384 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1385 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1390 dol_print_error(
null,
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1409 $isavailablemorning =
true;
1410 $isavailableafternoon =
true;
1413 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1414 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1415 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1416 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1417 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->db->idate($timestamp).
"'";
1418 if ($status !=
'-1') {
1419 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1422 $resql = $this->db->query($sql);
1424 $num_rows = $this->db->num_rows($resql);
1425 if ($num_rows > 0) {
1426 $arrayofrecord = array();
1428 while ($i < $num_rows) {
1429 $obj = $this->db->fetch_object($resql);
1432 $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);
1437 $isavailablemorning =
true;
1438 foreach ($arrayofrecord as $record) {
1439 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1442 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1445 $isavailablemorning =
false;
1448 $isavailableafternoon =
true;
1449 foreach ($arrayofrecord as $record) {
1450 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1453 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1456 $isavailableafternoon =
false;
1461 dol_print_error($this->db);
1464 $result = array(
'morning' => (
int) $isavailablemorning,
'afternoon' => (
int) $isavailableafternoon);
1465 if (!$isavailablemorning) {
1466 $result[
'morning_reason'] =
'leave_request';
1468 if (!$isavailableafternoon) {
1469 $result[
'afternoon_reason'] =
'leave_request';
1484 $langs->load(
'holiday');
1485 $nofetch = !empty($params[
'nofetch']);
1488 $datas[
'picto'] = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1489 if (isset($this->
status)) {
1490 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1492 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1494 if (!$nofetch && !empty($this->fk_type)) {
1495 $typeleaves = $this->
getTypes(1, -1);
1496 if (empty($typeleaves[$this->fk_type])) {
1497 $labeltoshow = $langs->trans(
"TypeWasDisabledOrRemoved", $this->fk_type);
1499 $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']);
1501 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type") .
':</b> ' . $labeltoshow;
1503 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1504 $listhalfday = array(
1505 'morning' => $langs->trans(
"Morning"),
1506 "afternoon" => $langs->trans(
"Afternoon")
1508 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ?
'afternoon' :
'morning';
1509 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ?
'morning' :
'afternoon';
1510 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateDebCP') .
'</b>: '.
dol_print_date($this->date_debut,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1511 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateFinCP') .
'</b>: '.
dol_print_date($this->date_fin,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1527 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1529 global
$conf, $langs, $hookmanager;
1531 if (!empty(
$conf->dol_no_mouse_hover)) {
1538 'objecttype' => $this->element,
1541 $classfortooltip =
'classfortooltip';
1544 $classfortooltip =
'classforajaxtooltip';
1545 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1551 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1556 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1557 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1558 $add_save_lastsearch_values = 1;
1560 if ($add_save_lastsearch_values) {
1561 $url .=
'&save_lastsearch_values=1';
1566 if (empty($notooltip)) {
1568 $label = $langs->trans(
"ShowMyObject");
1569 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1571 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1572 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1574 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1577 $linkstart =
'<a href="'.$url.
'"';
1578 $linkstart .= $linkclose.
'>';
1581 $result .= $linkstart;
1584 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1586 if ($withpicto != 2) {
1587 $result .= $this->ref;
1589 $result .= $linkend;
1592 $hookmanager->initHooks(array($this->element .
'dao'));
1593 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1594 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1596 $result = $hookmanager->resPrint;
1598 $result .= $hookmanager->resPrint;
1624 public function LibStatut($status, $mode = 0, $startdate =
'')
1629 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1637 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1645 $statusType =
'status6';
1646 if (!empty($startdate) && $startdate >=
dol_now()) {
1647 $statusType =
'status4';
1648 $params = array(
'tooltip' => $this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1650 if ($status == self::STATUS_DRAFT) {
1651 $statusType =
'status0';
1653 if ($status == self::STATUS_VALIDATED) {
1654 $statusType =
'status1';
1656 if ($status == self::STATUS_CANCELED) {
1657 $statusType =
'status9';
1659 if ($status == self::STATUS_REFUSED) {
1660 $statusType =
'status9';
1663 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1675 public function selectStatutCP($selected = 0, $htmlname =
'select_statut', $morecss =
'minwidth125')
1680 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1681 $nb = count($name) + 1;
1684 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1685 $out .=
'<option value="-1"> </option>'.
"\n";
1688 for ($i = 1; $i < $nb; $i++) {
1689 if ($i == $selected) {
1690 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1692 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1696 $out .=
"</select>\n";
1699 $out .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($showempty < 0 ? (
string) $showempty :
'-1'), $morecss);
1713 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1714 $sql .=
" value = '".$this->db->escape($value).
"'";
1715 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1717 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1718 $result = $this->db->query($sql);
1736 $sql =
"SELECT value";
1737 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1738 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1740 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1741 $result = $this->db->query($sql);
1744 $obj = $this->db->fetch_object($result);
1747 if ($createifnotfound) {
1748 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1749 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->db->escape($createifnotfound).
"')";
1750 $result = $this->db->query($sql);
1752 return $createifnotfound;
1754 $this->error = $this->db->lasterror();
1765 $this->error = $this->db->lasterror();
1780 global $user, $langs;
1784 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1785 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1786 $langs->load(
"holiday");
1799 if (empty($stringInDBForLastUpdate)) {
1802 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1803 $sql .=
" value = '".$this->db->escape($stringInDBForLastUpdate).
"'";
1804 $sql .=
" WHERE name = 'lastUpdate'";
1805 $result = $this->db->query($sql);
1807 $this->error = $this->db->lasterror();
1812 if ($stringInDBForLastUpdate <
'20000101000000') {
1813 $stringInDBForLastUpdate =
'20000101000000';
1824 while ($yearMonthLastUpdate < $yearMonthNow) {
1830 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1831 $nbUser = count($users);
1833 $typeleaves = $this->
getTypes(1, 1);
1836 foreach ($users as $userCounter) {
1837 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1838 if (empty($nbDaysToAdd)) {
1842 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1844 $nowHoliday = (float) $userCounter[
'nb_holiday'];
1845 $newSolde = $nowHoliday + $nbDaysToAdd;
1848 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidayMonthlyCredit'), $newSolde, $userCounter[
'type']);
1850 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1853 $this->db->rollback();
1857 if (empty($decrease)) {
1862 $filter =
" AND cp.statut = ".((int) self::STATUS_APPROVED);
1865 $filter .=
" AND cp.fk_type = ".((int) $userCounter[
'type']);
1866 $this->
fetchByUser($userCounter[
'id'],
'', $filter);
1868 if (empty($this->holiday)) {
1872 $startOfMonth =
dol_mktime(0, 0, 0, (
int) $month, 1, (
int) $year, 1);
1875 foreach ($this->holiday as $obj) {
1876 $startDate = $obj[
'date_debut_gmt'];
1877 $endDate = $obj[
'date_fin_gmt'];
1879 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1880 $startDate = $startOfMonth;
1883 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1884 $endDate = $endOfMonth;
1887 $nbDaysToDeduct = (float)
num_open_day($startDate, $endDate, 0, 1, $obj[
'halfday'], $obj[
'country_id'], $obj[
'fk_user']);
1889 if ($nbDaysToDeduct <= 0) {
1893 $newSolde -= $nbDaysToDeduct;
1896 $this->
addLogCP($user->id, $userCounter[
'rowid'], $obj[
'ref'].
' - '.$langs->trans(
'HolidayConsumption'), $newSolde, $userCounter[
'type']);
1898 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1901 $this->db->rollback();
1909 $lastUpdate =
dol_mktime(0, 0, 0, (
int) $newMonth[
'month'], 1, (
int) $newMonth[
'year']);
1911 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1912 $sql .=
" value = '".$this->db->escape(
dol_print_date($lastUpdate,
'%Y%m%d%H%M%S')).
"'";
1913 $sql .=
" WHERE name = 'lastUpdate'";
1914 $result = $this->db->query($sql);
1917 $this->db->rollback();
1921 $this->db->commit();
1931 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1932 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1933 $resql = $this->db->query($sql);
1935 $num = $this->db->num_rows($resql);
1939 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1940 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1941 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1942 $result = $this->db->query($sql);
1945 $this->errors[] = $this->db->lasterror();
1949 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1950 $sql .= ((float) $nbHoliday);
1951 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1952 $result = $this->db->query($sql);
1955 $this->errors[] = $this->db->lasterror();
1959 $this->errors[] = $this->db->lasterror();
1980 $sql =
"SELECT nb_holiday";
1981 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1982 $sql .=
" WHERE fk_user = ".(int) $user_id;
1984 $sql .=
" AND fk_type = ".(int) $fk_type;
1987 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1988 $result = $this->db->query($sql);
1990 $obj = $this->db->fetch_object($result);
1993 return $obj->nb_holiday;
2010 public function fetchUsers($stringlist =
true, $type =
true, $sqlFilters =
'')
2012 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
2019 $sql .=
" DISTINCT";
2022 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2025 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2026 $sql .=
" WHERE ((ug.fk_user = u.rowid";
2027 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
2028 $sql .=
" OR u.entity = 0)";
2030 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
2032 $sql .=
" AND u.statut > 0";
2033 $sql .=
" AND u.employee = 1";
2035 $sql .= $sqlFilters;
2038 $resql = $this->db->query($sql);
2043 $num = $this->db->num_rows($resql);
2048 $obj = $this->db->fetch_object($resql);
2051 $stringlist .= $obj->rowid;
2053 $stringlist .=
', '.$obj->rowid;
2062 $this->error =
"Error ".$this->db->lasterror();
2067 $sql =
"SELECT DISTINCT cpu.fk_user";
2068 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
2069 $sql .=
" WHERE cpu.fk_user = u.rowid";
2071 $sql .= $sqlFilters;
2074 $resql = $this->db->query($sql);
2079 $num = $this->db->num_rows($resql);
2084 $obj = $this->db->fetch_object($resql);
2087 $stringlist .= $obj->fk_user;
2089 $stringlist .=
', '.$obj->fk_user;
2098 $this->error =
"Error ".$this->db->lasterror();
2109 $sql .=
" DISTINCT";
2111 $sql .=
" u.rowid, u.lastname, u.firstname, u.gender, u.fk_country as country_id, u.photo, u.employee, u.statut as status, u.fk_user";
2112 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2115 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2116 $sql .=
" WHERE ((ug.fk_user = u.rowid";
2117 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
2118 $sql .=
" OR u.entity = 0)";
2120 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
2123 $sql .=
" AND u.statut > 0";
2124 $sql .=
" AND u.employee = 1";
2126 $sql .= $sqlFilters;
2129 $resql = $this->db->query($sql);
2134 $tab_result = $this->holiday;
2135 $num = $this->db->num_rows($resql);
2139 $obj = $this->db->fetch_object($resql);
2141 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2142 $tab_result[$i][
'id'] = (int) $obj->rowid;
2143 $tab_result[$i][
'name'] = $obj->lastname;
2144 $tab_result[$i][
'lastname'] = $obj->lastname;
2145 $tab_result[$i][
'firstname'] = $obj->firstname;
2146 $tab_result[$i][
'gender'] = $obj->gender;
2147 $tab_result[$i][
'status'] = (int) $obj->status;
2148 $tab_result[$i][
'employee'] = (int) $obj->employee;
2149 $tab_result[$i][
'photo'] = $obj->photo;
2150 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
2151 $tab_result[$i][
'country_id'] = (int) $obj->country_id;
2161 $this->errors[] =
"Error ".$this->db->lasterror();
2166 $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";
2167 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
2168 $sql .=
" WHERE cpu.fk_user = u.rowid";
2170 $sql .= $sqlFilters;
2173 $resql = $this->db->query($sql);
2178 $tab_result = $this->holiday;
2179 $num = $this->db->num_rows($resql);
2183 $obj = $this->db->fetch_object($resql);
2185 $tab_result[$i][
'rowid'] = $obj->rowid;
2186 $tab_result[$i][
'id'] = $obj->rowid;
2187 $tab_result[$i][
'name'] = $obj->lastname;
2188 $tab_result[$i][
'lastname'] = $obj->lastname;
2189 $tab_result[$i][
'firstname'] = $obj->firstname;
2190 $tab_result[$i][
'gender'] = $obj->gender;
2191 $tab_result[$i][
'status'] = $obj->status;
2192 $tab_result[$i][
'employee'] = $obj->employee;
2193 $tab_result[$i][
'photo'] = $obj->photo;
2194 $tab_result[$i][
'fk_user'] = $obj->fk_user;
2196 $tab_result[$i][
'type'] = $obj->fk_type;
2197 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
2205 $this->error =
"Error ".$this->db->lasterror();
2223 $users_validator = array();
2225 $sql =
"SELECT DISTINCT ur.fk_user";
2226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2227 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2229 $sql .=
" SELECT DISTINCT ugu.fk_user";
2230 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2231 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2234 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
2235 $result = $this->db->query($sql);
2237 $num_rows = $this->db->num_rows($result);
2239 while ($i < $num_rows) {
2240 $objp = $this->db->fetch_object($result);
2241 array_push($users_validator, $objp->fk_user);
2244 return $users_validator;
2246 $this->error = $this->db->lasterror();
2247 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2260 $sql =
"SELECT count(u.rowid) as compteur";
2261 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2262 $sql .=
" WHERE u.statut > 0";
2264 $result = $this->db->query($sql);
2265 $object = $this->db->fetch_object($result);
2276 $sql =
"SELECT count(u.rowid) as compteur";
2277 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2278 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2280 $result = $this->db->query($sql);
2281 $object = $this->db->fetch_object($result);
2295 if (empty($userCP)) {
2298 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2313 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2321 if ($prev_solde == $new_solde) {
2328 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2329 $sql .=
"date_action,";
2330 $sql .=
"fk_user_action,";
2331 $sql .=
"fk_user_update,";
2332 $sql .=
"type_action,";
2333 $sql .=
"prev_solde,";
2334 $sql .=
"new_solde,";
2336 $sql .=
") VALUES (";
2337 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2338 $sql .=
" ".((int) $fk_user_action).
",";
2339 $sql .=
" ".((int) $fk_user_update).
",";
2340 $sql .=
" '".$this->db->escape($label).
"',";
2341 $sql .=
" ".((float) $prev_solde).
",";
2342 $sql .=
" ".((float) $new_solde).
",";
2343 $sql .=
" ".((int) $fk_type);
2346 $resql = $this->db->query($sql);
2349 $this->errors[] =
"Error ".$this->db->lasterror();
2354 $optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2359 foreach ($this->errors as $errmsg) {
2360 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2361 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2363 $this->db->rollback();
2366 $this->db->commit();
2381 $sql .=
" cpl.rowid,";
2382 $sql .=
" cpl.date_action,";
2383 $sql .=
" cpl.fk_user_action,";
2384 $sql .=
" cpl.fk_user_update,";
2385 $sql .=
" cpl.type_action,";
2386 $sql .=
" cpl.prev_solde,";
2387 $sql .=
" cpl.new_solde,";
2388 $sql .=
" cpl.fk_type";
2389 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2390 $sql .=
" WHERE cpl.rowid > 0";
2393 if (!empty($sqlwhere)) {
2394 $sql .=
" ".$sqlwhere;
2398 if (!empty($sqlorder)) {
2399 $sql .=
" ".$sqlorder;
2402 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2403 $resql = $this->db->query($sql);
2408 $tab_result = $this->logs;
2409 $num = $this->db->num_rows($resql);
2418 $obj = $this->db->fetch_object($resql);
2420 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2421 $tab_result[$i][
'id'] = (int) $obj->rowid;
2422 $tab_result[$i][
'date_action'] = (string) $obj->date_action;
2423 $tab_result[$i][
'fk_user_action'] = (int) $obj->fk_user_action;
2424 $tab_result[$i][
'fk_user_update'] = (int) $obj->fk_user_update;
2425 $tab_result[$i][
'type_action'] = (string) $obj->type_action;
2426 $tab_result[$i][
'prev_solde'] = (float) $obj->prev_solde;
2427 $tab_result[$i][
'new_solde'] = (float) $obj->new_solde;
2428 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
2433 $this->logs = $tab_result;
2437 $this->error =
"Error ".$this->db->lasterror();
2454 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2455 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2456 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int)
$mysoc->country_id).
')';
2457 $sql .=
" AND entity IN (0, ".getEntity(
'c_holiday_types').
")";
2459 $sql .=
" AND active = ".((int) $active);
2462 $sql .=
" AND affect = ".((int) $affect);
2464 $sql .=
" ORDER BY sortorder";
2466 $result = $this->db->query($sql);
2468 $num = $this->db->num_rows($result);
2471 while ($obj = $this->db->fetch_object($result)) {
2472 $types[$obj->rowid] = array(
2473 'id' => $obj->rowid,
2474 'rowid' => $obj->rowid,
2475 'code' => $obj->code,
2476 'label' => $obj->label,
2477 'affect' => $obj->affect,
2478 'delay' => $obj->delay,
2479 'newbymonth' => $obj->newbymonth
2486 dol_print_error($this->db);
2503 $sql =
"SELECT f.rowid, f.statut as status,";
2504 $sql .=
" f.date_create as datec,";
2505 $sql .=
" f.tms as date_modification,";
2506 $sql .=
" f.date_valid as datev,";
2507 $sql .=
" f.date_approval as datea,";
2508 $sql .=
" f.date_refuse as dater,";
2509 $sql .=
" f.fk_user_create as fk_user_creation,";
2510 $sql .=
" f.fk_user_modif as fk_user_modification,";
2511 $sql .=
" f.fk_user_valid as fk_user_validation,";
2512 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2513 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2514 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2515 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2516 $sql .=
" WHERE f.rowid = ".((int) $id);
2517 $sql .=
" AND f.entity = ".((int)
$conf->entity);
2519 $resql = $this->db->query($sql);
2521 if ($this->db->num_rows($resql)) {
2522 $obj = $this->db->fetch_object($resql);
2524 $this->
id = $obj->rowid;
2526 $this->date_creation = $this->db->jdate($obj->datec);
2527 $this->date_modification = $this->db->jdate($obj->date_modification);
2528 $this->date_validation = $this->db->jdate($obj->datev);
2529 $this->date_approval = $this->db->jdate($obj->datea);
2531 $this->user_creation_id = $obj->fk_user_creation;
2532 $this->user_validation_id = $obj->fk_user_validation;
2533 $this->user_modification_id = $obj->fk_user_modification;
2536 if ($obj->fk_user_approval_done) {
2537 $this->fk_user_approve = $obj->fk_user_approval_done;
2538 $this->user_approve_id = $obj->fk_user_approval_done;
2542 $this->db->free($resql);
2544 dol_print_error($this->db);
2558 global $user, $langs;
2562 $this->specimen = 1;
2564 $this->fk_user = $user->id;
2566 $this->date_debut =
dol_now();
2567 $this->date_fin =
dol_now() + (24 * 3600);
2568 $this->date_valid =
dol_now();
2569 $this->fk_validator = $user->id;
2586 $this->nb = array();
2588 $sql =
"SELECT count(h.rowid) as nb";
2589 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2590 $sql .=
" WHERE h.statut > 1";
2591 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2592 if (!$user->hasRight(
'holiday',
'readall')) {
2593 $userchildids = $user->getAllChildIds(1);
2594 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2595 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2598 $resql = $this->db->query($sql);
2600 while ($obj = $this->db->fetch_object($resql)) {
2601 $this->nb[
"holidays"] = $obj->nb;
2603 $this->db->free($resql);
2606 dol_print_error($this->db);
2607 $this->error = $this->db->error();
2622 global
$conf, $langs;
2633 $sql =
"SELECT COUNT(h.rowid) as nb,";
2634 $sql .=
" SUM(CASE WHEN h.date_debut IS NULL OR h.date_debut < '".$this->db->idate($now -
$conf->holiday->approve->warning_delay).
"' THEN 1 ELSE 0 END) as nblate";
2635 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2636 $sql .=
" WHERE h.statut = 2";
2637 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2638 if (!$user->hasRight(
'holiday',
'read_all')) {
2639 $userchildids = $user->getAllChildIds(1);
2640 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2641 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2644 $resql = $this->db->query($sql);
2646 $langs->load(
"members");
2649 $response->warning_delay =
$conf->holiday->approve->warning_delay / 60 / 60 / 24;
2650 $response->label = $langs->trans(
"HolidaysToApprove");
2651 $response->labelShort = $langs->trans(
"ToApprove");
2652 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2653 $response->img = img_object(
'',
"holiday");
2655 $obj = $this->db->fetch_object($resql);
2657 $response->nbtodo = (int) $obj->nb;
2658 $response->nbtodolate = (int) $obj->nblate;
2663 dol_print_error($this->db);
2664 $this->error = $this->db->error();
2679 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2681 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2682 $return .=
'<div class="info-box info-box-sm">';
2683 $return .=
'<span class="info-box-icon bg-infobox-action">';
2684 $return .= img_picto(
'', $this->picto);
2685 $return .=
'</span>';
2686 $return .=
'<div class="info-box-content">';
2687 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().
'</span>';
2688 if ($selected >= 0) {
2689 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2691 if (property_exists($this,
'fk_type')) {
2694 $return .=
'<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata[
'labeltype']).
'">'.
dol_escape_htmltag($arraydata[
'labeltype']).
'</div>';
2696 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2697 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_debut,
'day').
'</span>';
2698 $return .=
' <span class="opacitymedium small">'.$langs->trans(
"To").
'</span> ';
2699 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_fin,
'day').
'</span>';
2700 if (!empty($arraydata[
'nbopenedday'])) {
2701 $return .=
' ('.$arraydata[
'nbopenedday'].
')';
2704 if (method_exists($this,
'getLibStatut')) {
2705 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2707 $return .=
'</div>';
2708 $return .=
'</div>';
2709 $return .=
'</div>';
2725 global
$conf, $langs, $user;
2727 $outputlangs = $langs;
2732 $arrayfields = array(
2733 'user' =>
'Employee',
2735 'date_start' =>
'DateDebCP',
2736 'date_end' =>
'DateFinCP',
2737 'used_days' =>
'NbUseDaysCPShort',
2740 if (!empty($newlang)) {
2742 $outputlangs->setDefaultLang($newlang);
2744 $outputlangs->loadLangs(array(
'main',
'holiday',
'hrm'));
2747 $this->errors[] =
'Bad value for parameter mailto. Must be a valid email address.';
2751 $typeleaves = $this->
getTypes(1, -1);
2752 $arraytypeleaves = array();
2753 foreach ($typeleaves as $val) {
2754 $labeltoshow = ($outputlangs->trans($val[
'code']) != $val[
'code'] ? $outputlangs->trans($val[
'code']) : $val[
'label']);
2755 $arraytypeleaves[$val[
'rowid']] = $labeltoshow;
2757 $listhalfday = array(
'morning' => $outputlangs->trans(
"Morning"),
"afternoon" => $outputlangs->trans(
"Afternoon"));
2761 $year_month = sprintf(
"%04d", $prev_month[
"year"]).
'-'.sprintf(
"%02d", $prev_month[
"month"]);
2762 $arrayleaves = array();
2764 $sql =
"SELECT cp.rowid, cp.ref, cp.fk_user, cp.date_debut, cp.date_fin, cp.fk_type, cp.description, cp.halfday, cp.statut as status";
2765 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday cp";
2766 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user u ON cp.fk_user = u.rowid";
2767 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
") AND cp.rowid > 0";
2768 $sql .=
" AND cp.statut = ".Holiday::STATUS_APPROVED;
2770 $sql .=
" (date_format(cp.date_debut, '%Y-%m') = '".$this->db->escape($year_month).
"' OR date_format(cp.date_fin, '%Y-%m') = '".$this->db->escape($year_month).
"')";
2772 $sql .=
" (date_format(cp.date_debut, '%Y-%m') < '".$this->db->escape($year_month).
"' AND date_format(cp.date_fin, '%Y-%m') > '".$this->db->escape($year_month).
"') ";
2774 $sql .= $this->db->order(
"cp.fk_user, cp.date_debut",
"ASC");
2775 $resql = $this->db->query($sql);
2776 if (empty($resql)) {
2777 $this->errors[] = $this->db->lasterror();
2780 $num = $this->db->num_rows($resql);
2782 $tmpuser =
new User($this->db);
2783 while ($obj = $this->db->fetch_object($resql)) {
2784 $tmpuser->fetch($obj->fk_user);
2786 $date_start = $this->db->jdate($obj->date_debut,
true);
2787 $date_end = $this->db->jdate($obj->date_fin,
true);
2792 $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ?
'afternoon' :
'morning';
2793 $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ?
'morning' :
'afternoon';
2795 $halfdayinmonth = $obj->halfday;
2796 $starthalfdayinmonth = $starthalfday;
2797 $endhalfdayinmonth = $endhalfday;
2802 $date_start_inmonth = $this->db->jdate($obj->date_debut,
true);
2803 $date_end_inmonth = $this->db->jdate($obj->date_fin,
true);
2804 if ($tmpstart[
'year'] < $prev_month[
"year"] || $tmpstart[
'mon'] < $prev_month[
"month"]) {
2805 $date_start_inmonth =
dol_get_first_day($prev_month[
"year"], $prev_month[
"month"],
true);
2806 $starthalfdayinmonth =
'morning';
2807 if ($halfdayinmonth == 2) {
2808 $halfdayinmonth = 1;
2810 if ($halfdayinmonth == -1) {
2811 $halfdayinmonth = 0;
2814 if ($tmpend[
'year'] > $prev_month[
"year"] || $tmpend[
'mon'] > $prev_month[
"month"]) {
2815 $date_end_inmonth =
dol_get_last_day($prev_month[
"year"], $prev_month[
"month"],
true) - ((24 * 3600) - 1);
2816 $endhalfdayinmonth =
'afternoon';
2817 if ($halfdayinmonth == 2) {
2818 $halfdayinmonth = -1;
2820 if ($halfdayinmonth == 1) {
2821 $halfdayinmonth = 0;
2824 $arrayleaves[$obj->fk_user][] = array(
2825 "user" => $tmpuser->getNomUrl(0,
'nolink', 0, 0, 24, 1),
2826 "type" => $arraytypeleaves[$obj->fk_type],
2827 "date_start" =>
dol_print_date($date_start_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$starthalfdayinmonth]).
')</span>',
2828 "date_end" =>
dol_print_date($date_end_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$endhalfdayinmonth]).
')</span>',
2829 "used_days" =>
num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth, $tmpuser->country_id, $obj->fk_user)
2835 $arrayemployees = $this->
fetchUsers(
false,
true);
2836 if (!is_array($arrayemployees)) {
2841 $arrayleavesfinal = array();
2842 $usertmp =
new User($this->db);
2843 foreach ($arrayemployees as $employee) {
2844 if (!empty($arrayleaves[$employee[
'rowid']])) {
2845 $arrayleavesfinal = array_merge($arrayleavesfinal, $arrayleaves[$employee[
'rowid']]);
2846 unset($arrayleaves[$employee[
'rowid']]);
2848 $usertmp->fetch($employee[
'rowid']);
2849 $arrayleavesfinal[] = array(
2850 "user" => $usertmp->getNomUrl(0,
'nolink', 0, 0, 24, 1),
2851 "type" => $outputlangs->trans(
"None"),
2859 foreach ($arrayleaves as $leavesofuser) {
2860 $arrayleavesfinal = array_merge($arrayleavesfinal, $leavesofuser);
2862 $arrayleaves = $arrayleavesfinal;
2864 $outputarrayleaves =
'<br><table style="width: 100%;border-collapse: separate !important;border-spacing: 0px;border-top: 1px solid #b6b6b6;border-left: 1px solid #b6b6b6;border-right: 1px solid #b6b6b6;margin: 0px 0px 20px 0px;">';
2865 $outputarrayleaves .=
'<tr>';
2866 foreach ($arrayfields as $key => $label) {
2867 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;">';
2868 $outputarrayleaves .= $outputlangs->trans($label);
2869 if ($key ==
'date_end') {
2870 $outputarrayleaves .=
" (".$langs->trans(
"Included").
")";
2872 $outputarrayleaves .=
'</td>';
2874 $outputarrayleaves .=
'</tr>';
2876 if (!empty($arrayleaves)) {
2877 foreach ($arrayleaves as $fields) {
2878 $outputarrayleaves .=
'<tr>';
2879 foreach ($fields as $field => $value) {
2880 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;" id="'.$field.
'">';
2881 $outputarrayleaves .= $value;
2882 $outputarrayleaves .=
'</td>';
2884 $outputarrayleaves .=
'</tr>';
2887 $outputarrayleaves .=
'<tr>';
2888 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;" colspan="5">';
2889 $outputarrayleaves .= $outputlangs->trans(
"None");
2890 $outputarrayleaves .=
'</td>';
2891 $outputarrayleaves .=
'</tr>';
2893 $outputarrayleaves .=
'</table>';
2895 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2896 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2898 $formmail =
new FormMail($this->db);
2900 $templateLabel =
'';
2901 if (empty($template) || $template ==
'EmailTemplateCode') {
2902 $templateLabel =
'(HolidayHrInformationsPreviousMonth)';
2904 if (is_numeric($template)) {
2905 $templateId = $template;
2907 $templateLabel = $template;
2910 $mailtemplate = $formmail->getEMailTemplate($this->db,
"holiday", $user, $outputlangs, $templateId, 1, $templateLabel);
2912 if (is_numeric($mailtemplate) || empty($mailtemplate->topic)) {
2913 $this->errors[] =
'No mail template found for code "'.$templateLabel.
'" or id "'.$templateId.
'".';
2918 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $this);
2921 $subject =
make_substitutions($mailtemplate->topic, $substitutionarray, $outputlangs);
2925 $msg = preg_replace(
'/__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__/', $outputarrayleaves, $msg);
2926 $cmail =
new CMailFile($subject, $mailto, $from, $msg, array(), array(), array(),
'',
'', 0, 1);
2927 $result = $cmail->sendfile();
2928 if (!$result || !empty($cmail->error) || !empty($cmail->errors)) {
2929 $this->errors[] = $cmail->error;
2930 if (is_array($cmail->errors) && count($cmail->errors) > 0) {
2931 $this->errors = array_merge($this->errors, $cmail->errors);
2937 if (!empty($this->errors)) {
2938 $this->output .=
"\n";
2941 return ($error ? 1 : 0);
if(! $sortfield) if(! $sortorder) $object
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='', $placeholder='')
Convert a html select field into an ajax combobox.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
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.
fetchUsers($stringlist=true, $type=true, $sqlFilters='')
Get list of Users or list of vacation balance.
info($id)
Load information on object.
updateBalance()
Update balance of vacations and check table of users for holidays is complete.
updateConfCP($name, $value)
Update an option of the Holiday module.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
fetchAll($sqlOrder, $sqlFilter)
List all holidays of all users.
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 the number of active Dolibarr users to the number of paid leave users.
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.
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)
Create a paid leave entry in the database.
sendApprovalEmail()
Send the approval email to the user who requested the leave.
selectStatutCP($selected=0, $htmlname='select_statut', $morecss='minwidth125')
Show select with list of leave status.
countActiveUsersWithoutCP()
Count number of active users in Dolibarr without Paid leave.
updateSoldeCP($userID=0, $nbHoliday=0, $fk_type=0)
Updates the timestamp of the last CP balance update.
update($user=null, $notrigger=0)
Update database.
getCPforUser($user_id, $fk_type=0)
Return the balance of annual leave of a user.
sendPreviousMonthHRInformations($mailto="", $template="", $newlang="")
Send a mail with previous month Hr information CAN BE A CRON TASK.
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.
const STATUS_CANCELED
Canceled.
fetchLog($sqlorder, $sqlwhere)
List log of leaves.
countActiveUsers()
Count number of active users in Dolibarr.
fetchByUser($user_id, $order='', $filter='')
List holidays for a particular user or list of users.
const STATUS_APPROVED
Approved.
getTooltipContentArray($params)
getTooltipContentArray
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
LibStatut($status, $mode=0, $startdate='')
Returns the label of a status.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_get_prev_month($month, $year)
Return previous month.
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='', $user_id=0)
Function to return number of working days (and text of units) between two dates (working days)
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_next_month($month, $year)
Return next month.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_stringtotime($string, $gm=1, $processnotimeasnoon=0)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)