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($sqlFilter)) {
686 if (!empty($sqlOrder)) {
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 = ".((int)
$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) {
1239 if ($dateStart < $infos_CP[
'date_debut'] && $dateEnd > $infos_CP[
'date_fin']) {
1243 if ($halfday == 0) {
1244 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1247 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1250 } elseif ($halfday == -1) {
1252 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1253 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1257 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1258 if ($dateStart < $dateEnd) {
1261 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1265 } elseif ($halfday == 1) {
1267 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1268 if ($dateStart < $dateEnd) {
1271 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1275 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1276 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1280 } elseif ($halfday == 2) {
1282 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1283 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1287 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1288 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1293 dol_print_error(
null,
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1312 $isavailablemorning =
true;
1313 $isavailableafternoon =
true;
1316 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1317 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1318 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1319 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1320 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->db->idate($timestamp).
"'";
1321 if ($status !=
'-1') {
1322 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1325 $resql = $this->db->query($sql);
1327 $num_rows = $this->db->num_rows($resql);
1328 if ($num_rows > 0) {
1329 $arrayofrecord = array();
1331 while ($i < $num_rows) {
1332 $obj = $this->db->fetch_object($resql);
1335 $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);
1340 $isavailablemorning =
true;
1341 foreach ($arrayofrecord as $record) {
1342 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1345 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1348 $isavailablemorning =
false;
1351 $isavailableafternoon =
true;
1352 foreach ($arrayofrecord as $record) {
1353 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1356 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1359 $isavailableafternoon =
false;
1367 $result = array(
'morning' => (
int) $isavailablemorning,
'afternoon' => (
int) $isavailableafternoon);
1368 if (!$isavailablemorning) {
1369 $result[
'morning_reason'] =
'leave_request';
1371 if (!$isavailableafternoon) {
1372 $result[
'afternoon_reason'] =
'leave_request';
1387 $langs->load(
'holiday');
1388 $nofetch = !empty($params[
'nofetch']);
1391 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1392 if (isset($this->
status)) {
1393 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1395 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1397 if (!$nofetch && !empty($this->fk_type)) {
1398 $typeleaves = $this->
getTypes(1, -1);
1399 if (empty($typeleaves[$this->fk_type])) {
1400 $labeltoshow = $langs->trans(
"TypeWasDisabledOrRemoved", $this->fk_type);
1402 $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']);
1404 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type") .
':</b> ' . $labeltoshow;
1406 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1407 $listhalfday = array(
1408 'morning' => $langs->trans(
"Morning"),
1409 "afternoon" => $langs->trans(
"Afternoon")
1411 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ?
'afternoon' :
'morning';
1412 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ?
'morning' :
'afternoon';
1413 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateDebCP') .
'</b>: '.
dol_print_date($this->date_debut,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1414 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateFinCP') .
'</b>: '.
dol_print_date($this->date_fin,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1430 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1432 global
$conf, $langs, $hookmanager;
1434 if (!empty(
$conf->dol_no_mouse_hover)) {
1441 'objecttype' => $this->element,
1444 $classfortooltip =
'classfortooltip';
1447 $classfortooltip =
'classforajaxtooltip';
1448 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1454 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1459 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1460 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1461 $add_save_lastsearch_values = 1;
1463 if ($add_save_lastsearch_values) {
1464 $url .=
'&save_lastsearch_values=1';
1469 if (empty($notooltip)) {
1471 $label = $langs->trans(
"ShowMyObject");
1472 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1474 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1475 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1477 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1480 $linkstart =
'<a href="'.$url.
'"';
1481 $linkstart .= $linkclose.
'>';
1484 $result .= $linkstart;
1487 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1489 if ($withpicto != 2) {
1490 $result .= $this->ref;
1492 $result .= $linkend;
1495 $hookmanager->initHooks(array($this->element .
'dao'));
1496 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1497 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1499 $result = $hookmanager->resPrint;
1501 $result .= $hookmanager->resPrint;
1527 public function LibStatut($status, $mode = 0, $startdate =
'')
1532 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1540 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1548 $statusType =
'status6';
1549 if (!empty($startdate) && $startdate >=
dol_now()) {
1550 $statusType =
'status4';
1551 $params = array(
'tooltip' => $this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1553 if ($status == self::STATUS_DRAFT) {
1554 $statusType =
'status0';
1556 if ($status == self::STATUS_VALIDATED) {
1557 $statusType =
'status1';
1559 if ($status == self::STATUS_CANCELED) {
1560 $statusType =
'status9';
1562 if ($status == self::STATUS_REFUSED) {
1563 $statusType =
'status9';
1566 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1578 public function selectStatutCP($selected = 0, $htmlname =
'select_statut', $morecss =
'minwidth125')
1583 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1584 $nb = count($name) + 1;
1587 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1588 $out .=
'<option value="-1"> </option>'.
"\n";
1591 for ($i = 1; $i < $nb; $i++) {
1592 if ($i == $selected) {
1593 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1595 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1599 $out .=
"</select>\n";
1602 $out .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($showempty < 0 ? (
string) $showempty :
'-1'), $morecss);
1616 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1617 $sql .=
" value = '".$this->db->escape($value).
"'";
1618 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1620 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1621 $result = $this->db->query($sql);
1639 $sql =
"SELECT value";
1640 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1641 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1643 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1644 $result = $this->db->query($sql);
1647 $obj = $this->db->fetch_object($result);
1650 if ($createifnotfound) {
1651 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1652 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->db->escape($createifnotfound).
"')";
1653 $result = $this->db->query($sql);
1655 return $createifnotfound;
1657 $this->error = $this->db->lasterror();
1668 $this->error = $this->db->lasterror();
1683 global $user, $langs;
1687 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1688 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1689 $langs->load(
"holiday");
1701 if (empty($stringInDBForLastUpdate)) {
1705 if ($stringInDBForLastUpdate <
'20000101000000') {
1706 $stringInDBForLastUpdate =
'20000101000000';
1717 while ($yearMonthLastUpdate < $yearMonthNow) {
1723 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1724 $nbUser = count($users);
1726 $typeleaves = $this->
getTypes(1, 1);
1729 foreach ($users as $userCounter) {
1730 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1731 if (empty($nbDaysToAdd)) {
1735 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1737 $nowHoliday = (float) $userCounter[
'nb_holiday'];
1738 $newSolde = $nowHoliday + $nbDaysToAdd;
1741 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidayMonthlyCredit'), $newSolde, $userCounter[
'type']);
1743 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1746 $this->db->rollback();
1750 if (empty($decrease)) {
1755 $filter =
" AND cp.statut = ".((int) self::STATUS_APPROVED);
1758 $filter .=
" AND cp.fk_type = ".((int) $userCounter[
'type']);
1759 $this->
fetchByUser($userCounter[
'id'],
'', $filter);
1761 if (empty($this->holiday)) {
1765 $startOfMonth =
dol_mktime(0, 0, 0, (
int) $month, 1, (
int) $year, 1);
1768 foreach ($this->holiday as $obj) {
1769 $startDate = $obj[
'date_debut_gmt'];
1770 $endDate = $obj[
'date_fin_gmt'];
1772 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1773 $startDate = $startOfMonth;
1776 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1777 $endDate = $endOfMonth;
1780 $nbDaysToDeduct = (int)
num_open_day($startDate, $endDate, 0, 1, $obj[
'halfday'], $obj[
'country_id'], $obj[
'fk_user']);
1782 if ($nbDaysToDeduct <= 0) {
1786 $newSolde -= $nbDaysToDeduct;
1789 $this->
addLogCP($user->id, $userCounter[
'rowid'], $obj[
'ref'].
' - '.$langs->trans(
'HolidayConsumption'), $newSolde, $userCounter[
'type']);
1791 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1794 $this->db->rollback();
1802 $lastUpdate =
dol_mktime(0, 0, 0, (
int) $newMonth[
'month'], 1, (
int) $newMonth[
'year']);
1804 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1805 $sql .=
" value = '".$this->db->escape(
dol_print_date($lastUpdate,
'%Y%m%d%H%M%S')).
"'";
1806 $sql .=
" WHERE name = 'lastUpdate'";
1807 $result = $this->db->query($sql);
1810 $this->db->rollback();
1814 $this->db->commit();
1824 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1825 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1826 $resql = $this->db->query($sql);
1828 $num = $this->db->num_rows($resql);
1832 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1833 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1834 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1835 $result = $this->db->query($sql);
1838 $this->errors[] = $this->db->lasterror();
1842 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1843 $sql .= ((float) $nbHoliday);
1844 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1845 $result = $this->db->query($sql);
1848 $this->errors[] = $this->db->lasterror();
1852 $this->errors[] = $this->db->lasterror();
1875 dol_syslog(get_class($this).
'::createCPusers');
1876 $arrayofusers = $this->
fetchUsers(
false,
true);
1878 foreach ($arrayofusers as $users) {
1879 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1880 $sql .=
" (fk_user, nb_holiday)";
1881 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1883 $resql = $this->db->query($sql);
1889 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1890 $sql .=
" (fk_user, nb_holiday)";
1891 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1893 $resql = $this->db->query($sql);
1909 $sql =
"SELECT nb_holiday";
1910 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1911 $sql .=
" WHERE fk_user = ".(int) $user_id;
1913 $sql .=
" AND fk_type = ".(int) $fk_type;
1916 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1917 $result = $this->db->query($sql);
1919 $obj = $this->db->fetch_object($result);
1922 return $obj->nb_holiday;
1939 public function fetchUsers($stringlist =
true, $type =
true, $sqlFilters =
'')
1941 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1948 $sql .=
" DISTINCT";
1951 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1954 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1955 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1956 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1957 $sql .=
" OR u.entity = 0)";
1959 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1961 $sql .=
" AND u.statut > 0";
1962 $sql .=
" AND u.employee = 1";
1964 $sql .= $sqlFilters;
1967 $resql = $this->db->query($sql);
1972 $num = $this->db->num_rows($resql);
1977 $obj = $this->db->fetch_object($resql);
1980 $stringlist .= $obj->rowid;
1982 $stringlist .=
', '.$obj->rowid;
1991 $this->error =
"Error ".$this->db->lasterror();
1996 $sql =
"SELECT DISTINCT cpu.fk_user";
1997 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1998 $sql .=
" WHERE cpu.fk_user = u.rowid";
2000 $sql .= $sqlFilters;
2003 $resql = $this->db->query($sql);
2008 $num = $this->db->num_rows($resql);
2013 $obj = $this->db->fetch_object($resql);
2016 $stringlist .= $obj->fk_user;
2018 $stringlist .=
', '.$obj->fk_user;
2027 $this->error =
"Error ".$this->db->lasterror();
2038 $sql .=
" DISTINCT";
2040 $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";
2041 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2044 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2045 $sql .=
" WHERE ((ug.fk_user = u.rowid";
2046 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
2047 $sql .=
" OR u.entity = 0)";
2049 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
2052 $sql .=
" AND u.statut > 0";
2053 $sql .=
" AND u.employee = 1";
2055 $sql .= $sqlFilters;
2058 $resql = $this->db->query($sql);
2063 $tab_result = $this->holiday;
2064 $num = $this->db->num_rows($resql);
2068 $obj = $this->db->fetch_object($resql);
2070 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2071 $tab_result[$i][
'id'] = (int) $obj->rowid;
2072 $tab_result[$i][
'name'] = $obj->lastname;
2073 $tab_result[$i][
'lastname'] = $obj->lastname;
2074 $tab_result[$i][
'firstname'] = $obj->firstname;
2075 $tab_result[$i][
'gender'] = $obj->gender;
2076 $tab_result[$i][
'status'] = (int) $obj->status;
2077 $tab_result[$i][
'employee'] = (int) $obj->employee;
2078 $tab_result[$i][
'photo'] = $obj->photo;
2079 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
2080 $tab_result[$i][
'country_id'] = (int) $obj->country_id;
2090 $this->errors[] =
"Error ".$this->db->lasterror();
2095 $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";
2096 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
2097 $sql .=
" WHERE cpu.fk_user = u.rowid";
2099 $sql .= $sqlFilters;
2102 $resql = $this->db->query($sql);
2107 $tab_result = $this->holiday;
2108 $num = $this->db->num_rows($resql);
2112 $obj = $this->db->fetch_object($resql);
2114 $tab_result[$i][
'rowid'] = $obj->rowid;
2115 $tab_result[$i][
'id'] = $obj->rowid;
2116 $tab_result[$i][
'name'] = $obj->lastname;
2117 $tab_result[$i][
'lastname'] = $obj->lastname;
2118 $tab_result[$i][
'firstname'] = $obj->firstname;
2119 $tab_result[$i][
'gender'] = $obj->gender;
2120 $tab_result[$i][
'status'] = $obj->status;
2121 $tab_result[$i][
'employee'] = $obj->employee;
2122 $tab_result[$i][
'photo'] = $obj->photo;
2123 $tab_result[$i][
'fk_user'] = $obj->fk_user;
2125 $tab_result[$i][
'type'] = $obj->fk_type;
2126 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
2134 $this->error =
"Error ".$this->db->lasterror();
2152 $users_validator = array();
2154 $sql =
"SELECT DISTINCT ur.fk_user";
2155 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2156 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2158 $sql .=
" SELECT DISTINCT ugu.fk_user";
2159 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2160 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2163 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
2164 $result = $this->db->query($sql);
2166 $num_rows = $this->db->num_rows($result);
2168 while ($i < $num_rows) {
2169 $objp = $this->db->fetch_object($result);
2170 array_push($users_validator, $objp->fk_user);
2173 return $users_validator;
2175 $this->error = $this->db->lasterror();
2176 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2189 $sql =
"SELECT count(u.rowid) as compteur";
2190 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2191 $sql .=
" WHERE u.statut > 0";
2193 $result = $this->db->query($sql);
2194 $object = $this->db->fetch_object($result);
2205 $sql =
"SELECT count(u.rowid) as compteur";
2206 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2207 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2209 $result = $this->db->query($sql);
2210 $object = $this->db->fetch_object($result);
2224 if (empty($userCP)) {
2227 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2242 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2250 if ($prev_solde == $new_solde) {
2257 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2258 $sql .=
"date_action,";
2259 $sql .=
"fk_user_action,";
2260 $sql .=
"fk_user_update,";
2261 $sql .=
"type_action,";
2262 $sql .=
"prev_solde,";
2263 $sql .=
"new_solde,";
2265 $sql .=
") VALUES (";
2266 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2267 $sql .=
" ".((int) $fk_user_action).
",";
2268 $sql .=
" ".((int) $fk_user_update).
",";
2269 $sql .=
" '".$this->db->escape($label).
"',";
2270 $sql .=
" ".((float) $prev_solde).
",";
2271 $sql .=
" ".((float) $new_solde).
",";
2272 $sql .=
" ".((int) $fk_type);
2275 $resql = $this->db->query($sql);
2278 $this->errors[] =
"Error ".$this->db->lasterror();
2283 $optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2288 foreach ($this->errors as $errmsg) {
2289 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2290 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2292 $this->db->rollback();
2295 $this->db->commit();
2310 $sql .=
" cpl.rowid,";
2311 $sql .=
" cpl.date_action,";
2312 $sql .=
" cpl.fk_user_action,";
2313 $sql .=
" cpl.fk_user_update,";
2314 $sql .=
" cpl.type_action,";
2315 $sql .=
" cpl.prev_solde,";
2316 $sql .=
" cpl.new_solde,";
2317 $sql .=
" cpl.fk_type";
2318 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2319 $sql .=
" WHERE cpl.rowid > 0";
2322 if (!empty($sqlwhere)) {
2323 $sql .=
" ".$sqlwhere;
2327 if (!empty($sqlorder)) {
2328 $sql .=
" ".$sqlorder;
2331 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2332 $resql = $this->db->query($sql);
2337 $tab_result = $this->logs;
2338 $num = $this->db->num_rows($resql);
2347 $obj = $this->db->fetch_object($resql);
2349 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2350 $tab_result[$i][
'id'] = (int) $obj->rowid;
2351 $tab_result[$i][
'date_action'] = (
string) $obj->date_action;
2352 $tab_result[$i][
'fk_user_action'] = (int) $obj->fk_user_action;
2353 $tab_result[$i][
'fk_user_update'] = (int) $obj->fk_user_update;
2354 $tab_result[$i][
'type_action'] = (
string) $obj->type_action;
2355 $tab_result[$i][
'prev_solde'] = (float) $obj->prev_solde;
2356 $tab_result[$i][
'new_solde'] = (float) $obj->new_solde;
2357 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
2362 $this->logs = $tab_result;
2366 $this->error =
"Error ".$this->db->lasterror();
2383 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2384 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2385 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int)
$mysoc->country_id).
')';
2386 $sql .=
" AND entity IN (0, ".getEntity(
'c_holiday_types').
")";
2388 $sql .=
" AND active = ".((int) $active);
2391 $sql .=
" AND affect = ".((int) $affect);
2393 $sql .=
" ORDER BY sortorder";
2395 $result = $this->db->query($sql);
2397 $num = $this->db->num_rows($result);
2400 while ($obj = $this->db->fetch_object($result)) {
2401 $types[$obj->rowid] = array(
2402 'id' => $obj->rowid,
2403 'rowid' => $obj->rowid,
2404 'code' => $obj->code,
2405 'label' => $obj->label,
2406 'affect' => $obj->affect,
2407 'delay' => $obj->delay,
2408 'newbymonth' => $obj->newbymonth
2432 $sql =
"SELECT f.rowid, f.statut as status,";
2433 $sql .=
" f.date_create as datec,";
2434 $sql .=
" f.tms as date_modification,";
2435 $sql .=
" f.date_valid as datev,";
2436 $sql .=
" f.date_approval as datea,";
2437 $sql .=
" f.date_refuse as dater,";
2438 $sql .=
" f.fk_user_create as fk_user_creation,";
2439 $sql .=
" f.fk_user_modif as fk_user_modification,";
2440 $sql .=
" f.fk_user_valid as fk_user_validation,";
2441 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2442 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2443 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2444 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2445 $sql .=
" WHERE f.rowid = ".((int) $id);
2446 $sql .=
" AND f.entity = ".((int)
$conf->entity);
2448 $resql = $this->db->query($sql);
2450 if ($this->db->num_rows($resql)) {
2451 $obj = $this->db->fetch_object($resql);
2453 $this->
id = $obj->rowid;
2455 $this->date_creation = $this->db->jdate($obj->datec);
2456 $this->date_modification = $this->db->jdate($obj->date_modification);
2457 $this->date_validation = $this->db->jdate($obj->datev);
2458 $this->date_approval = $this->db->jdate($obj->datea);
2460 $this->user_creation_id = $obj->fk_user_creation;
2461 $this->user_validation_id = $obj->fk_user_validation;
2462 $this->user_modification_id = $obj->fk_user_modification;
2465 if ($obj->fk_user_approval_done) {
2466 $this->fk_user_approve = $obj->fk_user_approval_done;
2470 $this->db->free($resql);
2486 global $user, $langs;
2490 $this->specimen = 1;
2492 $this->fk_user = $user->id;
2494 $this->date_debut =
dol_now();
2495 $this->date_fin =
dol_now() + (24 * 3600);
2496 $this->date_valid =
dol_now();
2497 $this->fk_validator = $user->id;
2514 $this->nb = array();
2516 $sql =
"SELECT count(h.rowid) as nb";
2517 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2518 $sql .=
" WHERE h.statut > 1";
2519 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2520 if (!$user->hasRight(
'holiday',
'readall')) {
2521 $userchildids = $user->getAllChildIds(1);
2522 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2523 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2526 $resql = $this->db->query($sql);
2528 while ($obj = $this->db->fetch_object($resql)) {
2529 $this->nb[
"holidays"] = $obj->nb;
2531 $this->db->free($resql);
2535 $this->error = $this->db->error();
2550 global
$conf, $langs;
2558 $sql =
"SELECT h.rowid, h.date_debut";
2559 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2560 $sql .=
" WHERE h.statut = 2";
2561 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2562 if (!$user->hasRight(
'holiday',
'read_all')) {
2563 $userchildids = $user->getAllChildIds(1);
2564 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2565 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2568 $resql = $this->db->query($sql);
2570 $langs->load(
"members");
2573 $response->warning_delay =
$conf->holiday->approve->warning_delay / 60 / 60 / 24;
2574 $response->label = $langs->trans(
"HolidaysToApprove");
2575 $response->labelShort = $langs->trans(
"ToApprove");
2576 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2579 while ($obj = $this->db->fetch_object($resql)) {
2580 $response->nbtodo++;
2582 if ($this->db->jdate($obj->date_debut) < ($now -
$conf->holiday->approve->warning_delay)) {
2583 $response->nbtodolate++;
2590 $this->error = $this->db->error();
2605 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2607 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2608 $return .=
'<div class="info-box info-box-sm">';
2609 $return .=
'<span class="info-box-icon bg-infobox-action">';
2611 $return .=
'</span>';
2612 $return .=
'<div class="info-box-content">';
2613 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().
'</span>';
2614 if ($selected >= 0) {
2615 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2617 if (property_exists($this,
'fk_type')) {
2620 $return .=
'<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata[
'labeltype']).
'">'.
dol_escape_htmltag($arraydata[
'labeltype']).
'</div>';
2622 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2623 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_debut,
'day').
'</span>';
2624 $return .=
' <span class="opacitymedium small">'.$langs->trans(
"To").
'</span> ';
2625 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_fin,
'day').
'</span>';
2626 if (!empty($arraydata[
'nbopenedday'])) {
2627 $return .=
' ('.$arraydata[
'nbopenedday'].
')';
2630 if (method_exists($this,
'getLibStatut')) {
2631 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2633 $return .=
'</div>';
2634 $return .=
'</div>';
2635 $return .=
'</div>';
2651 global
$conf, $langs, $user;
2653 $outputlangs = $langs;
2658 $arrayfields = array(
2659 'user' =>
'Employee',
2661 'date_start' =>
'DateDebCP',
2662 'date_end' =>
'DateFinCP',
2663 'used_days' =>
'NbUseDaysCPShort',
2666 if (!empty($newlang)) {
2668 $outputlangs->setDefaultLang($newlang);
2670 $outputlangs->loadLangs(array(
'main',
'holiday',
'hrm'));
2673 $this->errors[] =
'Bad value for parameter mailto. Must be a valid email address.';
2677 $typeleaves = $this->
getTypes(1, -1);
2678 $arraytypeleaves = array();
2679 foreach ($typeleaves as $val) {
2680 $labeltoshow = ($outputlangs->trans($val[
'code']) != $val[
'code'] ? $outputlangs->trans($val[
'code']) : $val[
'label']);
2681 $arraytypeleaves[$val[
'rowid']] = $labeltoshow;
2683 $listhalfday = array(
'morning' => $outputlangs->trans(
"Morning"),
"afternoon" => $outputlangs->trans(
"Afternoon"));
2687 $year_month = sprintf(
"%04d", $prev_month[
"year"]).
'-'.sprintf(
"%02d", $prev_month[
"month"]);
2688 $arrayleaves = array();
2690 $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";
2691 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday cp";
2692 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user u ON cp.fk_user = u.rowid";
2693 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
") AND cp.rowid > 0";
2694 $sql .=
" AND cp.statut = ".Holiday::STATUS_APPROVED;
2696 $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).
"')";
2698 $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).
"') ";
2700 $sql .= $this->db->order(
"cp.fk_user, cp.date_debut",
"ASC");
2701 $resql = $this->db->query($sql);
2702 if (empty($resql)) {
2703 $this->errors[] = $this->db->lasterror();
2706 $num = $this->db->num_rows($resql);
2708 $tmpuser =
new User($this->db);
2709 while ($obj = $this->db->fetch_object($resql)) {
2710 $tmpuser->fetch($obj->fk_user);
2712 $date_start = $this->db->jdate($obj->date_debut,
true);
2713 $date_end = $this->db->jdate($obj->date_fin,
true);
2718 $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ?
'afternoon' :
'morning';
2719 $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ?
'morning' :
'afternoon';
2721 $halfdayinmonth = $obj->halfday;
2722 $starthalfdayinmonth = $starthalfday;
2723 $endhalfdayinmonth = $endhalfday;
2728 $date_start_inmonth = $this->db->jdate($obj->date_debut,
true);
2729 $date_end_inmonth = $this->db->jdate($obj->date_fin,
true);
2730 if ($tmpstart[
'year'] < $prev_month[
"year"] || $tmpstart[
'mon'] < $prev_month[
"month"]) {
2731 $date_start_inmonth =
dol_get_first_day($prev_month[
"year"], $prev_month[
"month"],
true);
2732 $starthalfdayinmonth =
'morning';
2733 if ($halfdayinmonth == 2) {
2734 $halfdayinmonth = 1;
2736 if ($halfdayinmonth == -1) {
2737 $halfdayinmonth = 0;
2740 if ($tmpend[
'year'] > $prev_month[
"year"] || $tmpend[
'mon'] > $prev_month[
"month"]) {
2741 $date_end_inmonth =
dol_get_last_day($prev_month[
"year"], $prev_month[
"month"],
true) - ((24 * 3600) - 1);
2742 $endhalfdayinmonth =
'afternoon';
2743 if ($halfdayinmonth == 2) {
2744 $halfdayinmonth = -1;
2746 if ($halfdayinmonth == 1) {
2747 $halfdayinmonth = 0;
2750 $arrayleaves[] = array(
2751 "user" => $tmpuser->getNomUrl(0,
'nolink', 0, 0, 24, 1),
2752 "type" => $arraytypeleaves[$obj->fk_type],
2753 "date_start" =>
dol_print_date($date_start_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$starthalfdayinmonth]).
')</span>',
2754 "date_end" =>
dol_print_date($date_end_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$endhalfdayinmonth]).
')</span>',
2755 "used_days" =>
num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth, $tmpuser->country_id, $obj->fk_user)
2760 $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;">';
2761 $outputarrayleaves .=
'<tr>';
2762 foreach ($arrayfields as $key => $label) {
2763 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;">';
2764 $outputarrayleaves .= $outputlangs->trans($label);
2765 $outputarrayleaves .=
'</td>';
2767 $outputarrayleaves .=
'</tr>';
2769 if (!empty($arrayleaves)) {
2770 foreach ($arrayleaves as $key => $fields) {
2771 $outputarrayleaves .=
'<tr>';
2772 foreach ($fields as $field => $value) {
2773 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;" id="'.$field.
'">';
2774 $outputarrayleaves .= $value;
2775 $outputarrayleaves .=
'</td>';
2777 $outputarrayleaves .=
'</tr>';
2780 $outputarrayleaves .=
'<tr>';
2781 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;" colspan="5">';
2782 $outputarrayleaves .= $outputlangs->trans(
"None");
2783 $outputarrayleaves .=
'</td>';
2784 $outputarrayleaves .=
'</tr>';
2786 $outputarrayleaves .=
'</table>';
2788 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2789 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2791 $formmail =
new FormMail($this->db);
2793 $templateLabel =
'';
2794 if (empty($template) || $template ==
'EmailTemplateCode') {
2795 $templateLabel =
'(HolidayHrInformationsPreviousMonth)';
2797 if (is_numeric($template)) {
2798 $templateId = $template;
2800 $templateLabel = $template;
2803 $mailtemplate = $formmail->getEMailTemplate($this->db,
"holiday", $user, $outputlangs, $templateId, 1, $templateLabel);
2805 if (is_numeric($mailtemplate) || empty($mailtemplate->topic)) {
2806 $this->errors[] =
'No mail template found for code "'.$templateLabel.
'" or id "'.$templateId.
'".';
2811 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $this);
2814 $subject =
make_substitutions($mailtemplate->topic, $substitutionarray, $outputlangs);
2818 $msg = preg_replace(
'/__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__/', $outputarrayleaves, $msg);
2819 $cmail =
new CMailFile($subject, $mailto, $from, $msg, array(), array(), array(),
'',
'', 0, 1);
2820 $result = $cmail->sendfile();
2821 if (!$result || !empty($cmail->error) || !empty($cmail->errors)) {
2822 $this->errors[] = $cmail->error;
2823 if (is_array($cmail->errors) && count($cmail->errors) > 0) {
2824 $this->errors = array_merge($this->errors, $cmail->errors);
2830 if (!empty($this->errors)) {
2831 $this->output .=
"\n";
2834 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,...
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.
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.
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.
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_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...
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.
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).
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.
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)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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