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 $date_refuse = 0;
143 public $fk_user_refuse;
148 public $date_cancel = 0;
153 public $fk_user_cancel;
158 public $fk_user_create;
163 public $detail_refuse =
'';
173 public $holiday = array();
175 public $events = array();
180 public $logs = array();
214 $this->ismultientitymanaged = 0;
225 public function getNextNumRef($objsoc)
227 global $langs,
$conf;
228 $langs->load(
"order");
231 $conf->global->HOLIDAY_ADDON =
'mod_holiday_madonna';
241 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
242 foreach ($dirmodels as $reldir) {
246 $mybool = ((bool) @include_once $dir.$file) || $mybool;
254 $obj =
new $classname();
255 '@phan-var-force ModelNumRefHolidays $obj';
257 $numref = $obj->getNextValue($objsoc, $this);
262 $this->error = $obj->error;
267 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_HOLIDAY_ADDON_NotDefined");
291 $this->db->rollback();
303 public function create($user, $notrigger = 0)
311 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
312 $this->error =
"ErrorBadParameterFkUser";
315 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
316 $this->error =
"ErrorBadParameterFkValidator";
319 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
320 $this->error =
"ErrorBadParameterFkType";
325 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday(";
328 $sql .=
"date_create,";
329 $sql .=
"description,";
330 $sql .=
"date_debut,";
334 $sql .=
"fk_validator,";
336 $sql .=
"fk_user_create,";
338 $sql .=
") VALUES (";
340 $sql .=
" ".((int) $this->fk_user).
",";
341 $sql .=
" '".$this->db->idate($now).
"',";
342 $sql .=
" '".$this->db->escape($this->
description).
"',";
343 $sql .=
" '".$this->db->idate($this->date_debut).
"',";
344 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
345 $sql .=
" ".((int) $this->halfday).
",";
347 $sql .=
" ".((int) $this->fk_validator).
",";
348 $sql .=
" ".((int) $this->fk_type).
",";
349 $sql .=
" ".((int) $user->id).
",";
350 $sql .=
" ".((int)
$conf->entity);
355 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
356 $resql = $this->db->query($sql);
359 $this->errors[] =
"Error ".$this->db->lasterror();
363 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday");
367 $initialref =
'(PROV'.$this->id.
')';
368 if (!empty($this->
ref)) {
369 $initialref = $this->ref;
372 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"holiday SET ref='".$this->db->escape($initialref).
"' WHERE rowid=".((int) $this->
id);
373 if ($this->db->query($sql)) {
374 $this->
ref = $initialref;
380 if (!$error && !$notrigger) {
382 $result = $this->call_trigger(
'HOLIDAY_CREATE', $user);
394 foreach ($this->errors as $errmsg) {
395 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
396 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
398 $this->db->rollback();
414 public function fetch($id, $ref =
'')
417 $sql .=
" cp.rowid,";
419 $sql .=
" cp.fk_user,";
420 $sql .=
" cp.date_create,";
421 $sql .=
" cp.description,";
422 $sql .=
" cp.date_debut,";
423 $sql .=
" cp.date_fin,";
424 $sql .=
" cp.halfday,";
425 $sql .=
" cp.statut as status,";
426 $sql .=
" cp.fk_validator,";
427 $sql .=
" cp.date_valid,";
428 $sql .=
" cp.fk_user_valid,";
429 $sql .=
" cp.date_approval,";
430 $sql .=
" cp.fk_user_approve,";
431 $sql .=
" cp.date_refuse,";
432 $sql .=
" cp.fk_user_refuse,";
433 $sql .=
" cp.date_cancel,";
434 $sql .=
" cp.fk_user_cancel,";
435 $sql .=
" cp.detail_refuse,";
436 $sql .=
" cp.note_private,";
437 $sql .=
" cp.note_public,";
438 $sql .=
" cp.fk_user_create,";
439 $sql .=
" cp.fk_type,";
440 $sql .=
" cp.entity";
441 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
443 $sql .=
" WHERE cp.rowid = ".((int) $id);
445 $sql .=
" WHERE cp.ref = '".$this->db->escape($ref).
"'";
448 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
449 $resql = $this->db->query($sql);
451 if ($this->db->num_rows($resql)) {
452 $obj = $this->db->fetch_object($resql);
454 $this->
id = (int) $obj->rowid;
455 $this->
ref = (
string) ($obj->ref ? $obj->ref : $obj->rowid);
456 $this->fk_user = (int) $obj->fk_user;
457 $this->date_create = $this->db->jdate($obj->date_create);
459 $this->date_debut = $this->db->jdate($obj->date_debut);
460 $this->date_fin = $this->db->jdate($obj->date_fin);
461 $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
462 $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
463 $this->halfday = (int) $obj->halfday;
464 $this->
status = (int) $obj->status;
465 $this->statut = (int) $obj->status;
466 $this->fk_validator = $obj->fk_validator;
467 $this->date_valid = $this->db->jdate($obj->date_valid);
468 $this->fk_user_valid = $obj->fk_user_valid;
469 $this->user_validation_id = $obj->fk_user_valid;
470 $this->date_approval = $this->db->jdate($obj->date_approval);
471 $this->fk_user_approve = $obj->fk_user_approve;
472 $this->date_refuse = $this->db->jdate($obj->date_refuse);
473 $this->fk_user_refuse = $obj->fk_user_refuse;
474 $this->date_cancel = $this->db->jdate($obj->date_cancel);
475 $this->fk_user_cancel = $obj->fk_user_cancel;
476 $this->detail_refuse = $obj->detail_refuse;
477 $this->note_private = $obj->note_private;
478 $this->note_public = $obj->note_public;
479 $this->fk_user_create = $obj->fk_user_create;
480 $this->fk_type = $obj->fk_type;
481 $this->entity = $obj->entity;
489 $this->db->free($resql);
493 $this->error =
"Error ".$this->db->lasterror();
510 $sql .=
" cp.rowid,";
513 $sql .=
" cp.fk_user,";
514 $sql .=
" cp.fk_type,";
515 $sql .=
" cp.date_create,";
516 $sql .=
" cp.tms as date_modification,";
517 $sql .=
" cp.description,";
518 $sql .=
" cp.date_debut,";
519 $sql .=
" cp.date_fin,";
520 $sql .=
" cp.halfday,";
521 $sql .=
" cp.statut as status,";
522 $sql .=
" cp.fk_validator,";
523 $sql .=
" cp.date_valid,";
524 $sql .=
" cp.fk_user_valid,";
525 $sql .=
" cp.date_approval,";
526 $sql .=
" cp.fk_user_approve,";
527 $sql .=
" cp.date_refuse,";
528 $sql .=
" cp.fk_user_refuse,";
529 $sql .=
" cp.date_cancel,";
530 $sql .=
" cp.fk_user_cancel,";
531 $sql .=
" cp.detail_refuse,";
533 $sql .=
" uu.lastname as user_lastname,";
534 $sql .=
" uu.firstname as user_firstname,";
535 $sql .=
" uu.login as user_login,";
536 $sql .=
" uu.statut as user_status,";
537 $sql .=
" uu.photo as user_photo,";
539 $sql .=
" ua.lastname as validator_lastname,";
540 $sql .=
" ua.firstname as validator_firstname,";
541 $sql .=
" ua.login as validator_login,";
542 $sql .=
" ua.statut as validator_status,";
543 $sql .=
" ua.photo as validator_photo";
545 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
546 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
547 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
548 $sql .=
" AND cp.fk_user IN (".$this->db->sanitize($user_id).
")";
551 if (!empty($filter)) {
556 if (!empty($order)) {
560 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
561 $resql = $this->db->query($sql);
566 $tab_result = $this->holiday;
567 $num = $this->db->num_rows($resql);
576 $obj = $this->db->fetch_object($resql);
578 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
579 $tab_result[$i][
'id'] = (int) $obj->rowid;
580 $tab_result[$i][
'ref'] = (
string) ($obj->ref ? $obj->ref : $obj->rowid);
582 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
583 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
584 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
585 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
586 $tab_result[$i][
'description'] = (
string) $obj->description;
587 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
588 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
589 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
590 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
591 $tab_result[$i][
'halfday'] = (int) $obj->halfday;
592 $tab_result[$i][
'statut'] = (int) $obj->status;
593 $tab_result[$i][
'status'] = (int) $obj->status;
594 $tab_result[$i][
'fk_validator'] = (int) $obj->fk_validator;
595 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
596 $tab_result[$i][
'fk_user_valid'] = (int) $obj->fk_user_valid;
597 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
598 $tab_result[$i][
'fk_user_approve'] = (int) $obj->fk_user_approve;
599 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
600 $tab_result[$i][
'fk_user_refuse'] = (int) $obj->fk_user_refuse;
601 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
602 $tab_result[$i][
'fk_user_cancel'] = (int) $obj->fk_user_cancel;
603 $tab_result[$i][
'detail_refuse'] = (
string) $obj->detail_refuse;
605 $tab_result[$i][
'user_firstname'] = (
string) $obj->user_firstname;
606 $tab_result[$i][
'user_lastname'] = (
string) $obj->user_lastname;
607 $tab_result[$i][
'user_login'] = (
string) $obj->user_login;
608 $tab_result[$i][
'user_statut'] = (int) $obj->user_status;
609 $tab_result[$i][
'user_status'] = (int) $obj->user_status;
610 $tab_result[$i][
'user_photo'] = (
string) $obj->user_photo;
612 $tab_result[$i][
'validator_firstname'] = (
string) $obj->validator_firstname;
613 $tab_result[$i][
'validator_lastname'] = (
string) $obj->validator_lastname;
614 $tab_result[$i][
'validator_login'] = (
string) $obj->validator_login;
615 $tab_result[$i][
'validator_statut'] = (int) $obj->validator_status;
616 $tab_result[$i][
'validator_status'] = (int) $obj->validator_status;
617 $tab_result[$i][
'validator_photo'] = (
string) $obj->validator_photo;
623 $this->holiday = $tab_result;
627 $this->error =
"Error ".$this->db->lasterror();
642 $sql .=
" cp.rowid,";
644 $sql .=
" cp.fk_user,";
645 $sql .=
" cp.fk_type,";
646 $sql .=
" cp.date_create,";
647 $sql .=
" cp.tms as date_modification,";
648 $sql .=
" cp.description,";
649 $sql .=
" cp.date_debut,";
650 $sql .=
" cp.date_fin,";
651 $sql .=
" cp.halfday,";
652 $sql .=
" cp.statut as status,";
653 $sql .=
" cp.fk_validator,";
654 $sql .=
" cp.date_valid,";
655 $sql .=
" cp.fk_user_valid,";
656 $sql .=
" cp.date_approval,";
657 $sql .=
" cp.fk_user_approve,";
658 $sql .=
" cp.date_refuse,";
659 $sql .=
" cp.fk_user_refuse,";
660 $sql .=
" cp.date_cancel,";
661 $sql .=
" cp.fk_user_cancel,";
662 $sql .=
" cp.detail_refuse,";
664 $sql .=
" uu.lastname as user_lastname,";
665 $sql .=
" uu.firstname as user_firstname,";
666 $sql .=
" uu.login as user_login,";
667 $sql .=
" uu.statut as user_status,";
668 $sql .=
" uu.photo as user_photo,";
670 $sql .=
" ua.lastname as validator_lastname,";
671 $sql .=
" ua.firstname as validator_firstname,";
672 $sql .=
" ua.login as validator_login,";
673 $sql .=
" ua.statut as validator_status,";
674 $sql .=
" ua.photo as validator_photo";
676 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
677 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
678 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
681 if (!empty($filter)) {
686 if (!empty($order)) {
690 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
691 $resql = $this->db->query($sql);
696 $tab_result = $this->holiday;
697 $num = $this->db->num_rows($resql);
706 $obj = $this->db->fetch_object($resql);
708 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
709 $tab_result[$i][
'id'] = (int) $obj->rowid;
710 $tab_result[$i][
'ref'] = (
string) ($obj->ref ? $obj->ref : $obj->rowid);
712 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
713 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
714 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
715 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
716 $tab_result[$i][
'description'] = (
string) $obj->description;
717 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
718 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
719 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
720 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
721 $tab_result[$i][
'halfday'] = (int) $obj->halfday;
722 $tab_result[$i][
'statut'] = (int) $obj->status;
723 $tab_result[$i][
'status'] = (int) $obj->status;
724 $tab_result[$i][
'fk_validator'] = (int) $obj->fk_validator;
725 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
726 $tab_result[$i][
'fk_user_valid'] = (int) $obj->fk_user_valid;
727 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
728 $tab_result[$i][
'fk_user_approve'] = (int) $obj->fk_user_approve;
729 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
730 $tab_result[$i][
'fk_user_refuse'] = (int) $obj->fk_user_refuse;
731 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
732 $tab_result[$i][
'fk_user_cancel'] = (int) $obj->fk_user_cancel;
733 $tab_result[$i][
'detail_refuse'] = (
string) $obj->detail_refuse;
735 $tab_result[$i][
'user_firstname'] = (
string) $obj->user_firstname;
736 $tab_result[$i][
'user_lastname'] = (
string) $obj->user_lastname;
737 $tab_result[$i][
'user_login'] = (
string) $obj->user_login;
738 $tab_result[$i][
'user_statut'] = (int) $obj->user_status;
739 $tab_result[$i][
'user_status'] = (int) $obj->user_status;
740 $tab_result[$i][
'user_photo'] = (
string) $obj->user_photo;
742 $tab_result[$i][
'validator_firstname'] = (
string) $obj->validator_firstname;
743 $tab_result[$i][
'validator_lastname'] = (
string) $obj->validator_lastname;
744 $tab_result[$i][
'validator_login'] = (
string) $obj->validator_login;
745 $tab_result[$i][
'validator_statut'] = (int) $obj->validator_status;
746 $tab_result[$i][
'validator_status'] = (int) $obj->validator_status;
747 $tab_result[$i][
'validator_photo'] = (
string) $obj->validator_photo;
752 $this->holiday = $tab_result;
756 $this->error =
"Error ".$this->db->lasterror();
769 public function validate($user =
null, $notrigger = 0)
771 global
$conf, $langs;
772 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
776 $checkBalance = getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
778 if ($checkBalance > 0) {
779 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
780 $daysAsked =
num_open_day($this->date_debut, $this->date_fin, 0, 1, 0,
'', $this->fk_user);
782 if (($balance - $daysAsked) < 0 &&
getDolGlobalString(
'HOLIDAY_DISALLOW_NEGATIVE_BALANCE')) {
783 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
789 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref) || $this->
ref == $this->
id) {
790 $num = $this->getNextNumRef(
null);
797 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
798 $sql .=
" fk_user_valid = ".((int) $user->id).
",";
799 $sql .=
" date_valid = '".$this->db->idate(
dol_now()).
"',";
800 if (!empty($this->
status) && is_numeric($this->
status)) {
801 $sql .=
" statut = ".((int) $this->
status).
",";
803 $this->error =
'Property status must be a numeric value';
806 $sql .=
" ref = '".$this->db->escape($num).
"'";
807 $sql .=
" WHERE rowid = ".((int) $this->
id);
811 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
812 $resql = $this->db->query($sql);
815 $this->errors[] =
"Error ".$this->db->lasterror();
821 $result = $this->call_trigger(
'HOLIDAY_VALIDATE', $user);
830 $this->oldref = $this->ref;
833 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
835 $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) .
"'";
836 $sql .=
" WHERE filename LIKE '" . $this->db->escape($this->
ref) .
"%' AND filepath = 'holiday/" . $this->db->escape($this->
ref) .
"' and entity = " . ((int)
$conf->entity);
837 $resql = $this->db->query($sql);
840 $this->error = $this->db->lasterror();
842 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'holiday/".$this->db->escape($this->newref).
"'";
843 $sql .=
" WHERE filepath = 'holiday/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
844 $resql = $this->db->query($sql);
847 $this->error = $this->db->lasterror();
853 $dirsource =
$conf->holiday->multidir_output[$this->entity] .
'/' . $oldref;
854 $dirdest =
$conf->holiday->multidir_output[$this->entity] .
'/' . $newref;
855 if (!$error && file_exists($dirsource)) {
856 dol_syslog(get_class($this) .
"::validate rename dir " . $dirsource .
" into " . $dirdest);
857 if (@rename($dirsource, $dirdest)) {
860 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^' . preg_quote($oldref,
'/'));
861 foreach ($listoffiles as $fileentry) {
862 $dirsource = $fileentry[
'name'];
863 $dirdest = preg_replace(
'/^' . preg_quote($oldref,
'/') .
'/', $newref, $dirsource);
864 $dirsource = $fileentry[
'path'] .
'/' . $dirsource;
865 $dirdest = $fileentry[
'path'] .
'/' . $dirdest;
866 @rename($dirsource, $dirdest);
876 foreach ($this->errors as $errmsg) {
877 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
878 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
880 $this->db->rollback();
896 public function approve($user =
null, $notrigger = 0)
900 $checkBalance = getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
902 if ($checkBalance > 0) {
903 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
904 $daysAsked =
num_open_day($this->date_debut, $this->date_fin, 0, 1, 0,
'', $this->fk_user);
906 if (($balance - $daysAsked) < 0 &&
getDolGlobalString(
'HOLIDAY_DISALLOW_NEGATIVE_BALANCE')) {
907 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
913 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
914 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
915 if (!empty($this->date_debut)) {
916 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
920 if (!empty($this->date_fin)) {
921 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
925 $sql .=
" halfday = ".((int) $this->halfday).
",";
926 if (!empty($this->
status) && is_numeric($this->
status)) {
927 $sql .=
" statut = ".((int) $this->
status).
",";
931 if (!empty($this->fk_validator)) {
932 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
936 if (!empty($this->date_valid)) {
937 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
939 $sql .=
" date_valid = NULL,";
941 if (!empty($this->fk_user_valid)) {
942 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
944 $sql .=
" fk_user_valid = NULL,";
946 if (!empty($this->date_approval)) {
947 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
949 $sql .=
" date_approval = NULL,";
951 if (!empty($this->fk_user_approve)) {
952 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
954 $sql .=
" fk_user_approve = NULL,";
956 if (!empty($this->date_refuse)) {
957 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
959 $sql .=
" date_refuse = NULL,";
961 if (!empty($this->fk_user_refuse)) {
962 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
964 $sql .=
" fk_user_refuse = NULL,";
966 if (!empty($this->date_cancel)) {
967 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
969 $sql .=
" date_cancel = NULL,";
971 if (!empty($this->fk_user_cancel)) {
972 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
974 $sql .=
" fk_user_cancel = NULL,";
976 if (!empty($this->detail_refuse)) {
977 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
979 $sql .=
" detail_refuse = NULL";
981 $sql .=
" WHERE rowid = ".((int) $this->
id);
985 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
986 $resql = $this->db->query($sql);
989 $this->errors[] =
"Error ".$this->db->lasterror();
995 $result = $this->call_trigger(
'HOLIDAY_APPROVE', $user);
1005 foreach ($this->errors as $errmsg) {
1006 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
1007 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1009 $this->db->rollback();
1012 $this->db->commit();
1024 public function update($user =
null, $notrigger = 0)
1028 $checkBalance = getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
1030 if ($checkBalance > 0 && $this->
status != self::STATUS_DRAFT && $this->
status != self::STATUS_CANCELED) {
1031 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
1032 $daysAsked =
num_open_day($this->date_debut, $this->date_fin, 0, 1, 0,
'', $this->fk_user);
1034 if (($balance - $daysAsked) < 0 &&
getDolGlobalString(
'HOLIDAY_DISALLOW_NEGATIVE_BALANCE')) {
1035 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1041 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
1043 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
1045 if (!empty($this->date_create)) {
1046 $sql .=
" date_create = '".$this->db->idate($this->date_create).
"',";
1050 if (!empty($this->date_debut)) {
1051 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
1055 if (!empty($this->date_fin)) {
1056 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
1060 $sql .=
" halfday = ".((int) $this->halfday).
",";
1061 if (!empty($this->
status) && is_numeric($this->
status)) {
1062 $sql .=
" statut = ".((int) $this->
status).
",";
1066 if (!empty($this->fk_validator)) {
1067 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
1071 if (!empty($this->date_valid)) {
1072 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1074 $sql .=
" date_valid = NULL,";
1076 if (!empty($this->fk_user_valid)) {
1077 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
1079 $sql .=
" fk_user_valid = NULL,";
1081 if (!empty($this->date_approval)) {
1082 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
1084 $sql .=
" date_approval = NULL,";
1086 if (!empty($this->fk_user_approve)) {
1087 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
1089 $sql .=
" fk_user_approve = NULL,";
1091 if (!empty($this->date_refuse)) {
1092 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
1094 $sql .=
" date_refuse = NULL,";
1096 if (!empty($this->fk_user_refuse)) {
1097 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
1099 $sql .=
" fk_user_refuse = NULL,";
1101 if (!empty($this->date_cancel)) {
1102 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
1104 $sql .=
" date_cancel = NULL,";
1106 if (!empty($this->fk_user_cancel)) {
1107 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
1109 $sql .=
" fk_user_cancel = NULL,";
1111 if (!empty($this->detail_refuse)) {
1112 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1114 $sql .=
" detail_refuse = NULL";
1117 $sql .=
" WHERE rowid = ".((int) $this->
id);
1121 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1122 $resql = $this->db->query($sql);
1125 $this->errors[] =
"Error ".$this->db->lasterror();
1136 if (!$notrigger && $user !==
null) {
1138 $result = $this->call_trigger(
'HOLIDAY_MODIFY', $user);
1148 foreach ($this->errors as $errmsg) {
1149 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1150 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1152 $this->db->rollback();
1155 $this->db->commit();
1168 public function delete($user, $notrigger = 0)
1170 global
$conf, $langs;
1173 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1174 $sql .=
" WHERE rowid=".((int) $this->
id);
1178 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1179 $resql = $this->db->query($sql);
1182 $this->errors[] =
"Error ".$this->db->lasterror();
1188 $result = $this->call_trigger(
'HOLIDAY_DELETE', $user);
1198 foreach ($this->errors as $errmsg) {
1199 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1200 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1202 $this->db->rollback();
1205 $this->db->commit();
1227 foreach ($this->holiday as $infos_CP) {
1238 if ($halfday == 0) {
1239 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1242 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1245 } elseif ($halfday == -1) {
1247 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1248 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1252 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1253 if ($dateStart < $dateEnd) {
1256 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1260 } elseif ($halfday == 1) {
1262 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1263 if ($dateStart < $dateEnd) {
1266 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1270 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1271 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1275 } elseif ($halfday == 2) {
1277 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1278 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1282 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1283 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1288 dol_print_error(
null,
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1307 $isavailablemorning =
true;
1308 $isavailableafternoon =
true;
1311 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1312 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1313 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1314 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1315 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->db->idate($timestamp).
"'";
1316 if ($status !=
'-1') {
1317 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1320 $resql = $this->db->query($sql);
1322 $num_rows = $this->db->num_rows($resql);
1323 if ($num_rows > 0) {
1324 $arrayofrecord = array();
1326 while ($i < $num_rows) {
1327 $obj = $this->db->fetch_object($resql);
1330 $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);
1335 $isavailablemorning =
true;
1336 foreach ($arrayofrecord as $record) {
1337 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1340 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1343 $isavailablemorning =
false;
1346 $isavailableafternoon =
true;
1347 foreach ($arrayofrecord as $record) {
1348 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1351 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1354 $isavailableafternoon =
false;
1362 $result = array(
'morning' => (
int) $isavailablemorning,
'afternoon' => (
int) $isavailableafternoon);
1363 if (!$isavailablemorning) {
1364 $result[
'morning_reason'] =
'leave_request';
1366 if (!$isavailableafternoon) {
1367 $result[
'afternoon_reason'] =
'leave_request';
1382 $langs->load(
'holiday');
1383 $nofetch = !empty($params[
'nofetch']);
1386 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1387 if (isset($this->
status)) {
1388 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1390 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1392 if (!$nofetch && !empty($this->fk_type)) {
1393 $typeleaves = $this->
getTypes(1, -1);
1394 if (empty($typeleaves[$this->fk_type])) {
1395 $labeltoshow = $langs->trans(
"TypeWasDisabledOrRemoved", $this->fk_type);
1397 $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']);
1399 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type") .
':</b> ' . $labeltoshow;
1401 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1402 $listhalfday = array(
1403 'morning' => $langs->trans(
"Morning"),
1404 "afternoon" => $langs->trans(
"Afternoon")
1406 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ?
'afternoon' :
'morning';
1407 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ?
'morning' :
'afternoon';
1408 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateDebCP') .
'</b>: '.
dol_print_date($this->date_debut,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1409 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateFinCP') .
'</b>: '.
dol_print_date($this->date_fin,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1425 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1427 global
$conf, $langs, $hookmanager;
1429 if (!empty(
$conf->dol_no_mouse_hover)) {
1436 'objecttype' => $this->element,
1439 $classfortooltip =
'classfortooltip';
1442 $classfortooltip =
'classforajaxtooltip';
1443 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1449 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1454 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1455 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1456 $add_save_lastsearch_values = 1;
1458 if ($add_save_lastsearch_values) {
1459 $url .=
'&save_lastsearch_values=1';
1464 if (empty($notooltip)) {
1466 $label = $langs->trans(
"ShowMyObject");
1467 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1469 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1470 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1472 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1475 $linkstart =
'<a href="'.$url.
'"';
1476 $linkstart .= $linkclose.
'>';
1479 $result .= $linkstart;
1482 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1484 if ($withpicto != 2) {
1485 $result .= $this->ref;
1487 $result .= $linkend;
1490 $hookmanager->initHooks(array($this->element .
'dao'));
1491 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1492 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1494 $result = $hookmanager->resPrint;
1496 $result .= $hookmanager->resPrint;
1522 public function LibStatut($status, $mode = 0, $startdate =
'')
1527 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1535 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1543 $statusType =
'status6';
1544 if (!empty($startdate) && $startdate >=
dol_now()) {
1545 $statusType =
'status4';
1546 $params = array(
'tooltip' => $this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1548 if ($status == self::STATUS_DRAFT) {
1549 $statusType =
'status0';
1551 if ($status == self::STATUS_VALIDATED) {
1552 $statusType =
'status1';
1554 if ($status == self::STATUS_CANCELED) {
1555 $statusType =
'status9';
1557 if ($status == self::STATUS_REFUSED) {
1558 $statusType =
'status9';
1561 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1573 public function selectStatutCP($selected = 0, $htmlname =
'select_statut', $morecss =
'minwidth125')
1578 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1579 $nb = count($name) + 1;
1582 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1583 $out .=
'<option value="-1"> </option>'.
"\n";
1586 for ($i = 1; $i < $nb; $i++) {
1587 if ($i == $selected) {
1588 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1590 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1594 $out .=
"</select>\n";
1597 $out .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($showempty < 0 ? (
string) $showempty :
'-1'), $morecss);
1611 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1612 $sql .=
" value = '".$this->db->escape($value).
"'";
1613 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1615 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1616 $result = $this->db->query($sql);
1634 $sql =
"SELECT value";
1635 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1636 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1638 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1639 $result = $this->db->query($sql);
1642 $obj = $this->db->fetch_object($result);
1645 if ($createifnotfound) {
1646 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1647 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->db->escape($createifnotfound).
"')";
1648 $result = $this->db->query($sql);
1650 return $createifnotfound;
1652 $this->error = $this->db->lasterror();
1663 $this->error = $this->db->lasterror();
1678 global $user, $langs;
1682 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1683 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1684 $langs->load(
"holiday");
1694 if ($stringInDBForLastUpdate <
'20000101000000') {
1695 $stringInDBForLastUpdate =
'20000101000000';
1706 while ($yearMonthLastUpdate < $yearMonthNow) {
1712 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1713 $nbUser = count($users);
1715 $typeleaves = $this->
getTypes(1, 1);
1718 foreach ($users as $userCounter) {
1719 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1720 if (empty($nbDaysToAdd)) {
1724 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1726 $nowHoliday = (float) $userCounter[
'nb_holiday'];
1727 $newSolde = $nowHoliday + $nbDaysToAdd;
1730 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidayMonthlyCredit'), $newSolde, $userCounter[
'type']);
1732 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1735 $this->db->rollback();
1739 if (empty($decrease)) {
1744 $filter =
" AND cp.statut = ".((int) self::STATUS_APPROVED);
1747 $filter .=
" AND cp.fk_type = ".((int) $userCounter[
'type']);
1748 $this->
fetchByUser($userCounter[
'id'],
'', $filter);
1750 if (empty($this->holiday)) {
1754 $startOfMonth =
dol_mktime(0, 0, 0, (
int) $month, 1, (
int) $year, 1);
1757 foreach ($this->holiday as $obj) {
1758 $startDate = $obj[
'date_debut_gmt'];
1759 $endDate = $obj[
'date_fin_gmt'];
1761 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1762 $startDate = $startOfMonth;
1765 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1766 $endDate = $endOfMonth;
1769 $nbDaysToDeduct = (int)
num_open_day($startDate, $endDate, 0, 1, $obj[
'halfday'], $obj[
'country_id'], $obj[
'fk_user']);
1771 if ($nbDaysToDeduct <= 0) {
1775 $newSolde -= $nbDaysToDeduct;
1778 $this->
addLogCP($user->id, $userCounter[
'rowid'], $obj[
'ref'].
' - '.$langs->trans(
'HolidayConsumption'), $newSolde, $userCounter[
'type']);
1780 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1783 $this->db->rollback();
1791 $lastUpdate =
dol_mktime(0, 0, 0, (
int) $newMonth[
'month'], 1, (
int) $newMonth[
'year']);
1793 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1794 $sql .=
" value = '".$this->db->escape(
dol_print_date($lastUpdate,
'%Y%m%d%H%M%S')).
"'";
1795 $sql .=
" WHERE name = 'lastUpdate'";
1796 $result = $this->db->query($sql);
1799 $this->db->rollback();
1803 $this->db->commit();
1813 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1814 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1815 $resql = $this->db->query($sql);
1817 $num = $this->db->num_rows($resql);
1821 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1822 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1823 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1824 $result = $this->db->query($sql);
1827 $this->errors[] = $this->db->lasterror();
1831 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1832 $sql .= ((float) $nbHoliday);
1833 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1834 $result = $this->db->query($sql);
1837 $this->errors[] = $this->db->lasterror();
1841 $this->errors[] = $this->db->lasterror();
1864 dol_syslog(get_class($this).
'::createCPusers');
1865 $arrayofusers = $this->
fetchUsers(
false,
true);
1867 foreach ($arrayofusers as $users) {
1868 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1869 $sql .=
" (fk_user, nb_holiday)";
1870 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1872 $resql = $this->db->query($sql);
1878 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1879 $sql .=
" (fk_user, nb_holiday)";
1880 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1882 $resql = $this->db->query($sql);
1898 $sql =
"SELECT nb_holiday";
1899 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1900 $sql .=
" WHERE fk_user = ".(int) $user_id;
1902 $sql .=
" AND fk_type = ".(int) $fk_type;
1905 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1906 $result = $this->db->query($sql);
1908 $obj = $this->db->fetch_object($result);
1911 return $obj->nb_holiday;
1928 public function fetchUsers($stringlist =
true, $type =
true, $filters =
'')
1930 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1937 $sql .=
" DISTINCT";
1940 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1943 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1944 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1945 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1946 $sql .=
" OR u.entity = 0)";
1948 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1950 $sql .=
" AND u.statut > 0";
1951 $sql .=
" AND u.employee = 1";
1956 $resql = $this->db->query($sql);
1961 $num = $this->db->num_rows($resql);
1966 $obj = $this->db->fetch_object($resql);
1969 $stringlist .= $obj->rowid;
1971 $stringlist .=
', '.$obj->rowid;
1980 $this->error =
"Error ".$this->db->lasterror();
1985 $sql =
"SELECT DISTINCT cpu.fk_user";
1986 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1987 $sql .=
" WHERE cpu.fk_user = u.rowid";
1992 $resql = $this->db->query($sql);
1997 $num = $this->db->num_rows($resql);
2002 $obj = $this->db->fetch_object($resql);
2005 $stringlist .= $obj->fk_user;
2007 $stringlist .=
', '.$obj->fk_user;
2016 $this->error =
"Error ".$this->db->lasterror();
2027 $sql .=
" DISTINCT";
2029 $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";
2030 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2033 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2034 $sql .=
" WHERE ((ug.fk_user = u.rowid";
2035 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
2036 $sql .=
" OR u.entity = 0)";
2038 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
2041 $sql .=
" AND u.statut > 0";
2042 $sql .=
" AND u.employee = 1";
2047 $resql = $this->db->query($sql);
2052 $tab_result = $this->holiday;
2053 $num = $this->db->num_rows($resql);
2057 $obj = $this->db->fetch_object($resql);
2059 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2060 $tab_result[$i][
'id'] = (int) $obj->rowid;
2061 $tab_result[$i][
'name'] = $obj->lastname;
2062 $tab_result[$i][
'lastname'] = $obj->lastname;
2063 $tab_result[$i][
'firstname'] = $obj->firstname;
2064 $tab_result[$i][
'gender'] = $obj->gender;
2065 $tab_result[$i][
'status'] = (int) $obj->status;
2066 $tab_result[$i][
'employee'] = (int) $obj->employee;
2067 $tab_result[$i][
'photo'] = $obj->photo;
2068 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
2069 $tab_result[$i][
'country_id'] = (int) $obj->country_id;
2079 $this->errors[] =
"Error ".$this->db->lasterror();
2084 $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";
2085 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
2086 $sql .=
" WHERE cpu.fk_user = u.rowid";
2091 $resql = $this->db->query($sql);
2096 $tab_result = $this->holiday;
2097 $num = $this->db->num_rows($resql);
2101 $obj = $this->db->fetch_object($resql);
2103 $tab_result[$i][
'rowid'] = $obj->rowid;
2104 $tab_result[$i][
'id'] = $obj->rowid;
2105 $tab_result[$i][
'name'] = $obj->lastname;
2106 $tab_result[$i][
'lastname'] = $obj->lastname;
2107 $tab_result[$i][
'firstname'] = $obj->firstname;
2108 $tab_result[$i][
'gender'] = $obj->gender;
2109 $tab_result[$i][
'status'] = $obj->status;
2110 $tab_result[$i][
'employee'] = $obj->employee;
2111 $tab_result[$i][
'photo'] = $obj->photo;
2112 $tab_result[$i][
'fk_user'] = $obj->fk_user;
2114 $tab_result[$i][
'type'] = $obj->fk_type;
2115 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
2123 $this->error =
"Error ".$this->db->lasterror();
2141 $users_validator = array();
2143 $sql =
"SELECT DISTINCT ur.fk_user";
2144 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2145 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2147 $sql .=
" SELECT DISTINCT ugu.fk_user";
2148 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2149 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2152 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
2153 $result = $this->db->query($sql);
2155 $num_rows = $this->db->num_rows($result);
2157 while ($i < $num_rows) {
2158 $objp = $this->db->fetch_object($result);
2159 array_push($users_validator, $objp->fk_user);
2162 return $users_validator;
2164 $this->error = $this->db->lasterror();
2165 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2178 $sql =
"SELECT count(u.rowid) as compteur";
2179 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2180 $sql .=
" WHERE u.statut > 0";
2182 $result = $this->db->query($sql);
2183 $object = $this->db->fetch_object($result);
2194 $sql =
"SELECT count(u.rowid) as compteur";
2195 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2196 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2198 $result = $this->db->query($sql);
2199 $object = $this->db->fetch_object($result);
2213 if (empty($userCP)) {
2216 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2231 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2239 if ($prev_solde == $new_solde) {
2246 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2247 $sql .=
"date_action,";
2248 $sql .=
"fk_user_action,";
2249 $sql .=
"fk_user_update,";
2250 $sql .=
"type_action,";
2251 $sql .=
"prev_solde,";
2252 $sql .=
"new_solde,";
2254 $sql .=
") VALUES (";
2255 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2256 $sql .=
" ".((int) $fk_user_action).
",";
2257 $sql .=
" ".((int) $fk_user_update).
",";
2258 $sql .=
" '".$this->db->escape($label).
"',";
2259 $sql .=
" ".((float) $prev_solde).
",";
2260 $sql .=
" ".((float) $new_solde).
",";
2261 $sql .=
" ".((int) $fk_type);
2264 $resql = $this->db->query($sql);
2267 $this->errors[] =
"Error ".$this->db->lasterror();
2272 $optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2277 foreach ($this->errors as $errmsg) {
2278 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2279 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2281 $this->db->rollback();
2284 $this->db->commit();
2299 $sql .=
" cpl.rowid,";
2300 $sql .=
" cpl.date_action,";
2301 $sql .=
" cpl.fk_user_action,";
2302 $sql .=
" cpl.fk_user_update,";
2303 $sql .=
" cpl.type_action,";
2304 $sql .=
" cpl.prev_solde,";
2305 $sql .=
" cpl.new_solde,";
2306 $sql .=
" cpl.fk_type";
2307 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2308 $sql .=
" WHERE cpl.rowid > 0";
2311 if (!empty($sqlwhere)) {
2312 $sql .=
" ".$sqlwhere;
2316 if (!empty($sqlorder)) {
2317 $sql .=
" ".$sqlorder;
2320 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2321 $resql = $this->db->query($sql);
2326 $tab_result = $this->logs;
2327 $num = $this->db->num_rows($resql);
2336 $obj = $this->db->fetch_object($resql);
2338 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2339 $tab_result[$i][
'id'] = (int) $obj->rowid;
2340 $tab_result[$i][
'date_action'] = (
string) $obj->date_action;
2341 $tab_result[$i][
'fk_user_action'] = (int) $obj->fk_user_action;
2342 $tab_result[$i][
'fk_user_update'] = (int) $obj->fk_user_update;
2343 $tab_result[$i][
'type_action'] = (
string) $obj->type_action;
2344 $tab_result[$i][
'prev_solde'] = (float) $obj->prev_solde;
2345 $tab_result[$i][
'new_solde'] = (float) $obj->new_solde;
2346 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
2351 $this->logs = $tab_result;
2355 $this->error =
"Error ".$this->db->lasterror();
2372 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2374 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int)
$mysoc->country_id).
')';
2375 $sql .=
" AND entity IN (0, ".getEntity(
'c_holiday_types').
")";
2377 $sql .=
" AND active = ".((int) $active);
2380 $sql .=
" AND affect = ".((int) $affect);
2382 $sql .=
" ORDER BY sortorder";
2384 $result = $this->db->query($sql);
2386 $num = $this->db->num_rows($result);
2389 while ($obj = $this->db->fetch_object($result)) {
2390 $types[$obj->rowid] = array(
2391 'id' => $obj->rowid,
2392 'rowid' => $obj->rowid,
2393 'code' => $obj->code,
2394 'label' => $obj->label,
2395 'affect' => $obj->affect,
2396 'delay' => $obj->delay,
2397 'newbymonth' => $obj->newbymonth
2421 $sql =
"SELECT f.rowid, f.statut as status,";
2422 $sql .=
" f.date_create as datec,";
2423 $sql .=
" f.tms as date_modification,";
2424 $sql .=
" f.date_valid as datev,";
2425 $sql .=
" f.date_approval as datea,";
2426 $sql .=
" f.date_refuse as dater,";
2427 $sql .=
" f.fk_user_create as fk_user_creation,";
2428 $sql .=
" f.fk_user_modif as fk_user_modification,";
2429 $sql .=
" f.fk_user_valid as fk_user_validation,";
2430 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2431 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2432 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2433 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2434 $sql .=
" WHERE f.rowid = ".((int) $id);
2435 $sql .=
" AND f.entity = ".$conf->entity;
2437 $resql = $this->db->query($sql);
2439 if ($this->db->num_rows($resql)) {
2440 $obj = $this->db->fetch_object($resql);
2442 $this->
id = $obj->rowid;
2444 $this->date_creation = $this->db->jdate($obj->datec);
2445 $this->date_modification = $this->db->jdate($obj->date_modification);
2446 $this->date_validation = $this->db->jdate($obj->datev);
2447 $this->date_approval = $this->db->jdate($obj->datea);
2449 $this->user_creation_id = $obj->fk_user_creation;
2450 $this->user_validation_id = $obj->fk_user_validation;
2451 $this->user_modification_id = $obj->fk_user_modification;
2454 if ($obj->fk_user_approval_done) {
2455 $this->fk_user_approve = $obj->fk_user_approval_done;
2459 $this->db->free($resql);
2475 global $user, $langs;
2479 $this->specimen = 1;
2481 $this->fk_user = $user->id;
2483 $this->date_debut =
dol_now();
2484 $this->date_fin =
dol_now() + (24 * 3600);
2485 $this->date_valid =
dol_now();
2486 $this->fk_validator = $user->id;
2503 $this->nb = array();
2505 $sql =
"SELECT count(h.rowid) as nb";
2506 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2507 $sql .=
" WHERE h.statut > 1";
2508 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2509 if (!$user->hasRight(
'holiday',
'readall')) {
2510 $userchildids = $user->getAllChildIds(1);
2511 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2512 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2515 $resql = $this->db->query($sql);
2517 while ($obj = $this->db->fetch_object($resql)) {
2518 $this->nb[
"holidays"] = $obj->nb;
2520 $this->db->free($resql);
2524 $this->error = $this->db->error();
2539 global
$conf, $langs;
2547 $sql =
"SELECT h.rowid, h.date_debut";
2548 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2549 $sql .=
" WHERE h.statut = 2";
2550 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2551 if (!$user->hasRight(
'holiday',
'read_all')) {
2552 $userchildids = $user->getAllChildIds(1);
2553 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2554 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2557 $resql = $this->db->query($sql);
2559 $langs->load(
"members");
2562 $response->warning_delay =
$conf->holiday->approve->warning_delay / 60 / 60 / 24;
2563 $response->label = $langs->trans(
"HolidaysToApprove");
2564 $response->labelShort = $langs->trans(
"ToApprove");
2565 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2568 while ($obj = $this->db->fetch_object($resql)) {
2569 $response->nbtodo++;
2571 if ($this->db->jdate($obj->date_debut) < ($now -
$conf->holiday->approve->warning_delay)) {
2572 $response->nbtodolate++;
2579 $this->error = $this->db->error();
2594 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2596 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2597 $return .=
'<div class="info-box info-box-sm">';
2598 $return .=
'<span class="info-box-icon bg-infobox-action">';
2600 $return .=
'</span>';
2601 $return .=
'<div class="info-box-content">';
2602 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().
'</span>';
2603 if ($selected >= 0) {
2604 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2606 if (property_exists($this,
'fk_type')) {
2609 $return .=
'<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata[
'labeltype']).
'">'.
dol_escape_htmltag($arraydata[
'labeltype']).
'</div>';
2611 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2612 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_debut,
'day').
'</span>';
2613 $return .=
' <span class="opacitymedium small">'.$langs->trans(
"To").
'</span> ';
2614 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_fin,
'day').
'</span>';
2615 if (!empty($arraydata[
'nbopenedday'])) {
2616 $return .=
' ('.$arraydata[
'nbopenedday'].
')';
2619 if (method_exists($this,
'getLibStatut')) {
2620 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2622 $return .=
'</div>';
2623 $return .=
'</div>';
2624 $return .=
'</div>';
2640 global
$conf, $langs, $user;
2642 $outputlangs = $langs;
2647 $arrayfields = array(
2648 'user' =>
'Employee',
2650 'date_start' =>
'DateDebCP',
2651 'date_end' =>
'DateFinCP',
2652 'used_days' =>
'NbUseDaysCPShort',
2655 if (!empty($newlang)) {
2657 $outputlangs->setDefaultLang($newlang);
2659 $outputlangs->loadLangs(array(
'main',
'holiday',
'hrm'));
2662 $this->errors[] =
'Bad value for parameter mailto. Must be a valid email address.';
2666 $typeleaves = $this->
getTypes(1, -1);
2667 $arraytypeleaves = array();
2668 foreach ($typeleaves as $val) {
2669 $labeltoshow = ($outputlangs->trans($val[
'code']) != $val[
'code'] ? $outputlangs->trans($val[
'code']) : $val[
'label']);
2670 $arraytypeleaves[$val[
'rowid']] = $labeltoshow;
2672 $listhalfday = array(
'morning' => $outputlangs->trans(
"Morning"),
"afternoon" => $outputlangs->trans(
"Afternoon"));
2676 $year_month = sprintf(
"%04d", $prev_month[
"year"]).
'-'.sprintf(
"%02d", $prev_month[
"month"]);
2677 $arrayleaves = array();
2679 $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";
2680 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday cp";
2681 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user u ON cp.fk_user = u.rowid";
2682 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
") AND cp.rowid > 0";
2683 $sql .=
" AND cp.statut = ".Holiday::STATUS_APPROVED;
2685 $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).
"')";
2687 $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).
"') ";
2689 $sql .= $this->db->order(
"cp.fk_user, cp.date_debut",
"ASC");
2690 $resql = $this->db->query($sql);
2691 if (empty($resql)) {
2692 $this->errors[] = $this->db->lasterror();
2695 $num = $this->db->num_rows($resql);
2697 $tmpuser =
new User($this->db);
2698 while ($obj = $this->db->fetch_object($resql)) {
2699 $tmpuser->fetch($obj->fk_user);
2701 $date_start = $this->db->jdate($obj->date_debut,
true);
2702 $date_end = $this->db->jdate($obj->date_fin,
true);
2707 $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ?
'afternoon' :
'morning';
2708 $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ?
'morning' :
'afternoon';
2710 $halfdayinmonth = $obj->halfday;
2711 $starthalfdayinmonth = $starthalfday;
2712 $endhalfdayinmonth = $endhalfday;
2717 $date_start_inmonth = $this->db->jdate($obj->date_debut,
true);
2718 $date_end_inmonth = $this->db->jdate($obj->date_fin,
true);
2719 if ($tmpstart[
'year'] < $prev_month[
"year"] || $tmpstart[
'mon'] < $prev_month[
"month"]) {
2720 $date_start_inmonth =
dol_get_first_day($prev_month[
"year"], $prev_month[
"month"],
true);
2721 $starthalfdayinmonth =
'morning';
2722 if ($halfdayinmonth == 2) {
2723 $halfdayinmonth = 1;
2725 if ($halfdayinmonth == -1) {
2726 $halfdayinmonth = 0;
2729 if ($tmpend[
'year'] > $prev_month[
"year"] || $tmpend[
'mon'] > $prev_month[
"month"]) {
2730 $date_end_inmonth =
dol_get_last_day($prev_month[
"year"], $prev_month[
"month"],
true) - ((24 * 3600) - 1);
2731 $endhalfdayinmonth =
'afternoon';
2732 if ($halfdayinmonth == 2) {
2733 $halfdayinmonth = -1;
2735 if ($halfdayinmonth == 1) {
2736 $halfdayinmonth = 0;
2739 $arrayleaves[] = array(
2740 "user" => $tmpuser->getNomUrl(0,
'nolink', 0, 0, 24, 1),
2741 "type" => $arraytypeleaves[$obj->fk_type],
2742 "date_start" =>
dol_print_date($date_start_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$starthalfdayinmonth]).
')</span>',
2743 "date_end" =>
dol_print_date($date_end_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$endhalfdayinmonth]).
')</span>',
2744 "used_days" =>
num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth, $tmpuser->country_id, $obj->fk_user)
2749 $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;">';
2750 $outputarrayleaves .=
'<tr>';
2751 foreach ($arrayfields as $key => $label) {
2752 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;">';
2753 $outputarrayleaves .= $outputlangs->trans($label);
2754 $outputarrayleaves .=
'</td>';
2756 $outputarrayleaves .=
'</tr>';
2758 if (!empty($arrayleaves)) {
2759 foreach ($arrayleaves as $key => $fields) {
2760 $outputarrayleaves .=
'<tr>';
2761 foreach ($fields as $field => $value) {
2762 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;" id="'.$field.
'">';
2763 $outputarrayleaves .= $value;
2764 $outputarrayleaves .=
'</td>';
2766 $outputarrayleaves .=
'</tr>';
2769 $outputarrayleaves .=
'<tr>';
2770 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;" colspan="5">';
2771 $outputarrayleaves .= $outputlangs->trans(
"None");
2772 $outputarrayleaves .=
'</td>';
2773 $outputarrayleaves .=
'</tr>';
2775 $outputarrayleaves .=
'</table>';
2777 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2778 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2780 $formmail =
new FormMail($this->db);
2782 $templateLabel =
'';
2783 if (empty($template) || $template ==
'EmailTemplateCode') {
2784 $templateLabel =
'(HolidayHrInformationsPreviousMonth)';
2786 if (is_numeric($template)) {
2787 $templateId = $template;
2789 $templateLabel = $template;
2792 $mailtemplate = $formmail->getEMailTemplate($this->db,
"holiday", $user, $outputlangs, $templateId, 1, $templateLabel);
2794 if (is_numeric($mailtemplate) || empty($mailtemplate->topic)) {
2795 $this->errors[] =
'No mail template found for code "'.$templateLabel.
'" or id "'.$templateId.
'".';
2800 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $this);
2803 $subject =
make_substitutions($mailtemplate->topic, $substitutionarray, $outputlangs);
2807 $msg = preg_replace(
'/__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__/', $outputarrayleaves, $msg);
2808 $cmail =
new CMailFile($subject, $mailto, $from, $msg, array(), array(), array(),
'',
'', 0, 1);
2809 $result = $cmail->sendfile();
2810 if (!$result || !empty($cmail->error) || !empty($cmail->errors)) {
2811 $this->errors[] = $cmail->error;
2812 if (is_array($cmail->errors) && count($cmail->errors) > 0) {
2813 $this->errors = array_merge($this->errors, $cmail->errors);
2819 if (!empty($this->errors)) {
2820 $this->output .=
"\n";
2823 return ($error ? 1 : 0);
if(! $sortfield) if(! $sortorder) $object
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
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.
Class of the module paid holiday.
getTypes($active=-1, $affect=-1)
Return array with list of types.
getNomUrl($withpicto=0, $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clickable name (with picto eventually)
verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday=0)
Check if a user is on holiday (partially or completely) into a period.
validate($user=null, $notrigger=0)
Validate leave request.
info($id)
Load information on object.
updateBalance()
Update balance of vacations and check table of users for holidays is complete.
updateConfCP($name, $value)
Met à jour une option du module Holiday Payés.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
fetch($id, $ref='')
Load object in memory from database.
addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
addLogCP
verifNbUsers($userDolibarrWithoutCP, $userCP)
Compare 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)
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()
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.
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.
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
fetchUsers($stringlist=true, $type=true, $filters='')
Get list of Users or list of vacation balance.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
LibStatut($status, $mode=0, $startdate='')
Returns the label of a status.
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_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php