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,";
538 $sql .=
" uu.fk_country as country_id,";
540 $sql .=
" ua.lastname as validator_lastname,";
541 $sql .=
" ua.firstname as validator_firstname,";
542 $sql .=
" ua.login as validator_login,";
543 $sql .=
" ua.statut as validator_status,";
544 $sql .=
" ua.photo as validator_photo";
546 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
547 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
548 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
549 $sql .=
" AND cp.fk_user IN (".$this->db->sanitize($user_id).
")";
552 if (!empty($filter)) {
557 if (!empty($order)) {
561 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
562 $resql = $this->db->query($sql);
567 $tab_result = $this->holiday;
568 $num = $this->db->num_rows($resql);
577 $obj = $this->db->fetch_object($resql);
579 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
580 $tab_result[$i][
'id'] = (int) $obj->rowid;
581 $tab_result[$i][
'ref'] = (
string) ($obj->ref ? $obj->ref : $obj->rowid);
583 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
584 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
585 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
586 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
587 $tab_result[$i][
'description'] = (
string) $obj->description;
588 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
589 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
590 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
591 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
592 $tab_result[$i][
'halfday'] = (int) $obj->halfday;
593 $tab_result[$i][
'statut'] = (int) $obj->status;
594 $tab_result[$i][
'status'] = (int) $obj->status;
595 $tab_result[$i][
'fk_validator'] = (int) $obj->fk_validator;
596 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
597 $tab_result[$i][
'fk_user_valid'] = (int) $obj->fk_user_valid;
598 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
599 $tab_result[$i][
'fk_user_approve'] = (int) $obj->fk_user_approve;
600 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
601 $tab_result[$i][
'fk_user_refuse'] = (int) $obj->fk_user_refuse;
602 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
603 $tab_result[$i][
'fk_user_cancel'] = (int) $obj->fk_user_cancel;
604 $tab_result[$i][
'detail_refuse'] = (
string) $obj->detail_refuse;
606 $tab_result[$i][
'user_firstname'] = (
string) $obj->user_firstname;
607 $tab_result[$i][
'user_lastname'] = (
string) $obj->user_lastname;
608 $tab_result[$i][
'user_login'] = (
string) $obj->user_login;
609 $tab_result[$i][
'user_statut'] = (int) $obj->user_status;
610 $tab_result[$i][
'user_status'] = (int) $obj->user_status;
611 $tab_result[$i][
'user_photo'] = (
string) $obj->user_photo;
613 $tab_result[$i][
'validator_firstname'] = (
string) $obj->validator_firstname;
614 $tab_result[$i][
'validator_lastname'] = (
string) $obj->validator_lastname;
615 $tab_result[$i][
'validator_login'] = (
string) $obj->validator_login;
616 $tab_result[$i][
'validator_statut'] = (int) $obj->validator_status;
617 $tab_result[$i][
'validator_status'] = (int) $obj->validator_status;
618 $tab_result[$i][
'validator_photo'] = (
string) $obj->validator_photo;
620 $tab_result[$i][
'country_id'] = (int) $obj->country_id;
626 $this->holiday = $tab_result;
630 $this->error =
"Error ".$this->db->lasterror();
645 $sql .=
" cp.rowid,";
647 $sql .=
" cp.fk_user,";
648 $sql .=
" cp.fk_type,";
649 $sql .=
" cp.date_create,";
650 $sql .=
" cp.tms as date_modification,";
651 $sql .=
" cp.description,";
652 $sql .=
" cp.date_debut,";
653 $sql .=
" cp.date_fin,";
654 $sql .=
" cp.halfday,";
655 $sql .=
" cp.statut as status,";
656 $sql .=
" cp.fk_validator,";
657 $sql .=
" cp.date_valid,";
658 $sql .=
" cp.fk_user_valid,";
659 $sql .=
" cp.date_approval,";
660 $sql .=
" cp.fk_user_approve,";
661 $sql .=
" cp.date_refuse,";
662 $sql .=
" cp.fk_user_refuse,";
663 $sql .=
" cp.date_cancel,";
664 $sql .=
" cp.fk_user_cancel,";
665 $sql .=
" cp.detail_refuse,";
667 $sql .=
" uu.lastname as user_lastname,";
668 $sql .=
" uu.firstname as user_firstname,";
669 $sql .=
" uu.login as user_login,";
670 $sql .=
" uu.statut as user_status,";
671 $sql .=
" uu.photo as user_photo,";
673 $sql .=
" ua.lastname as validator_lastname,";
674 $sql .=
" ua.firstname as validator_firstname,";
675 $sql .=
" ua.login as validator_login,";
676 $sql .=
" ua.statut as validator_status,";
677 $sql .=
" ua.photo as validator_photo";
679 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
680 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
681 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
684 if (!empty($sqlFilter)) {
689 if (!empty($sqlOrder)) {
693 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
694 $resql = $this->db->query($sql);
699 $tab_result = $this->holiday;
700 $num = $this->db->num_rows($resql);
709 $obj = $this->db->fetch_object($resql);
711 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
712 $tab_result[$i][
'id'] = (int) $obj->rowid;
713 $tab_result[$i][
'ref'] = (
string) ($obj->ref ? $obj->ref : $obj->rowid);
715 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
716 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
717 $tab_result[$i][
'date_create'] = $this->db->jdate($obj->date_create);
718 $tab_result[$i][
'date_modification'] = $this->db->jdate($obj->date_modification);
719 $tab_result[$i][
'description'] = (
string) $obj->description;
720 $tab_result[$i][
'date_debut'] = $this->db->jdate($obj->date_debut);
721 $tab_result[$i][
'date_fin'] = $this->db->jdate($obj->date_fin);
722 $tab_result[$i][
'date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
723 $tab_result[$i][
'date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
724 $tab_result[$i][
'halfday'] = (int) $obj->halfday;
725 $tab_result[$i][
'statut'] = (int) $obj->status;
726 $tab_result[$i][
'status'] = (int) $obj->status;
727 $tab_result[$i][
'fk_validator'] = (int) $obj->fk_validator;
728 $tab_result[$i][
'date_valid'] = $this->db->jdate($obj->date_valid);
729 $tab_result[$i][
'fk_user_valid'] = (int) $obj->fk_user_valid;
730 $tab_result[$i][
'date_approval'] = $this->db->jdate($obj->date_approval);
731 $tab_result[$i][
'fk_user_approve'] = (int) $obj->fk_user_approve;
732 $tab_result[$i][
'date_refuse'] = $this->db->jdate($obj->date_refuse);
733 $tab_result[$i][
'fk_user_refuse'] = (int) $obj->fk_user_refuse;
734 $tab_result[$i][
'date_cancel'] = $this->db->jdate($obj->date_cancel);
735 $tab_result[$i][
'fk_user_cancel'] = (int) $obj->fk_user_cancel;
736 $tab_result[$i][
'detail_refuse'] = (
string) $obj->detail_refuse;
738 $tab_result[$i][
'user_firstname'] = (
string) $obj->user_firstname;
739 $tab_result[$i][
'user_lastname'] = (
string) $obj->user_lastname;
740 $tab_result[$i][
'user_login'] = (
string) $obj->user_login;
741 $tab_result[$i][
'user_statut'] = (int) $obj->user_status;
742 $tab_result[$i][
'user_status'] = (int) $obj->user_status;
743 $tab_result[$i][
'user_photo'] = (
string) $obj->user_photo;
745 $tab_result[$i][
'validator_firstname'] = (
string) $obj->validator_firstname;
746 $tab_result[$i][
'validator_lastname'] = (
string) $obj->validator_lastname;
747 $tab_result[$i][
'validator_login'] = (
string) $obj->validator_login;
748 $tab_result[$i][
'validator_statut'] = (int) $obj->validator_status;
749 $tab_result[$i][
'validator_status'] = (int) $obj->validator_status;
750 $tab_result[$i][
'validator_photo'] = (
string) $obj->validator_photo;
755 $this->holiday = $tab_result;
759 $this->error =
"Error ".$this->db->lasterror();
772 public function validate($user =
null, $notrigger = 0)
774 global
$conf, $langs;
775 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
779 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
781 if ($checkBalance > 0) {
782 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
787 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
788 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
789 $daysAsked =
num_open_day($datedebutforcount, $datefinforcount, 0, 1, (
int) $this->halfday,
'', $this->fk_user);
791 if (($balance - $daysAsked) < 0) {
792 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
798 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref) || $this->
ref == $this->
id) {
799 $num = $this->getNextNumRef(
null);
806 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
807 $sql .=
" fk_user_valid = ".((int) $user->id).
",";
808 $sql .=
" date_valid = '".$this->db->idate(
dol_now()).
"',";
809 if (!empty($this->
status) && is_numeric($this->
status)) {
810 $sql .=
" statut = ".((int) $this->
status).
",";
812 $this->error =
'Property status must be a numeric value';
815 $sql .=
" ref = '".$this->db->escape($num).
"'";
816 $sql .=
" WHERE rowid = ".((int) $this->
id);
820 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
821 $resql = $this->db->query($sql);
824 $this->errors[] =
"Error ".$this->db->lasterror();
830 $result = $this->call_trigger(
'HOLIDAY_VALIDATE', $user);
839 $this->oldref = $this->ref;
842 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
844 $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) .
"'";
845 $sql .=
" WHERE filename LIKE '" . $this->db->escape($this->
ref) .
"%' AND filepath = 'holiday/" . $this->db->escape($this->
ref) .
"' and entity = " . ((int)
$conf->entity);
846 $resql = $this->db->query($sql);
849 $this->error = $this->db->lasterror();
851 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'holiday/".$this->db->escape($this->newref).
"'";
852 $sql .=
" WHERE filepath = 'holiday/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
853 $resql = $this->db->query($sql);
856 $this->error = $this->db->lasterror();
862 $dirsource =
$conf->holiday->multidir_output[$this->entity] .
'/' . $oldref;
863 $dirdest =
$conf->holiday->multidir_output[$this->entity] .
'/' . $newref;
864 if (!$error && file_exists($dirsource)) {
865 dol_syslog(get_class($this) .
"::validate rename dir " . $dirsource .
" into " . $dirdest);
866 if (@rename($dirsource, $dirdest)) {
869 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^' . preg_quote($oldref,
'/'));
870 foreach ($listoffiles as $fileentry) {
871 $dirsource = $fileentry[
'name'];
872 $dirdest = preg_replace(
'/^' . preg_quote($oldref,
'/') .
'/', $newref, $dirsource);
873 $dirsource = $fileentry[
'path'] .
'/' . $dirsource;
874 $dirdest = $fileentry[
'path'] .
'/' . $dirdest;
875 @rename($dirsource, $dirdest);
885 foreach ($this->errors as $errmsg) {
886 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
887 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
889 $this->db->rollback();
905 public function approve($user =
null, $notrigger = 0)
909 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
911 if ($checkBalance > 0) {
912 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
917 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
918 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
919 $daysAsked =
num_open_day($datedebutforcount, $datefinforcount, 0, 1, (
int) $this->halfday,
'', $this->fk_user);
921 if (($balance - $daysAsked) < 0) {
922 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
928 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
929 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
930 if (!empty($this->date_debut)) {
931 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
935 if (!empty($this->date_fin)) {
936 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
940 $sql .=
" halfday = ".((int) $this->halfday).
",";
941 if (!empty($this->
status) && is_numeric($this->
status)) {
942 $sql .=
" statut = ".((int) $this->
status).
",";
946 if (!empty($this->fk_validator)) {
947 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
951 if (!empty($this->date_valid)) {
952 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
954 $sql .=
" date_valid = NULL,";
956 if (!empty($this->fk_user_valid)) {
957 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
959 $sql .=
" fk_user_valid = NULL,";
961 if (!empty($this->date_approval)) {
962 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
964 $sql .=
" date_approval = NULL,";
966 if (!empty($this->fk_user_approve)) {
967 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
969 $sql .=
" fk_user_approve = NULL,";
971 if (!empty($this->date_refuse)) {
972 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
974 $sql .=
" date_refuse = NULL,";
976 if (!empty($this->fk_user_refuse)) {
977 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
979 $sql .=
" fk_user_refuse = NULL,";
981 if (!empty($this->date_cancel)) {
982 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
984 $sql .=
" date_cancel = NULL,";
986 if (!empty($this->fk_user_cancel)) {
987 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
989 $sql .=
" fk_user_cancel = NULL,";
991 if (!empty($this->detail_refuse)) {
992 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
994 $sql .=
" detail_refuse = NULL";
996 $sql .=
" WHERE rowid = ".((int) $this->
id);
1000 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
1001 $resql = $this->db->query($sql);
1004 $this->errors[] =
"Error ".$this->db->lasterror();
1010 $result = $this->call_trigger(
'HOLIDAY_APPROVE', $user);
1020 foreach ($this->errors as $errmsg) {
1021 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
1022 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1024 $this->db->rollback();
1027 $this->db->commit();
1039 public function update($user =
null, $notrigger = 0)
1043 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type,
true);
1044 if ($this->
status == self::STATUS_REFUSED || $this->
status == self::STATUS_APPROVED) {
1048 if ($checkBalance > 0 && $this->
status != self::STATUS_DRAFT && $this->
status != self::STATUS_CANCELED) {
1049 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
1054 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
1055 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
1056 $daysAsked =
num_open_day($datedebutforcount, $datefinforcount, 0, 1, (
int) $this->halfday,
'', $this->fk_user);
1058 if (($balance - $daysAsked) < 0) {
1059 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1065 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
1067 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
1069 if (!empty($this->date_create)) {
1070 $sql .=
" date_create = '".$this->db->idate($this->date_create).
"',";
1074 if (!empty($this->date_debut)) {
1075 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
1079 if (!empty($this->date_fin)) {
1080 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
1084 $sql .=
" halfday = ".((int) $this->halfday).
",";
1085 if (!empty($this->
status) && is_numeric($this->
status)) {
1086 $sql .=
" statut = ".((int) $this->
status).
",";
1090 if (!empty($this->fk_validator)) {
1091 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
1095 if (!empty($this->date_valid)) {
1096 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1098 $sql .=
" date_valid = NULL,";
1100 if (!empty($this->fk_user_valid)) {
1101 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
1103 $sql .=
" fk_user_valid = NULL,";
1105 if (!empty($this->date_approval)) {
1106 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
1108 $sql .=
" date_approval = NULL,";
1110 if (!empty($this->fk_user_approve)) {
1111 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
1113 $sql .=
" fk_user_approve = NULL,";
1115 if (!empty($this->date_refuse)) {
1116 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
1118 $sql .=
" date_refuse = NULL,";
1120 if (!empty($this->fk_user_refuse)) {
1121 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
1123 $sql .=
" fk_user_refuse = NULL,";
1125 if (!empty($this->date_cancel)) {
1126 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
1128 $sql .=
" date_cancel = NULL,";
1130 if (!empty($this->fk_user_cancel)) {
1131 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
1133 $sql .=
" fk_user_cancel = NULL,";
1135 if (!empty($this->detail_refuse)) {
1136 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1138 $sql .=
" detail_refuse = NULL";
1141 $sql .=
" WHERE rowid = ".((int) $this->
id);
1145 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1146 $resql = $this->db->query($sql);
1149 $this->errors[] =
"Error ".$this->db->lasterror();
1160 if (!$notrigger && $user !==
null) {
1162 $result = $this->call_trigger(
'HOLIDAY_MODIFY', $user);
1172 foreach ($this->errors as $errmsg) {
1173 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1174 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1176 $this->db->rollback();
1179 $this->db->commit();
1192 public function delete($user, $notrigger = 0)
1194 global
$conf, $langs;
1197 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1198 $sql .=
" WHERE rowid=".((int) $this->
id);
1209 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1210 $resql = $this->db->query($sql);
1213 $this->errors[] =
"Error ".$this->db->lasterror();
1220 $result = $this->call_trigger(
'HOLIDAY_DELETE', $user);
1230 foreach ($this->errors as $errmsg) {
1231 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1232 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1234 $this->db->rollback();
1237 $this->db->commit();
1259 foreach ($this->holiday as $infos_CP) {
1271 if ($dateStart < $infos_CP[
'date_debut'] && $dateEnd > $infos_CP[
'date_fin']) {
1275 if ($halfday == 0) {
1276 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1279 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1282 } elseif ($halfday == -1) {
1284 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1285 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1289 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1290 if ($dateStart < $dateEnd) {
1293 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1297 } elseif ($halfday == 1) {
1299 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1300 if ($dateStart < $dateEnd) {
1303 if ($dateStart > $infos_CP[
'date_debut'] || 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))) {
1312 } elseif ($halfday == 2) {
1314 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1315 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1319 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1320 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1325 dol_print_error(
null,
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1344 $isavailablemorning =
true;
1345 $isavailableafternoon =
true;
1348 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1349 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1350 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1351 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1352 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->db->idate($timestamp).
"'";
1353 if ($status !=
'-1') {
1354 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1357 $resql = $this->db->query($sql);
1359 $num_rows = $this->db->num_rows($resql);
1360 if ($num_rows > 0) {
1361 $arrayofrecord = array();
1363 while ($i < $num_rows) {
1364 $obj = $this->db->fetch_object($resql);
1367 $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);
1372 $isavailablemorning =
true;
1373 foreach ($arrayofrecord as $record) {
1374 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1377 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1380 $isavailablemorning =
false;
1383 $isavailableafternoon =
true;
1384 foreach ($arrayofrecord as $record) {
1385 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1388 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1391 $isavailableafternoon =
false;
1399 $result = array(
'morning' => (
int) $isavailablemorning,
'afternoon' => (
int) $isavailableafternoon);
1400 if (!$isavailablemorning) {
1401 $result[
'morning_reason'] =
'leave_request';
1403 if (!$isavailableafternoon) {
1404 $result[
'afternoon_reason'] =
'leave_request';
1419 $langs->load(
'holiday');
1420 $nofetch = !empty($params[
'nofetch']);
1423 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1424 if (isset($this->
status)) {
1425 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1427 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1429 if (!$nofetch && !empty($this->fk_type)) {
1430 $typeleaves = $this->
getTypes(1, -1);
1431 if (empty($typeleaves[$this->fk_type])) {
1432 $labeltoshow = $langs->trans(
"TypeWasDisabledOrRemoved", $this->fk_type);
1434 $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']);
1436 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type") .
':</b> ' . $labeltoshow;
1438 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1439 $listhalfday = array(
1440 'morning' => $langs->trans(
"Morning"),
1441 "afternoon" => $langs->trans(
"Afternoon")
1443 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ?
'afternoon' :
'morning';
1444 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ?
'morning' :
'afternoon';
1445 $datas[
'date_start'] =
'<br><b>'.$langs->trans(
'DateDebCP') .
'</b>: '.
dol_print_date($this->date_debut,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1446 $datas[
'date_end'] =
'<br><b>'.$langs->trans(
'DateFinCP') .
'</b>: '.
dol_print_date($this->date_fin,
'day') .
' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1462 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1464 global
$conf, $langs, $hookmanager;
1466 if (!empty(
$conf->dol_no_mouse_hover)) {
1473 'objecttype' => $this->element,
1476 $classfortooltip =
'classfortooltip';
1479 $classfortooltip =
'classforajaxtooltip';
1480 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1486 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1491 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1492 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1493 $add_save_lastsearch_values = 1;
1495 if ($add_save_lastsearch_values) {
1496 $url .=
'&save_lastsearch_values=1';
1501 if (empty($notooltip)) {
1503 $label = $langs->trans(
"ShowMyObject");
1504 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1506 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1507 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1509 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1512 $linkstart =
'<a href="'.$url.
'"';
1513 $linkstart .= $linkclose.
'>';
1516 $result .= $linkstart;
1519 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1521 if ($withpicto != 2) {
1522 $result .= $this->ref;
1524 $result .= $linkend;
1527 $hookmanager->initHooks(array($this->element .
'dao'));
1528 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1529 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1531 $result = $hookmanager->resPrint;
1533 $result .= $hookmanager->resPrint;
1559 public function LibStatut($status, $mode = 0, $startdate =
'')
1564 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1572 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1580 $statusType =
'status6';
1581 if (!empty($startdate) && $startdate >=
dol_now()) {
1582 $statusType =
'status4';
1583 $params = array(
'tooltip' => $this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1585 if ($status == self::STATUS_DRAFT) {
1586 $statusType =
'status0';
1588 if ($status == self::STATUS_VALIDATED) {
1589 $statusType =
'status1';
1591 if ($status == self::STATUS_CANCELED) {
1592 $statusType =
'status9';
1594 if ($status == self::STATUS_REFUSED) {
1595 $statusType =
'status9';
1598 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1610 public function selectStatutCP($selected = 0, $htmlname =
'select_statut', $morecss =
'minwidth125')
1615 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1616 $nb = count($name) + 1;
1619 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1620 $out .=
'<option value="-1"> </option>'.
"\n";
1623 for ($i = 1; $i < $nb; $i++) {
1624 if ($i == $selected) {
1625 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1627 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1631 $out .=
"</select>\n";
1634 $out .=
ajax_combobox($htmlname, array(), 0, 0,
'resolve', ($showempty < 0 ? (
string) $showempty :
'-1'), $morecss);
1648 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1649 $sql .=
" value = '".$this->db->escape($value).
"'";
1650 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1652 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1653 $result = $this->db->query($sql);
1671 $sql =
"SELECT value";
1672 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1673 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1675 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1676 $result = $this->db->query($sql);
1679 $obj = $this->db->fetch_object($result);
1682 if ($createifnotfound) {
1683 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1684 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->db->escape($createifnotfound).
"')";
1685 $result = $this->db->query($sql);
1687 return $createifnotfound;
1689 $this->error = $this->db->lasterror();
1700 $this->error = $this->db->lasterror();
1715 global $user, $langs;
1719 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1720 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
1721 $langs->load(
"holiday");
1734 if (empty($stringInDBForLastUpdate)) {
1737 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1738 $sql .=
" value = '".$this->db->escape($stringInDBForLastUpdate).
"'";
1739 $sql .=
" WHERE name = 'lastUpdate'";
1740 $result = $this->db->query($sql);
1742 $this->error = $this->db->lasterror();
1747 if ($stringInDBForLastUpdate <
'20000101000000') {
1748 $stringInDBForLastUpdate =
'20000101000000';
1759 while ($yearMonthLastUpdate < $yearMonthNow) {
1765 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1766 $nbUser = count($users);
1768 $typeleaves = $this->
getTypes(1, 1);
1771 foreach ($users as $userCounter) {
1772 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1773 if (empty($nbDaysToAdd)) {
1777 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1779 $nowHoliday = (float) $userCounter[
'nb_holiday'];
1780 $newSolde = $nowHoliday + $nbDaysToAdd;
1783 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidayMonthlyCredit'), $newSolde, $userCounter[
'type']);
1785 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1788 $this->db->rollback();
1792 if (empty($decrease)) {
1797 $filter =
" AND cp.statut = ".((int) self::STATUS_APPROVED);
1800 $filter .=
" AND cp.fk_type = ".((int) $userCounter[
'type']);
1801 $this->
fetchByUser($userCounter[
'id'],
'', $filter);
1803 if (empty($this->holiday)) {
1807 $startOfMonth =
dol_mktime(0, 0, 0, (
int) $month, 1, (
int) $year, 1);
1810 foreach ($this->holiday as $obj) {
1811 $startDate = $obj[
'date_debut_gmt'];
1812 $endDate = $obj[
'date_fin_gmt'];
1814 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1815 $startDate = $startOfMonth;
1818 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1819 $endDate = $endOfMonth;
1822 $nbDaysToDeduct = (float)
num_open_day($startDate, $endDate, 0, 1, $obj[
'halfday'], $obj[
'country_id'], $obj[
'fk_user']);
1824 if ($nbDaysToDeduct <= 0) {
1828 $newSolde -= $nbDaysToDeduct;
1831 $this->
addLogCP($user->id, $userCounter[
'rowid'], $obj[
'ref'].
' - '.$langs->trans(
'HolidayConsumption'), $newSolde, $userCounter[
'type']);
1833 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1836 $this->db->rollback();
1844 $lastUpdate =
dol_mktime(0, 0, 0, (
int) $newMonth[
'month'], 1, (
int) $newMonth[
'year']);
1846 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1847 $sql .=
" value = '".$this->db->escape(
dol_print_date($lastUpdate,
'%Y%m%d%H%M%S')).
"'";
1848 $sql .=
" WHERE name = 'lastUpdate'";
1849 $result = $this->db->query($sql);
1852 $this->db->rollback();
1856 $this->db->commit();
1866 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1867 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1868 $resql = $this->db->query($sql);
1870 $num = $this->db->num_rows($resql);
1874 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1875 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1876 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1877 $result = $this->db->query($sql);
1880 $this->errors[] = $this->db->lasterror();
1884 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1885 $sql .= ((float) $nbHoliday);
1886 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1887 $result = $this->db->query($sql);
1890 $this->errors[] = $this->db->lasterror();
1894 $this->errors[] = $this->db->lasterror();
1917 dol_syslog(get_class($this).
'::createCPusers');
1918 $arrayofusers = $this->
fetchUsers(
false,
true);
1920 foreach ($arrayofusers as $users) {
1921 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1922 $sql .=
" (fk_user, nb_holiday)";
1923 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1925 $resql = $this->db->query($sql);
1931 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1932 $sql .=
" (fk_user, nb_holiday)";
1933 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1935 $resql = $this->db->query($sql);
1951 $sql =
"SELECT nb_holiday";
1952 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1953 $sql .=
" WHERE fk_user = ".(int) $user_id;
1955 $sql .=
" AND fk_type = ".(int) $fk_type;
1958 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1959 $result = $this->db->query($sql);
1961 $obj = $this->db->fetch_object($result);
1964 return $obj->nb_holiday;
1981 public function fetchUsers($stringlist =
true, $type =
true, $sqlFilters =
'')
1983 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1990 $sql .=
" DISTINCT";
1993 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1996 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1997 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1998 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1999 $sql .=
" OR u.entity = 0)";
2001 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
2003 $sql .=
" AND u.statut > 0";
2004 $sql .=
" AND u.employee = 1";
2006 $sql .= $sqlFilters;
2009 $resql = $this->db->query($sql);
2014 $num = $this->db->num_rows($resql);
2019 $obj = $this->db->fetch_object($resql);
2022 $stringlist .= $obj->rowid;
2024 $stringlist .=
', '.$obj->rowid;
2033 $this->error =
"Error ".$this->db->lasterror();
2038 $sql =
"SELECT DISTINCT cpu.fk_user";
2039 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
2040 $sql .=
" WHERE cpu.fk_user = u.rowid";
2042 $sql .= $sqlFilters;
2045 $resql = $this->db->query($sql);
2050 $num = $this->db->num_rows($resql);
2055 $obj = $this->db->fetch_object($resql);
2058 $stringlist .= $obj->fk_user;
2060 $stringlist .=
', '.$obj->fk_user;
2069 $this->error =
"Error ".$this->db->lasterror();
2080 $sql .=
" DISTINCT";
2082 $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";
2083 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2086 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
2087 $sql .=
" WHERE ((ug.fk_user = u.rowid";
2088 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
2089 $sql .=
" OR u.entity = 0)";
2091 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
2094 $sql .=
" AND u.statut > 0";
2095 $sql .=
" AND u.employee = 1";
2097 $sql .= $sqlFilters;
2100 $resql = $this->db->query($sql);
2105 $tab_result = $this->holiday;
2106 $num = $this->db->num_rows($resql);
2110 $obj = $this->db->fetch_object($resql);
2112 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2113 $tab_result[$i][
'id'] = (int) $obj->rowid;
2114 $tab_result[$i][
'name'] = $obj->lastname;
2115 $tab_result[$i][
'lastname'] = $obj->lastname;
2116 $tab_result[$i][
'firstname'] = $obj->firstname;
2117 $tab_result[$i][
'gender'] = $obj->gender;
2118 $tab_result[$i][
'status'] = (int) $obj->status;
2119 $tab_result[$i][
'employee'] = (int) $obj->employee;
2120 $tab_result[$i][
'photo'] = $obj->photo;
2121 $tab_result[$i][
'fk_user'] = (int) $obj->fk_user;
2122 $tab_result[$i][
'country_id'] = (int) $obj->country_id;
2132 $this->errors[] =
"Error ".$this->db->lasterror();
2137 $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";
2138 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
2139 $sql .=
" WHERE cpu.fk_user = u.rowid";
2141 $sql .= $sqlFilters;
2144 $resql = $this->db->query($sql);
2149 $tab_result = $this->holiday;
2150 $num = $this->db->num_rows($resql);
2154 $obj = $this->db->fetch_object($resql);
2156 $tab_result[$i][
'rowid'] = $obj->rowid;
2157 $tab_result[$i][
'id'] = $obj->rowid;
2158 $tab_result[$i][
'name'] = $obj->lastname;
2159 $tab_result[$i][
'lastname'] = $obj->lastname;
2160 $tab_result[$i][
'firstname'] = $obj->firstname;
2161 $tab_result[$i][
'gender'] = $obj->gender;
2162 $tab_result[$i][
'status'] = $obj->status;
2163 $tab_result[$i][
'employee'] = $obj->employee;
2164 $tab_result[$i][
'photo'] = $obj->photo;
2165 $tab_result[$i][
'fk_user'] = $obj->fk_user;
2167 $tab_result[$i][
'type'] = $obj->fk_type;
2168 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
2176 $this->error =
"Error ".$this->db->lasterror();
2194 $users_validator = array();
2196 $sql =
"SELECT DISTINCT ur.fk_user";
2197 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2198 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2200 $sql .=
" SELECT DISTINCT ugu.fk_user";
2201 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2202 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
2205 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
2206 $result = $this->db->query($sql);
2208 $num_rows = $this->db->num_rows($result);
2210 while ($i < $num_rows) {
2211 $objp = $this->db->fetch_object($result);
2212 array_push($users_validator, $objp->fk_user);
2215 return $users_validator;
2217 $this->error = $this->db->lasterror();
2218 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2231 $sql =
"SELECT count(u.rowid) as compteur";
2232 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2233 $sql .=
" WHERE u.statut > 0";
2235 $result = $this->db->query($sql);
2236 $object = $this->db->fetch_object($result);
2247 $sql =
"SELECT count(u.rowid) as compteur";
2248 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2249 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2251 $result = $this->db->query($sql);
2252 $object = $this->db->fetch_object($result);
2266 if (empty($userCP)) {
2269 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2284 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2292 if ($prev_solde == $new_solde) {
2299 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2300 $sql .=
"date_action,";
2301 $sql .=
"fk_user_action,";
2302 $sql .=
"fk_user_update,";
2303 $sql .=
"type_action,";
2304 $sql .=
"prev_solde,";
2305 $sql .=
"new_solde,";
2307 $sql .=
") VALUES (";
2308 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2309 $sql .=
" ".((int) $fk_user_action).
",";
2310 $sql .=
" ".((int) $fk_user_update).
",";
2311 $sql .=
" '".$this->db->escape($label).
"',";
2312 $sql .=
" ".((float) $prev_solde).
",";
2313 $sql .=
" ".((float) $new_solde).
",";
2314 $sql .=
" ".((int) $fk_type);
2317 $resql = $this->db->query($sql);
2320 $this->errors[] =
"Error ".$this->db->lasterror();
2325 $optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2330 foreach ($this->errors as $errmsg) {
2331 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2332 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2334 $this->db->rollback();
2337 $this->db->commit();
2352 $sql .=
" cpl.rowid,";
2353 $sql .=
" cpl.date_action,";
2354 $sql .=
" cpl.fk_user_action,";
2355 $sql .=
" cpl.fk_user_update,";
2356 $sql .=
" cpl.type_action,";
2357 $sql .=
" cpl.prev_solde,";
2358 $sql .=
" cpl.new_solde,";
2359 $sql .=
" cpl.fk_type";
2360 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2361 $sql .=
" WHERE cpl.rowid > 0";
2364 if (!empty($sqlwhere)) {
2365 $sql .=
" ".$sqlwhere;
2369 if (!empty($sqlorder)) {
2370 $sql .=
" ".$sqlorder;
2373 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2374 $resql = $this->db->query($sql);
2379 $tab_result = $this->logs;
2380 $num = $this->db->num_rows($resql);
2389 $obj = $this->db->fetch_object($resql);
2391 $tab_result[$i][
'rowid'] = (int) $obj->rowid;
2392 $tab_result[$i][
'id'] = (int) $obj->rowid;
2393 $tab_result[$i][
'date_action'] = (
string) $obj->date_action;
2394 $tab_result[$i][
'fk_user_action'] = (int) $obj->fk_user_action;
2395 $tab_result[$i][
'fk_user_update'] = (int) $obj->fk_user_update;
2396 $tab_result[$i][
'type_action'] = (
string) $obj->type_action;
2397 $tab_result[$i][
'prev_solde'] = (float) $obj->prev_solde;
2398 $tab_result[$i][
'new_solde'] = (float) $obj->new_solde;
2399 $tab_result[$i][
'fk_type'] = (int) $obj->fk_type;
2404 $this->logs = $tab_result;
2408 $this->error =
"Error ".$this->db->lasterror();
2425 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2426 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2427 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int)
$mysoc->country_id).
')';
2428 $sql .=
" AND entity IN (0, ".getEntity(
'c_holiday_types').
")";
2430 $sql .=
" AND active = ".((int) $active);
2433 $sql .=
" AND affect = ".((int) $affect);
2435 $sql .=
" ORDER BY sortorder";
2437 $result = $this->db->query($sql);
2439 $num = $this->db->num_rows($result);
2442 while ($obj = $this->db->fetch_object($result)) {
2443 $types[$obj->rowid] = array(
2444 'id' => $obj->rowid,
2445 'rowid' => $obj->rowid,
2446 'code' => $obj->code,
2447 'label' => $obj->label,
2448 'affect' => $obj->affect,
2449 'delay' => $obj->delay,
2450 'newbymonth' => $obj->newbymonth
2474 $sql =
"SELECT f.rowid, f.statut as status,";
2475 $sql .=
" f.date_create as datec,";
2476 $sql .=
" f.tms as date_modification,";
2477 $sql .=
" f.date_valid as datev,";
2478 $sql .=
" f.date_approval as datea,";
2479 $sql .=
" f.date_refuse as dater,";
2480 $sql .=
" f.fk_user_create as fk_user_creation,";
2481 $sql .=
" f.fk_user_modif as fk_user_modification,";
2482 $sql .=
" f.fk_user_valid as fk_user_validation,";
2483 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2484 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2485 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2486 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2487 $sql .=
" WHERE f.rowid = ".((int) $id);
2488 $sql .=
" AND f.entity = ".((int)
$conf->entity);
2490 $resql = $this->db->query($sql);
2492 if ($this->db->num_rows($resql)) {
2493 $obj = $this->db->fetch_object($resql);
2495 $this->
id = $obj->rowid;
2497 $this->date_creation = $this->db->jdate($obj->datec);
2498 $this->date_modification = $this->db->jdate($obj->date_modification);
2499 $this->date_validation = $this->db->jdate($obj->datev);
2500 $this->date_approval = $this->db->jdate($obj->datea);
2502 $this->user_creation_id = $obj->fk_user_creation;
2503 $this->user_validation_id = $obj->fk_user_validation;
2504 $this->user_modification_id = $obj->fk_user_modification;
2507 if ($obj->fk_user_approval_done) {
2508 $this->fk_user_approve = $obj->fk_user_approval_done;
2512 $this->db->free($resql);
2528 global $user, $langs;
2532 $this->specimen = 1;
2534 $this->fk_user = $user->id;
2536 $this->date_debut =
dol_now();
2537 $this->date_fin =
dol_now() + (24 * 3600);
2538 $this->date_valid =
dol_now();
2539 $this->fk_validator = $user->id;
2556 $this->nb = array();
2558 $sql =
"SELECT count(h.rowid) as nb";
2559 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2560 $sql .=
" WHERE h.statut > 1";
2561 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2562 if (!$user->hasRight(
'holiday',
'readall')) {
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 while ($obj = $this->db->fetch_object($resql)) {
2571 $this->nb[
"holidays"] = $obj->nb;
2573 $this->db->free($resql);
2577 $this->error = $this->db->error();
2592 global
$conf, $langs;
2600 $sql =
"SELECT h.rowid, h.date_debut";
2601 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2602 $sql .=
" WHERE h.statut = 2";
2603 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2604 if (!$user->hasRight(
'holiday',
'read_all')) {
2605 $userchildids = $user->getAllChildIds(1);
2606 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2607 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2610 $resql = $this->db->query($sql);
2612 $langs->load(
"members");
2615 $response->warning_delay =
$conf->holiday->approve->warning_delay / 60 / 60 / 24;
2616 $response->label = $langs->trans(
"HolidaysToApprove");
2617 $response->labelShort = $langs->trans(
"ToApprove");
2618 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2621 while ($obj = $this->db->fetch_object($resql)) {
2622 $response->nbtodo++;
2624 if ($this->db->jdate($obj->date_debut) < ($now -
$conf->holiday->approve->warning_delay)) {
2625 $response->nbtodolate++;
2632 $this->error = $this->db->error();
2647 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2649 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2650 $return .=
'<div class="info-box info-box-sm">';
2651 $return .=
'<span class="info-box-icon bg-infobox-action">';
2653 $return .=
'</span>';
2654 $return .=
'<div class="info-box-content">';
2655 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().
'</span>';
2656 if ($selected >= 0) {
2657 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2659 if (property_exists($this,
'fk_type')) {
2662 $return .=
'<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata[
'labeltype']).
'">'.
dol_escape_htmltag($arraydata[
'labeltype']).
'</div>';
2664 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2665 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_debut,
'day').
'</span>';
2666 $return .=
' <span class="opacitymedium small">'.$langs->trans(
"To").
'</span> ';
2667 $return .=
'<span class="info-box-label small">'.dol_print_date($this->date_fin,
'day').
'</span>';
2668 if (!empty($arraydata[
'nbopenedday'])) {
2669 $return .=
' ('.$arraydata[
'nbopenedday'].
')';
2672 if (method_exists($this,
'getLibStatut')) {
2673 $return .=
'<div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2675 $return .=
'</div>';
2676 $return .=
'</div>';
2677 $return .=
'</div>';
2693 global
$conf, $langs, $user;
2695 $outputlangs = $langs;
2700 $arrayfields = array(
2701 'user' =>
'Employee',
2703 'date_start' =>
'DateDebCP',
2704 'date_end' =>
'DateFinCP',
2705 'used_days' =>
'NbUseDaysCPShort',
2708 if (!empty($newlang)) {
2710 $outputlangs->setDefaultLang($newlang);
2712 $outputlangs->loadLangs(array(
'main',
'holiday',
'hrm'));
2715 $this->errors[] =
'Bad value for parameter mailto. Must be a valid email address.';
2719 $typeleaves = $this->
getTypes(1, -1);
2720 $arraytypeleaves = array();
2721 foreach ($typeleaves as $val) {
2722 $labeltoshow = ($outputlangs->trans($val[
'code']) != $val[
'code'] ? $outputlangs->trans($val[
'code']) : $val[
'label']);
2723 $arraytypeleaves[$val[
'rowid']] = $labeltoshow;
2725 $listhalfday = array(
'morning' => $outputlangs->trans(
"Morning"),
"afternoon" => $outputlangs->trans(
"Afternoon"));
2729 $year_month = sprintf(
"%04d", $prev_month[
"year"]).
'-'.sprintf(
"%02d", $prev_month[
"month"]);
2730 $arrayleaves = array();
2732 $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";
2733 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday cp";
2734 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user u ON cp.fk_user = u.rowid";
2735 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
") AND cp.rowid > 0";
2736 $sql .=
" AND cp.statut = ".Holiday::STATUS_APPROVED;
2738 $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).
"')";
2740 $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).
"') ";
2742 $sql .= $this->db->order(
"cp.fk_user, cp.date_debut",
"ASC");
2743 $resql = $this->db->query($sql);
2744 if (empty($resql)) {
2745 $this->errors[] = $this->db->lasterror();
2748 $num = $this->db->num_rows($resql);
2750 $tmpuser =
new User($this->db);
2751 while ($obj = $this->db->fetch_object($resql)) {
2752 $tmpuser->fetch($obj->fk_user);
2754 $date_start = $this->db->jdate($obj->date_debut,
true);
2755 $date_end = $this->db->jdate($obj->date_fin,
true);
2760 $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ?
'afternoon' :
'morning';
2761 $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ?
'morning' :
'afternoon';
2763 $halfdayinmonth = $obj->halfday;
2764 $starthalfdayinmonth = $starthalfday;
2765 $endhalfdayinmonth = $endhalfday;
2770 $date_start_inmonth = $this->db->jdate($obj->date_debut,
true);
2771 $date_end_inmonth = $this->db->jdate($obj->date_fin,
true);
2772 if ($tmpstart[
'year'] < $prev_month[
"year"] || $tmpstart[
'mon'] < $prev_month[
"month"]) {
2773 $date_start_inmonth =
dol_get_first_day($prev_month[
"year"], $prev_month[
"month"],
true);
2774 $starthalfdayinmonth =
'morning';
2775 if ($halfdayinmonth == 2) {
2776 $halfdayinmonth = 1;
2778 if ($halfdayinmonth == -1) {
2779 $halfdayinmonth = 0;
2782 if ($tmpend[
'year'] > $prev_month[
"year"] || $tmpend[
'mon'] > $prev_month[
"month"]) {
2783 $date_end_inmonth =
dol_get_last_day($prev_month[
"year"], $prev_month[
"month"],
true) - ((24 * 3600) - 1);
2784 $endhalfdayinmonth =
'afternoon';
2785 if ($halfdayinmonth == 2) {
2786 $halfdayinmonth = -1;
2788 if ($halfdayinmonth == 1) {
2789 $halfdayinmonth = 0;
2792 $arrayleaves[] = array(
2793 "user" => $tmpuser->getNomUrl(0,
'nolink', 0, 0, 24, 1),
2794 "type" => $arraytypeleaves[$obj->fk_type],
2795 "date_start" =>
dol_print_date($date_start_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$starthalfdayinmonth]).
')</span>',
2796 "date_end" =>
dol_print_date($date_end_inmonth,
'day') .
' <span class="opacitymedium">('.$outputlangs->trans($listhalfday[$endhalfdayinmonth]).
')</span>',
2797 "used_days" =>
num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth, $tmpuser->country_id, $obj->fk_user)
2802 $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;">';
2803 $outputarrayleaves .=
'<tr>';
2804 foreach ($arrayfields as $key => $label) {
2805 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;">';
2806 $outputarrayleaves .= $outputlangs->trans($label);
2807 if ($key ==
'date_end') {
2808 $outputarrayleaves .=
" (".$langs->trans(
"Included").
")";
2810 $outputarrayleaves .=
'</td>';
2812 $outputarrayleaves .=
'</tr>';
2814 if (!empty($arrayleaves)) {
2815 foreach ($arrayleaves as $fields) {
2816 $outputarrayleaves .=
'<tr>';
2817 foreach ($fields as $field => $value) {
2818 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;" id="'.$field.
'">';
2819 $outputarrayleaves .= $value;
2820 $outputarrayleaves .=
'</td>';
2822 $outputarrayleaves .=
'</tr>';
2825 $outputarrayleaves .=
'<tr>';
2826 $outputarrayleaves .=
'<td style="border-bottom:1px solid #b6b6b6;padding: 6px 10px 6px 12px;" colspan="5">';
2827 $outputarrayleaves .= $outputlangs->trans(
"None");
2828 $outputarrayleaves .=
'</td>';
2829 $outputarrayleaves .=
'</tr>';
2831 $outputarrayleaves .=
'</table>';
2833 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2834 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2836 $formmail =
new FormMail($this->db);
2838 $templateLabel =
'';
2839 if (empty($template) || $template ==
'EmailTemplateCode') {
2840 $templateLabel =
'(HolidayHrInformationsPreviousMonth)';
2842 if (is_numeric($template)) {
2843 $templateId = $template;
2845 $templateLabel = $template;
2848 $mailtemplate = $formmail->getEMailTemplate($this->db,
"holiday", $user, $outputlangs, $templateId, 1, $templateLabel);
2850 if (is_numeric($mailtemplate) || empty($mailtemplate->topic)) {
2851 $this->errors[] =
'No mail template found for code "'.$templateLabel.
'" or id "'.$templateId.
'".';
2856 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $this);
2859 $subject =
make_substitutions($mailtemplate->topic, $substitutionarray, $outputlangs);
2863 $msg = preg_replace(
'/__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__/', $outputarrayleaves, $msg);
2864 $cmail =
new CMailFile($subject, $mailto, $from, $msg, array(), array(), array(),
'',
'', 0, 1);
2865 $result = $cmail->sendfile();
2866 if (!$result || !empty($cmail->error) || !empty($cmail->errors)) {
2867 $this->errors[] = $cmail->error;
2868 if (is_array($cmail->errors) && count($cmail->errors) > 0) {
2869 $this->errors = array_merge($this->errors, $cmail->errors);
2875 if (!empty($this->errors)) {
2876 $this->output .=
"\n";
2879 return ($error ? 1 : 0);
if(! $sortfield) if(! $sortorder) $object
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class of the module paid holiday.
getTypes($active=-1, $affect=-1)
Return array with list of types.
getNomUrl($withpicto=0, $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clickable name (with picto eventually)
verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday=0)
Check if a user is on holiday (partially or completely) into a period.
validate($user=null, $notrigger=0)
Validate leave request.
fetchUsers($stringlist=true, $type=true, $sqlFilters='')
Get list of Users or list of vacation balance.
info($id)
Load information on object.
updateBalance()
Update balance of vacations and check table of users for holidays is complete.
updateConfCP($name, $value)
Update an option of the Holiday module.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
fetchAll($sqlOrder, $sqlFilter)
List all holidays of all users.
fetch($id, $ref='')
Load object in memory from database.
addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
addLogCP
verifNbUsers($userDolibarrWithoutCP, $userCP)
Compare the number of active Dolibarr users to the number of paid leave users.
verifDateHolidayForTimestamp($fk_user, $timestamp, $status='-1')
Check that a user is not on holiday for a particular timestamp.
approve($user=null, $notrigger=0)
Approve leave request.
const STATUS_REFUSED
Refused.
getConfCP($name, $createifnotfound='')
Return value of a conf parameter for leave module TODO Move this into llx_const table.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Create a paid leave entry in the database.
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...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php