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;
250 dol_print_error(
null,
"Failed to include file ".$file);
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);
460 $this->date_debut = $this->db->jdate($obj->date_debut);
461 $this->date_fin = $this->db->jdate($obj->date_fin);
462 $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
463 $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
465 $this->halfday = (int) $obj->halfday;
466 $this->
status = (int) $obj->status;
467 $this->statut = (int) $obj->status;
468 $this->fk_validator = $obj->fk_validator;
469 $this->date_valid = $this->db->jdate($obj->date_valid);
470 $this->fk_user_valid = $obj->fk_user_valid;
471 $this->user_validation_id = $obj->fk_user_valid;
472 $this->date_approval = $this->db->jdate($obj->date_approval);
473 $this->fk_user_approve = $obj->fk_user_approve;
474 $this->date_refuse = $this->db->jdate($obj->date_refuse);
475 $this->fk_user_refuse = $obj->fk_user_refuse;
476 $this->date_cancel = $this->db->jdate($obj->date_cancel);
477 $this->fk_user_cancel = $obj->fk_user_cancel;
478 $this->detail_refuse = $obj->detail_refuse;
479 $this->note_private = $obj->note_private;
480 $this->note_public = $obj->note_public;
481 $this->fk_user_create = $obj->fk_user_create;
482 $this->fk_type = $obj->fk_type;
483 $this->entity = $obj->entity;
491 $this->db->free($resql);
495 $this->error =
"Error ".$this->db->lasterror();
512 $sql .=
" cp.rowid,";
515 $sql .=
" cp.fk_user,";
516 $sql .=
" cp.fk_type,";
517 $sql .=
" cp.date_create,";
518 $sql .=
" cp.tms as date_modification,";
519 $sql .=
" cp.description,";
520 $sql .=
" cp.date_debut,";
521 $sql .=
" cp.date_fin,";
522 $sql .=
" cp.halfday,";
523 $sql .=
" cp.statut as status,";
524 $sql .=
" cp.fk_validator,";
525 $sql .=
" cp.date_valid,";
526 $sql .=
" cp.fk_user_valid,";
527 $sql .=
" cp.date_approval,";
528 $sql .=
" cp.fk_user_approve,";
529 $sql .=
" cp.date_refuse,";
530 $sql .=
" cp.fk_user_refuse,";
531 $sql .=
" cp.date_cancel,";
532 $sql .=
" cp.fk_user_cancel,";
533 $sql .=
" cp.detail_refuse,";
535 $sql .=
" uu.lastname as user_lastname,";
536 $sql .=
" uu.firstname as user_firstname,";
537 $sql .=
" uu.login as user_login,";
538 $sql .=
" uu.statut as user_status,";
539 $sql .=
" uu.photo as user_photo,";
541 $sql .=
" ua.lastname as validator_lastname,";
542 $sql .=
" ua.firstname as validator_firstname,";
543 $sql .=
" ua.login as validator_login,";
544 $sql .=
" ua.statut as validator_status,";
545 $sql .=
" ua.photo as validator_photo";
547 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
548 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
549 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
550 $sql .=
" AND cp.fk_user IN (".$this->db->sanitize($user_id).
")";
553 if (!empty($filter)) {
558 if (!empty($order)) {
562 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
563 $resql = $this->db->query($sql);
568 $tab_result = $this->holiday;
569 $num = $this->db->num_rows($resql);
578 $obj = $this->db->fetch_object($resql);
580 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
581 $tab_result[$i][
'id'] = (int) $obj->rowid;
582 $tab_result[$i][
'ref'] = (string) ($obj->ref ? $obj->ref : $obj->rowid);
584 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
585 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
586 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
587 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
588 $tab_result[$i][
'description'] = (string) $obj->description;
589 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
590 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
591 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
592 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
593 $tab_result[$i][
'halfday'] = (int) $obj->halfday;
594 $tab_result[$i][
'statut'] = (int) $obj->status;
595 $tab_result[$i][
'status'] = (int) $obj->status;
596 $tab_result[$i][
'fk_validator'] = (int) $obj->fk_validator;
597 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
598 $tab_result[$i][
'fk_user_valid'] = (int) $obj->fk_user_valid;
599 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
600 $tab_result[$i][
'fk_user_approve'] = (int) $obj->fk_user_approve;
601 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
602 $tab_result[$i][
'fk_user_refuse'] = (int) $obj->fk_user_refuse;
603 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
604 $tab_result[$i][
'fk_user_cancel'] = (int) $obj->fk_user_cancel;
605 $tab_result[$i][
'detail_refuse'] = (string) $obj->detail_refuse;
607 $tab_result[$i][
'user_firstname'] = (string) $obj->user_firstname;
608 $tab_result[$i][
'user_lastname'] = (string) $obj->user_lastname;
609 $tab_result[$i][
'user_login'] = (string) $obj->user_login;
610 $tab_result[$i][
'user_statut'] = (int) $obj->user_status;
611 $tab_result[$i][
'user_status'] = (int) $obj->user_status;
612 $tab_result[$i][
'user_photo'] = (string) $obj->user_photo;
614 $tab_result[$i][
'validator_firstname'] = (string) $obj->validator_firstname;
615 $tab_result[$i][
'validator_lastname'] = (string) $obj->validator_lastname;
616 $tab_result[$i][
'validator_login'] = (string) $obj->validator_login;
617 $tab_result[$i][
'validator_statut'] = (int) $obj->validator_status;
618 $tab_result[$i][
'validator_status'] = (int) $obj->validator_status;
619 $tab_result[$i][
'validator_photo'] = (string) $obj->validator_photo;
625 $this->holiday = $tab_result;
629 $this->error =
"Error ".$this->db->lasterror();
644 $sql .=
" cp.rowid,";
646 $sql .=
" cp.fk_user,";
647 $sql .=
" cp.fk_type,";
648 $sql .=
" cp.date_create,";
649 $sql .=
" cp.tms as date_modification,";
650 $sql .=
" cp.description,";
651 $sql .=
" cp.date_debut,";
652 $sql .=
" cp.date_fin,";
653 $sql .=
" cp.halfday,";
654 $sql .=
" cp.statut as status,";
655 $sql .=
" cp.fk_validator,";
656 $sql .=
" cp.date_valid,";
657 $sql .=
" cp.fk_user_valid,";
658 $sql .=
" cp.date_approval,";
659 $sql .=
" cp.fk_user_approve,";
660 $sql .=
" cp.date_refuse,";
661 $sql .=
" cp.fk_user_refuse,";
662 $sql .=
" cp.date_cancel,";
663 $sql .=
" cp.fk_user_cancel,";
664 $sql .=
" cp.detail_refuse,";
666 $sql .=
" uu.lastname as user_lastname,";
667 $sql .=
" uu.firstname as user_firstname,";
668 $sql .=
" uu.login as user_login,";
669 $sql .=
" uu.statut as user_status,";
670 $sql .=
" uu.photo as user_photo,";
672 $sql .=
" ua.lastname as validator_lastname,";
673 $sql .=
" ua.firstname as validator_firstname,";
674 $sql .=
" ua.login as validator_login,";
675 $sql .=
" ua.statut as validator_status,";
676 $sql .=
" ua.photo as validator_photo";
678 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
679 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
680 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
683 if (!empty($sqlFilter)) {
688 if (!empty($sqlOrder)) {
692 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
693 $resql = $this->db->query($sql);
698 $tab_result = $this->holiday;
699 $num = $this->db->num_rows($resql);
708 $obj = $this->db->fetch_object($resql);
710 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
711 $tab_result[$i][
'id'] = (int) $obj->rowid;
712 $tab_result[$i][
'ref'] = (string) ($obj->ref ? $obj->ref : $obj->rowid);
714 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
715 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
716 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
717 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
718 $tab_result[$i][
'description'] = (string) $obj->description;
719 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
720 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
721 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
722 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
723 $tab_result[$i][
'halfday'] = (int) $obj->halfday;
724 $tab_result[$i][
'statut'] = (int) $obj->status;
725 $tab_result[$i][
'status'] = (int) $obj->status;
726 $tab_result[$i][
'fk_validator'] = (int) $obj->fk_validator;
727 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
728 $tab_result[$i][
'fk_user_valid'] = (int) $obj->fk_user_valid;
729 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
730 $tab_result[$i][
'fk_user_approve'] = (int) $obj->fk_user_approve;
731 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
732 $tab_result[$i][
'fk_user_refuse'] = (int) $obj->fk_user_refuse;
733 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
734 $tab_result[$i][
'fk_user_cancel'] = (int) $obj->fk_user_cancel;
735 $tab_result[$i][
'detail_refuse'] = (string) $obj->detail_refuse;
737 $tab_result[$i][
'user_firstname'] = (string) $obj->user_firstname;
738 $tab_result[$i][
'user_lastname'] = (string) $obj->user_lastname;
739 $tab_result[$i][
'user_login'] = (string) $obj->user_login;
740 $tab_result[$i][
'user_statut'] = (int) $obj->user_status;
741 $tab_result[$i][
'user_status'] = (int) $obj->user_status;
742 $tab_result[$i][
'user_photo'] = (string) $obj->user_photo;
744 $tab_result[$i][
'validator_firstname'] = (string) $obj->validator_firstname;
745 $tab_result[$i][
'validator_lastname'] = (string) $obj->validator_lastname;
746 $tab_result[$i][
'validator_login'] = (string) $obj->validator_login;
747 $tab_result[$i][
'validator_statut'] = (int) $obj->validator_status;
748 $tab_result[$i][
'validator_status'] = (int) $obj->validator_status;
749 $tab_result[$i][
'validator_photo'] = (string) $obj->validator_photo;
754 $this->holiday = $tab_result;
758 $this->error =
"Error ".$this->db->lasterror();
771 public function validate($user =
null, $notrigger = 0)
773 global
$conf, $langs;
774 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
778 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
780 if ($checkBalance > 0) {
781 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
786 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
787 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
788 $daysAsked =
num_open_day($datedebutforcount, $datefinforcount, 0, 1, 0,
'', $this->fk_user);
790 if (($balance - $daysAsked) < 0) {
791 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
797 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref) || $this->
ref == $this->
id) {
798 $num = $this->getNextNumRef(
null);
800 $num = (string) $this->
ref;
805 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
806 $sql .=
" fk_user_valid = ".((int) $user->id).
",";
807 $sql .=
" date_valid = '".$this->db->idate(
dol_now()).
"',";
808 if (!empty($this->
status) && is_numeric($this->
status)) {
809 $sql .=
" statut = ".((int) $this->
status).
",";
811 $this->error =
'Property status must be a numeric value';
814 $sql .=
" ref = '".$this->db->escape($num).
"'";
815 $sql .=
" WHERE rowid = ".((int) $this->
id);
819 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
820 $resql = $this->db->query($sql);
823 $this->errors[] =
"Error ".$this->db->lasterror();
829 $result = $this->call_trigger(
'HOLIDAY_VALIDATE', $user);
838 $this->oldref = $this->ref;
841 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
843 $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) .
"'";
844 $sql .=
" WHERE filename LIKE '" . $this->db->escape($this->
ref) .
"%' AND filepath = 'holiday/" . $this->db->escape($this->
ref) .
"' and entity = " . ((int)
$conf->entity);
845 $resql = $this->db->query($sql);
848 $this->error = $this->db->lasterror();
850 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'holiday/".$this->db->escape($this->newref).
"'";
851 $sql .=
" WHERE filepath = 'holiday/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
852 $resql = $this->db->query($sql);
855 $this->error = $this->db->lasterror();
861 $dirsource =
$conf->holiday->multidir_output[$this->entity] .
'/' . $oldref;
862 $dirdest =
$conf->holiday->multidir_output[$this->entity] .
'/' . $newref;
863 if (!$error && file_exists($dirsource)) {
864 dol_syslog(get_class($this) .
"::validate rename dir " . $dirsource .
" into " . $dirdest);
865 if (@rename($dirsource, $dirdest)) {
868 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^' . preg_quote($oldref,
'/'));
869 foreach ($listoffiles as $fileentry) {
870 $dirsource = $fileentry[
'name'];
871 $dirdest = preg_replace(
'/^' . preg_quote($oldref,
'/') .
'/', $newref, $dirsource);
872 $dirsource = $fileentry[
'path'] .
'/' . $dirsource;
873 $dirdest = $fileentry[
'path'] .
'/' . $dirdest;
874 @rename($dirsource, $dirdest);
884 foreach ($this->errors as $errmsg) {
885 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
886 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
888 $this->db->rollback();
904 public function approve($user =
null, $notrigger = 0)
908 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
910 if ($checkBalance > 0) {
911 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
916 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
917 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
918 $daysAsked =
num_open_day($datedebutforcount, $datefinforcount, 0, 1, 0,
'', $this->fk_user);
920 if (($balance - $daysAsked) < 0) {
921 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
927 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
928 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
929 if (!empty($this->date_debut)) {
930 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
934 if (!empty($this->date_fin)) {
935 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
939 $sql .=
" halfday = ".((int) $this->halfday).
",";
940 if (!empty($this->
status) && is_numeric($this->
status)) {
941 $sql .=
" statut = ".((int) $this->
status).
",";
945 if (!empty($this->fk_validator)) {
946 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
950 if (!empty($this->date_valid)) {
951 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
953 $sql .=
" date_valid = NULL,";
955 if (!empty($this->fk_user_valid)) {
956 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
958 $sql .=
" fk_user_valid = NULL,";
960 if (!empty($this->date_approval)) {
961 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
963 $sql .=
" date_approval = NULL,";
965 if (!empty($this->fk_user_approve)) {
966 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
968 $sql .=
" fk_user_approve = NULL,";
970 if (!empty($this->date_refuse)) {
971 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
973 $sql .=
" date_refuse = NULL,";
975 if (!empty($this->fk_user_refuse)) {
976 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
978 $sql .=
" fk_user_refuse = NULL,";
980 if (!empty($this->date_cancel)) {
981 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
983 $sql .=
" date_cancel = NULL,";
985 if (!empty($this->fk_user_cancel)) {
986 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
988 $sql .=
" fk_user_cancel = NULL,";
990 if (!empty($this->detail_refuse)) {
991 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
993 $sql .=
" detail_refuse = NULL";
995 $sql .=
" WHERE rowid = ".((int) $this->
id);
999 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
1000 $resql = $this->db->query($sql);
1003 $this->errors[] =
"Error ".$this->db->lasterror();
1009 $result = $this->call_trigger(
'HOLIDAY_APPROVE', $user);
1019 foreach ($this->errors as $errmsg) {
1020 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
1021 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1023 $this->db->rollback();
1026 $this->db->commit();
1038 public function update($user =
null, $notrigger = 0)
1042 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
1044 if ($checkBalance > 0 && $this->
status != self::STATUS_DRAFT && $this->
status != self::STATUS_CANCELED) {
1045 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
1050 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
1051 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
1052 $daysAsked =
num_open_day($datedebutforcount, $datefinforcount, 0, 1, 0,
'', $this->fk_user);
1054 if (($balance - $daysAsked) < 0) {
1055 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1061 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
1063 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
1065 if (!empty($this->date_create)) {
1066 $sql .=
" date_create = '".$this->db->idate($this->date_create).
"',";
1070 if (!empty($this->date_debut)) {
1071 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
1075 if (!empty($this->date_fin)) {
1076 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
1080 $sql .=
" halfday = ".((int) $this->halfday).
",";
1081 if (!empty($this->
status) && is_numeric($this->
status)) {
1082 $sql .=
" statut = ".((int) $this->
status).
",";
1086 if (!empty($this->fk_validator)) {
1087 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
1091 if (!empty($this->date_valid)) {
1092 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1094 $sql .=
" date_valid = NULL,";
1096 if (!empty($this->fk_user_valid)) {
1097 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
1099 $sql .=
" fk_user_valid = NULL,";
1101 if (!empty($this->date_approval)) {
1102 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
1104 $sql .=
" date_approval = NULL,";
1106 if (!empty($this->fk_user_approve)) {
1107 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
1109 $sql .=
" fk_user_approve = NULL,";
1111 if (!empty($this->date_refuse)) {
1112 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
1114 $sql .=
" date_refuse = NULL,";
1116 if (!empty($this->fk_user_refuse)) {
1117 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
1119 $sql .=
" fk_user_refuse = NULL,";
1121 if (!empty($this->date_cancel)) {
1122 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
1124 $sql .=
" date_cancel = NULL,";
1126 if (!empty($this->fk_user_cancel)) {
1127 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
1129 $sql .=
" fk_user_cancel = NULL,";
1131 if (!empty($this->detail_refuse)) {
1132 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1134 $sql .=
" detail_refuse = NULL";
1137 $sql .=
" WHERE rowid = ".((int) $this->
id);
1141 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1142 $resql = $this->db->query($sql);
1145 $this->errors[] =
"Error ".$this->db->lasterror();
1156 if (!$notrigger && $user !==
null) {
1158 $result = $this->call_trigger(
'HOLIDAY_MODIFY', $user);
1168 foreach ($this->errors as $errmsg) {
1169 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1170 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1172 $this->db->rollback();
1175 $this->db->commit();
1188 public function delete($user, $notrigger = 0)
1190 global
$conf, $langs;
1193 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1194 $sql .=
" WHERE rowid=".((int) $this->
id);
1198 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1199 $resql = $this->db->query($sql);
1202 $this->errors[] =
"Error ".$this->db->lasterror();
1208 $result = $this->call_trigger(
'HOLIDAY_DELETE', $user);
1218 foreach ($this->errors as $errmsg) {
1219 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1220 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1222 $this->db->rollback();
1225 $this->db->commit();
1247 foreach ($this->holiday as $infos_CP) {
1259 if ($dateStart < $infos_CP[
'date_debut'] && $dateEnd > $infos_CP[
'date_fin']) {
1263 if ($halfday == 0) {
1264 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1267 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1270 } elseif ($halfday == -1) {
1272 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1273 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1277 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1278 if ($dateStart < $dateEnd) {
1281 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1285 } elseif ($halfday == 1) {
1287 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1288 if ($dateStart < $dateEnd) {
1291 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1295 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1296 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1300 } elseif ($halfday == 2) {
1302 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1303 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1307 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1308 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1313 dol_print_error(
null,
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1332 $isavailablemorning =
true;
1333 $isavailableafternoon =
true;
1336 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1337 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1338 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1339 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1340 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->db->idate($timestamp).
"'";
1341 if ($status !=
'-1') {
1342 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1345 $resql = $this->db->query($sql);
1347 $num_rows = $this->db->num_rows($resql);
1348 if ($num_rows > 0) {
1349 $arrayofrecord = array();
1351 while ($i < $num_rows) {
1352 $obj = $this->db->fetch_object($resql);
1355 $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);
1360 $isavailablemorning =
true;
1361 foreach ($arrayofrecord as $record) {
1362 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1365 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1368 $isavailablemorning =
false;
1371 $isavailableafternoon =
true;
1372 foreach ($arrayofrecord as $record) {
1373 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1376 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1379 $isavailableafternoon =
false;
1384 dol_print_error($this->db);
1387 $result = array(
'morning' => (
int) $isavailablemorning,
'afternoon' => (
int) $isavailableafternoon);
1388 if (!$isavailablemorning) {
1389 $result[
'morning_reason'] =
'leave_request';
1391 if (!$isavailableafternoon) {
1392 $result[
'afternoon_reason'] =
'leave_request';
1407 $langs->load(
'holiday');
1408 $nofetch = !empty($params[
'nofetch']);
1411 $datas[
'picto'] = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1412 if (isset($this->
status)) {
1413 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1415 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1417 if (!$nofetch && !empty($this->fk_type)) {
1418 $typeleaves = $this->
getTypes(1, -1);
1419 if (empty($typeleaves[$this->fk_type])) {
1420 $labeltoshow = $langs->trans(
"TypeWasDisabledOrRemoved", $this->fk_type);
1422 $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']);
1424 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type") .
':</b> ' . $labeltoshow;
1426 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1427 $listhalfday = array(
1428 'morning' => $langs->trans(
"Morning"),
1429 "afternoon" => $langs->trans(
"Afternoon")
1431 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ?
'afternoon' :
'morning';
1432 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ?
'morning' :
'afternoon';
1433 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateDebCP') .
'</b>: '.
dol_print_date($this->date_debut,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1434 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateFinCP') .
'</b>: '.
dol_print_date($this->date_fin,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1450 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1452 global
$conf, $langs, $hookmanager;
1454 if (!empty(
$conf->dol_no_mouse_hover)) {
1461 'objecttype' => $this->element,
1464 $classfortooltip =
'classfortooltip';
1467 $classfortooltip =
'classforajaxtooltip';
1468 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1474 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1479 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1480 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1481 $add_save_lastsearch_values = 1;
1483 if ($add_save_lastsearch_values) {
1484 $url .=
'&save_lastsearch_values=1';
1489 if (empty($notooltip)) {
1491 $label = $langs->trans(
"ShowMyObject");
1492 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1494 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1495 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1497 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1500 $linkstart =
'<a href="'.$url.
'"';
1501 $linkstart .= $linkclose.
'>';
1504 $result .= $linkstart;
1507 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1509 if ($withpicto != 2) {
1510 $result .= $this->ref;
1512 $result .= $linkend;
1515 $hookmanager->initHooks(array($this->element .
'dao'));
1516 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1517 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1519 $result = $hookmanager->resPrint;
1521 $result .= $hookmanager->resPrint;
1547 public function LibStatut($status, $mode = 0, $startdate =
'')
1552 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1560 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1568 $statusType =
'status6';
1569 if (!empty($startdate) && $startdate >=
dol_now()) {
1570 $statusType =
'status4';
1571 $params = array(
'tooltip' => $this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1573 if ($status == self::STATUS_DRAFT) {
1574 $statusType =
'status0';
1576 if ($status == self::STATUS_VALIDATED) {
1577 $statusType =
'status1';
1579 if ($status == self::STATUS_CANCELED) {
1580 $statusType =
'status9';
1582 if ($status == self::STATUS_REFUSED) {
1583 $statusType =
'status9';
1586 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1598 public function selectStatutCP($selected = 0, $htmlname =
'select_statut', $morecss =
'minwidth125')
1603 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1604 $nb = count($name) + 1;
1607 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1608 $out .=
'<option value="-1"> </option>'.
"\n";
1611 for ($i = 1; $i < $nb; $i++) {
1612 if ($i == $selected) {
1613 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1615 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1619 $out .=
"</select>\n";
1622 $out .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($showempty < 0 ? (
string) $showempty :
'-1'), $morecss);
1636 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1637 $sql .=
" value = '".$this->db->escape($value).
"'";
1638 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1640 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1641 $result = $this->db->query($sql);
1659 $sql =
"SELECT value";
1660 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1661 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1663 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1664 $result = $this->db->query($sql);
1667 $obj = $this->db->fetch_object($result);
1670 if ($createifnotfound) {
1671 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1672 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->db->escape($createifnotfound).
"')";
1673 $result = $this->db->query($sql);
1675 return $createifnotfound;
1677 $this->error = $this->db->lasterror();
1688 $this->error = $this->db->lasterror();
1703 global $user, $langs;
1707 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1708 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1709 $langs->load(
"holiday");
1721 if (empty($stringInDBForLastUpdate)) {
1725 if ($stringInDBForLastUpdate <
'20000101000000') {
1726 $stringInDBForLastUpdate =
'20000101000000';
1737 while ($yearMonthLastUpdate < $yearMonthNow) {
1743 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1744 $nbUser = count($users);
1746 $typeleaves = $this->
getTypes(1, 1);
1749 foreach ($users as $userCounter) {
1750 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1751 if (empty($nbDaysToAdd)) {
1755 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1757 $nowHoliday = (float) $userCounter[
'nb_holiday'];
1758 $newSolde = $nowHoliday + $nbDaysToAdd;
1761 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidayMonthlyCredit'), $newSolde, $userCounter[
'type']);
1763 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1766 $this->db->rollback();
1770 if (empty($decrease)) {
1775 $filter =
" AND cp.statut = ".((int) self::STATUS_APPROVED);
1778 $filter .=
" AND cp.fk_type = ".((int) $userCounter[
'type']);
1779 $this->
fetchByUser($userCounter[
'id'],
'', $filter);
1781 if (empty($this->holiday)) {
1785 $startOfMonth =
dol_mktime(0, 0, 0, (
int) $month, 1, (
int) $year, 1);
1788 foreach ($this->holiday as $obj) {
1789 $startDate = $obj[
'date_debut_gmt'];
1790 $endDate = $obj[
'date_fin_gmt'];
1792 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1793 $startDate = $startOfMonth;
1796 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1797 $endDate = $endOfMonth;
1800 $nbDaysToDeduct = (int)
num_open_day($startDate, $endDate, 0, 1, $obj[
'halfday'], $obj[
'country_id'], $obj[
'fk_user']);
1802 if ($nbDaysToDeduct <= 0) {
1806 $newSolde -= $nbDaysToDeduct;
1809 $this->
addLogCP($user->id, $userCounter[
'rowid'], $obj[
'ref'].
' - '.$langs->trans(
'HolidayConsumption'), $newSolde, $userCounter[
'type']);
1811 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1814 $this->db->rollback();
1822 $lastUpdate =
dol_mktime(0, 0, 0, (
int) $newMonth[
'month'], 1, (
int) $newMonth[
'year']);
1824 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1825 $sql .=
" value = '".$this->db->escape(
dol_print_date($lastUpdate,
'%Y%m%d%H%M%S')).
"'";
1826 $sql .=
" WHERE name = 'lastUpdate'";
1827 $result = $this->db->query($sql);
1830 $this->db->rollback();
1834 $this->db->commit();
1844 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1845 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1846 $resql = $this->db->query($sql);
1848 $num = $this->db->num_rows($resql);
1852 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1853 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1854 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1855 $result = $this->db->query($sql);
1858 $this->errors[] = $this->db->lasterror();
1862 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1863 $sql .= ((float) $nbHoliday);
1864 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1865 $result = $this->db->query($sql);
1868 $this->errors[] = $this->db->lasterror();
1872 $this->errors[] = $this->db->lasterror();
1893 $sql =
"SELECT nb_holiday";
1894 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1895 $sql .=
" WHERE fk_user = ".(int) $user_id;
1897 $sql .=
" AND fk_type = ".(int) $fk_type;
1900 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1901 $result = $this->db->query($sql);
1903 $obj = $this->db->fetch_object($result);
1906 return $obj->nb_holiday;
1923 public function fetchUsers($stringlist =
true, $type =
true, $sqlFilters =
'')
1925 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1932 $sql .=
" DISTINCT";
1935 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1938 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1939 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1940 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1941 $sql .=
" OR u.entity = 0)";
1943 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1945 $sql .=
" AND u.statut > 0";
1946 $sql .=
" AND u.employee = 1";
1948 $sql .= $sqlFilters;
1951 $resql = $this->db->query($sql);
1956 $num = $this->db->num_rows($resql);
1961 $obj = $this->db->fetch_object($resql);
1964 $stringlist .= $obj->rowid;
1966 $stringlist .=
', '.$obj->rowid;
1975 $this->error =
"Error ".$this->db->lasterror();
1980 $sql =
"SELECT DISTINCT cpu.fk_user";
1981 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1982 $sql .=
" WHERE cpu.fk_user = u.rowid";
1984 $sql .= $sqlFilters;
1987 $resql = $this->db->query($sql);
1992 $num = $this->db->num_rows($resql);
1997 $obj = $this->db->fetch_object($resql);
2000 $stringlist .= $obj->fk_user;
2002 $stringlist .=
', '.$obj->fk_user;
2011 $this->error =
"Error ".$this->db->lasterror();
2022 $sql .=
" DISTINCT";
2024 $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";
2025 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2028 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2029 $sql .=
" WHERE ((ug.fk_user = u.rowid";
2030 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
2031 $sql .=
" OR u.entity = 0)";
2033 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
2036 $sql .=
" AND u.statut > 0";
2037 $sql .=
" AND u.employee = 1";
2039 $sql .= $sqlFilters;
2042 $resql = $this->db->query($sql);
2047 $tab_result = $this->holiday;
2048 $num = $this->db->num_rows($resql);
2052 $obj = $this->db->fetch_object($resql);
2054 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2055 $tab_result[$i][
'id'] = (int) $obj->rowid;
2056 $tab_result[$i][
'name'] = $obj->lastname;
2057 $tab_result[$i][
'lastname'] = $obj->lastname;
2058 $tab_result[$i][
'firstname'] = $obj->firstname;
2059 $tab_result[$i][
'gender'] = $obj->gender;
2060 $tab_result[$i][
'status'] = (int) $obj->status;
2061 $tab_result[$i][
'employee'] = (int) $obj->employee;
2062 $tab_result[$i][
'photo'] = $obj->photo;
2063 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
2064 $tab_result[$i][
'country_id'] = (int) $obj->country_id;
2074 $this->errors[] =
"Error ".$this->db->lasterror();
2079 $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";
2080 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
2081 $sql .=
" WHERE cpu.fk_user = u.rowid";
2083 $sql .= $sqlFilters;
2086 $resql = $this->db->query($sql);
2091 $tab_result = $this->holiday;
2092 $num = $this->db->num_rows($resql);
2096 $obj = $this->db->fetch_object($resql);
2098 $tab_result[$i][
'rowid'] = $obj->rowid;
2099 $tab_result[$i][
'id'] = $obj->rowid;
2100 $tab_result[$i][
'name'] = $obj->lastname;
2101 $tab_result[$i][
'lastname'] = $obj->lastname;
2102 $tab_result[$i][
'firstname'] = $obj->firstname;
2103 $tab_result[$i][
'gender'] = $obj->gender;
2104 $tab_result[$i][
'status'] = $obj->status;
2105 $tab_result[$i][
'employee'] = $obj->employee;
2106 $tab_result[$i][
'photo'] = $obj->photo;
2107 $tab_result[$i][
'fk_user'] = $obj->fk_user;
2109 $tab_result[$i][
'type'] = $obj->fk_type;
2110 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
2118 $this->error =
"Error ".$this->db->lasterror();
2136 $users_validator = array();
2138 $sql =
"SELECT DISTINCT ur.fk_user";
2139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2140 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2142 $sql .=
" SELECT DISTINCT ugu.fk_user";
2143 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2144 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2147 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
2148 $result = $this->db->query($sql);
2150 $num_rows = $this->db->num_rows($result);
2152 while ($i < $num_rows) {
2153 $objp = $this->db->fetch_object($result);
2154 array_push($users_validator, $objp->fk_user);
2157 return $users_validator;
2159 $this->error = $this->db->lasterror();
2160 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2173 $sql =
"SELECT count(u.rowid) as compteur";
2174 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2175 $sql .=
" WHERE u.statut > 0";
2177 $result = $this->db->query($sql);
2178 $object = $this->db->fetch_object($result);
2189 $sql =
"SELECT count(u.rowid) as compteur";
2190 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2191 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2193 $result = $this->db->query($sql);
2194 $object = $this->db->fetch_object($result);
2208 if (empty($userCP)) {
2211 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2226 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2234 if ($prev_solde == $new_solde) {
2241 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2242 $sql .=
"date_action,";
2243 $sql .=
"fk_user_action,";
2244 $sql .=
"fk_user_update,";
2245 $sql .=
"type_action,";
2246 $sql .=
"prev_solde,";
2247 $sql .=
"new_solde,";
2249 $sql .=
") VALUES (";
2250 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2251 $sql .=
" ".((int) $fk_user_action).
",";
2252 $sql .=
" ".((int) $fk_user_update).
",";
2253 $sql .=
" '".$this->db->escape($label).
"',";
2254 $sql .=
" ".((float) $prev_solde).
",";
2255 $sql .=
" ".((float) $new_solde).
",";
2256 $sql .=
" ".((int) $fk_type);
2259 $resql = $this->db->query($sql);
2262 $this->errors[] =
"Error ".$this->db->lasterror();
2267 $optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2272 foreach ($this->errors as $errmsg) {
2273 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2274 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2276 $this->db->rollback();
2279 $this->db->commit();
2294 $sql .=
" cpl.rowid,";
2295 $sql .=
" cpl.date_action,";
2296 $sql .=
" cpl.fk_user_action,";
2297 $sql .=
" cpl.fk_user_update,";
2298 $sql .=
" cpl.type_action,";
2299 $sql .=
" cpl.prev_solde,";
2300 $sql .=
" cpl.new_solde,";
2301 $sql .=
" cpl.fk_type";
2302 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2303 $sql .=
" WHERE cpl.rowid > 0";
2306 if (!empty($sqlwhere)) {
2307 $sql .=
" ".$sqlwhere;
2311 if (!empty($sqlorder)) {
2312 $sql .=
" ".$sqlorder;
2315 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2316 $resql = $this->db->query($sql);
2321 $tab_result = $this->logs;
2322 $num = $this->db->num_rows($resql);
2331 $obj = $this->db->fetch_object($resql);
2333 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2334 $tab_result[$i][
'id'] = (int) $obj->rowid;
2335 $tab_result[$i][
'date_action'] = (string) $obj->date_action;
2336 $tab_result[$i][
'fk_user_action'] = (int) $obj->fk_user_action;
2337 $tab_result[$i][
'fk_user_update'] = (int) $obj->fk_user_update;
2338 $tab_result[$i][
'type_action'] = (string) $obj->type_action;
2339 $tab_result[$i][
'prev_solde'] = (float) $obj->prev_solde;
2340 $tab_result[$i][
'new_solde'] = (float) $obj->new_solde;
2341 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
2346 $this->logs = $tab_result;
2350 $this->error =
"Error ".$this->db->lasterror();
2367 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2368 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2369 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int)
$mysoc->country_id).
')';
2370 $sql .=
" AND entity IN (0, ".getEntity(
'c_holiday_types').
")";
2372 $sql .=
" AND active = ".((int) $active);
2375 $sql .=
" AND affect = ".((int) $affect);
2377 $sql .=
" ORDER BY sortorder";
2379 $result = $this->db->query($sql);
2381 $num = $this->db->num_rows($result);
2384 while ($obj = $this->db->fetch_object($result)) {
2385 $types[$obj->rowid] = array(
2386 'id' => $obj->rowid,
2387 'rowid' => $obj->rowid,
2388 'code' => $obj->code,
2389 'label' => $obj->label,
2390 'affect' => $obj->affect,
2391 'delay' => $obj->delay,
2392 'newbymonth' => $obj->newbymonth
2399 dol_print_error($this->db);
2416 $sql =
"SELECT f.rowid, f.statut as status,";
2417 $sql .=
" f.date_create as datec,";
2418 $sql .=
" f.tms as date_modification,";
2419 $sql .=
" f.date_valid as datev,";
2420 $sql .=
" f.date_approval as datea,";
2421 $sql .=
" f.date_refuse as dater,";
2422 $sql .=
" f.fk_user_create as fk_user_creation,";
2423 $sql .=
" f.fk_user_modif as fk_user_modification,";
2424 $sql .=
" f.fk_user_valid as fk_user_validation,";
2425 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2426 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2427 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2428 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2429 $sql .=
" WHERE f.rowid = ".((int) $id);
2430 $sql .=
" AND f.entity = ".((int)
$conf->entity);
2432 $resql = $this->db->query($sql);
2434 if ($this->db->num_rows($resql)) {
2435 $obj = $this->db->fetch_object($resql);
2437 $this->
id = $obj->rowid;
2439 $this->date_creation = $this->db->jdate($obj->datec);
2440 $this->date_modification = $this->db->jdate($obj->date_modification);
2441 $this->date_validation = $this->db->jdate($obj->datev);
2442 $this->date_approval = $this->db->jdate($obj->datea);
2444 $this->user_creation_id = $obj->fk_user_creation;
2445 $this->user_validation_id = $obj->fk_user_validation;
2446 $this->user_modification_id = $obj->fk_user_modification;
2449 if ($obj->fk_user_approval_done) {
2450 $this->fk_user_approve = $obj->fk_user_approval_done;
2454 $this->db->free($resql);
2456 dol_print_error($this->db);
2470 global $user, $langs;
2474 $this->specimen = 1;
2476 $this->fk_user = $user->id;
2478 $this->date_debut =
dol_now();
2479 $this->date_fin =
dol_now() + (24 * 3600);
2480 $this->date_valid =
dol_now();
2481 $this->fk_validator = $user->id;
2498 $this->nb = array();
2500 $sql =
"SELECT count(h.rowid) as nb";
2501 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2502 $sql .=
" WHERE h.statut > 1";
2503 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2504 if (!$user->hasRight(
'holiday',
'readall')) {
2505 $userchildids = $user->getAllChildIds(1);
2506 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2507 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2510 $resql = $this->db->query($sql);
2512 while ($obj = $this->db->fetch_object($resql)) {
2513 $this->nb[
"holidays"] = $obj->nb;
2515 $this->db->free($resql);
2518 dol_print_error($this->db);
2519 $this->error = $this->db->error();
2534 global
$conf, $langs;
2545 $sql =
"SELECT COUNT(h.rowid) as nb,";
2546 $sql .=
" SUM(CASE WHEN h.date_debut IS NULL OR h.date_debut < '".$this->db->idate($now -
$conf->holiday->approve->warning_delay).
"' THEN 1 ELSE 0 END) as nblate";
2547 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2548 $sql .=
" WHERE h.statut = 2";
2549 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2550 if (!$user->hasRight(
'holiday',
'read_all')) {
2551 $userchildids = $user->getAllChildIds(1);
2552 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2553 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2556 $resql = $this->db->query($sql);
2558 $langs->load(
"members");
2561 $response->warning_delay =
$conf->holiday->approve->warning_delay / 60 / 60 / 24;
2562 $response->label = $langs->trans(
"HolidaysToApprove");
2563 $response->labelShort = $langs->trans(
"ToApprove");
2564 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2565 $response->img = img_object(
'',
"holiday");
2567 $obj = $this->db->fetch_object($resql);
2569 $response->nbtodo = (int) $obj->nb;
2570 $response->nbtodolate = (int) $obj->nblate;
2575 dol_print_error($this->db);
2576 $this->error = $this->db->error();
2591 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2593 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2594 $return .=
'<div class="info-box info-box-sm">';
2595 $return .=
'<span class="info-box-icon bg-infobox-action">';
2596 $return .= img_picto(
'', $this->picto);
2597 $return .=
'</span>';
2598 $return .=
'<div class="info-box-content">';
2599 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().
'</span>';
2600 if ($selected >= 0) {
2601 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2603 if (property_exists($this,
'fk_type')) {
2606 $return .=
'<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata[
'labeltype']).
'">'.
dol_escape_htmltag($arraydata[
'labeltype']).
'</div>';
2608 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2609 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_debut,
'day').
'</span>';
2610 $return .=
' <span class="opacitymedium small">'.$langs->trans(
"To").
'</span> ';
2611 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_fin,
'day').
'</span>';
2612 if (!empty($arraydata[
'nbopenedday'])) {
2613 $return .=
' ('.$arraydata[
'nbopenedday'].
')';
2616 if (method_exists($this,
'getLibStatut')) {
2617 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2619 $return .=
'</div>';
2620 $return .=
'</div>';
2621 $return .=
'</div>';
2637 global
$conf, $langs, $user;
2639 $outputlangs = $langs;
2644 $arrayfields = array(
2645 'user' =>
'Employee',
2647 'date_start' =>
'DateDebCP',
2648 'date_end' =>
'DateFinCP',
2649 'used_days' =>
'NbUseDaysCPShort',
2652 if (!empty($newlang)) {
2654 $outputlangs->setDefaultLang($newlang);
2656 $outputlangs->loadLangs(array(
'main',
'holiday',
'hrm'));
2659 $this->errors[] =
'Bad value for parameter mailto. Must be a valid email address.';
2663 $typeleaves = $this->
getTypes(1, -1);
2664 $arraytypeleaves = array();
2665 foreach ($typeleaves as $val) {
2666 $labeltoshow = ($outputlangs->trans($val[
'code']) != $val[
'code'] ? $outputlangs->trans($val[
'code']) : $val[
'label']);
2667 $arraytypeleaves[$val[
'rowid']] = $labeltoshow;
2669 $listhalfday = array(
'morning' => $outputlangs->trans(
"Morning"),
"afternoon" => $outputlangs->trans(
"Afternoon"));
2673 $year_month = sprintf(
"%04d", $prev_month[
"year"]).
'-'.sprintf(
"%02d", $prev_month[
"month"]);
2674 $arrayleaves = array();
2676 $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";
2677 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday cp";
2678 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user u ON cp.fk_user = u.rowid";
2679 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
") AND cp.rowid > 0";
2680 $sql .=
" AND cp.statut = ".Holiday::STATUS_APPROVED;
2682 $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).
"')";
2684 $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).
"') ";
2686 $sql .= $this->db->order(
"cp.fk_user, cp.date_debut",
"ASC");
2687 $resql = $this->db->query($sql);
2688 if (empty($resql)) {
2689 $this->errors[] = $this->db->lasterror();
2692 $num = $this->db->num_rows($resql);
2694 $tmpuser =
new User($this->db);
2695 while ($obj = $this->db->fetch_object($resql)) {
2696 $tmpuser->fetch($obj->fk_user);
2698 $date_start = $this->db->jdate($obj->date_debut,
true);
2699 $date_end = $this->db->jdate($obj->date_fin,
true);
2704 $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ?
'afternoon' :
'morning';
2705 $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ?
'morning' :
'afternoon';
2707 $halfdayinmonth = $obj->halfday;
2708 $starthalfdayinmonth = $starthalfday;
2709 $endhalfdayinmonth = $endhalfday;
2714 $date_start_inmonth = $this->db->jdate($obj->date_debut,
true);
2715 $date_end_inmonth = $this->db->jdate($obj->date_fin,
true);
2716 if ($tmpstart[
'year'] < $prev_month[
"year"] || $tmpstart[
'mon'] < $prev_month[
"month"]) {
2717 $date_start_inmonth =
dol_get_first_day($prev_month[
"year"], $prev_month[
"month"],
true);
2718 $starthalfdayinmonth =
'morning';
2719 if ($halfdayinmonth == 2) {
2720 $halfdayinmonth = 1;
2722 if ($halfdayinmonth == -1) {
2723 $halfdayinmonth = 0;
2726 if ($tmpend[
'year'] > $prev_month[
"year"] || $tmpend[
'mon'] > $prev_month[
"month"]) {
2727 $date_end_inmonth =
dol_get_last_day($prev_month[
"year"], $prev_month[
"month"],
true) - ((24 * 3600) - 1);
2728 $endhalfdayinmonth =
'afternoon';
2729 if ($halfdayinmonth == 2) {
2730 $halfdayinmonth = -1;
2732 if ($halfdayinmonth == 1) {
2733 $halfdayinmonth = 0;
2736 $arrayleaves[] = array(
2737 "user" => $tmpuser->getNomUrl(0,
'nolink', 0, 0, 24, 1),
2738 "type" => $arraytypeleaves[$obj->fk_type],
2739 "date_start" =>
dol_print_date($date_start_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$starthalfdayinmonth]).
')</span>',
2740 "date_end" =>
dol_print_date($date_end_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$endhalfdayinmonth]).
')</span>',
2741 "used_days" =>
num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth, $tmpuser->country_id, $obj->fk_user)
2746 $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;">';
2747 $outputarrayleaves .=
'<tr>';
2748 foreach ($arrayfields as $key => $label) {
2749 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;">';
2750 $outputarrayleaves .= $outputlangs->trans($label);
2751 if ($key ==
'date_end') {
2752 $outputarrayleaves .=
" (".$langs->trans(
"Included").
")";
2754 $outputarrayleaves .=
'</td>';
2756 $outputarrayleaves .=
'</tr>';
2758 if (!empty($arrayleaves)) {
2759 foreach ($arrayleaves as $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='', $placeholder='')
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.
const STATUS_CANCELED
Canceled.
fetchLog($sqlorder, $sqlwhere)
List log of leaves.
countActiveUsers()
Count number of active users in Dolibarr.
fetchByUser($user_id, $order='', $filter='')
List holidays for a particular user or list of users.
const STATUS_APPROVED
Approved.
getTooltipContentArray($params)
getTooltipContentArray
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
LibStatut($status, $mode=0, $startdate='')
Returns the label of a status.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_get_prev_month($month, $year)
Return previous month.
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='', $user_id=0)
Function to return number of working days (and text of units) between two dates (working days)
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_next_month($month, $year)
Return next month.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_stringtotime($string, $gm=1, $processnotimeasnoon=0)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0)
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)