28 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'holiday';
44 public $table_element =
'holiday';
50 public $ismultientitymanaged = 0;
55 public $fk_element =
'fk_holiday';
60 public $picto =
'holiday';
67 public $date_create =
'';
74 public $date_debut =
'';
75 public $date_fin =
'';
76 public $date_debut_gmt =
'';
77 public $date_fin_gmt =
'';
89 public $date_valid =
'';
94 public $fk_user_valid;
99 public $date_approval;
104 public $fk_user_approve;
109 public $date_refuse =
'';
114 public $fk_user_refuse;
119 public $date_cancel =
'';
124 public $fk_user_cancel;
127 public $detail_refuse =
'';
134 public $holiday = array();
135 public $events = array();
136 public $logs = array();
138 public $optName =
'';
139 public $optValue =
'';
140 public $optRowid =
'';
184 global $langs, $conf;
185 $langs->load(
"order");
187 if (empty($conf->global->HOLIDAY_ADDON)) {
188 $conf->global->HOLIDAY_ADDON =
'mod_holiday_madonna';
191 if (!empty($conf->global->HOLIDAY_ADDON)) {
194 $file = $conf->global->HOLIDAY_ADDON.
".php";
195 $classname = $conf->global->HOLIDAY_ADDON;
198 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
199 foreach ($dirmodels as $reldir) {
203 $mybool |= @include_once $dir.$file;
206 if ($mybool ===
false) {
211 $obj =
new $classname();
212 $numref = $obj->getNextValue($objsoc, $this);
217 $this->error = $obj->error;
222 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_HOLIDAY_ADDON_NotDefined");
246 $this->
db->rollback();
258 public function create($user, $notrigger = 0)
266 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
267 $this->error =
"ErrorBadParameterFkUser";
return -1;
269 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
270 $this->error =
"ErrorBadParameterFkValidator";
return -1;
272 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
273 $this->error =
"ErrorBadParameterFkType";
return -1;
277 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday(";
280 $sql .=
"date_create,";
281 $sql .=
"description,";
282 $sql .=
"date_debut,";
286 $sql .=
"fk_validator,";
288 $sql .=
"fk_user_create,";
290 $sql .=
") VALUES (";
292 $sql .=
" ".((int) $this->fk_user).
",";
293 $sql .=
" '".$this->db->idate($now).
"',";
294 $sql .=
" '".$this->db->escape($this->
description).
"',";
295 $sql .=
" '".$this->db->idate($this->date_debut).
"',";
296 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
297 $sql .=
" ".((int) $this->halfday).
",";
299 $sql .=
" ".((int) $this->fk_validator).
",";
300 $sql .=
" ".((int) $this->fk_type).
",";
301 $sql .=
" ".((int) $user->id).
",";
302 $sql .=
" ".((int) $conf->entity);
307 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
310 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
314 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"holiday");
318 $initialref =
'(PROV'.$this->id.
')';
319 if (!empty($this->
ref)) {
320 $initialref = $this->ref;
323 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"holiday SET ref='".$this->
db->escape($initialref).
"' WHERE rowid=".((int) $this->
id);
324 if ($this->
db->query($sql)) {
325 $this->
ref = $initialref;
334 if (!$error && !$notrigger) {
348 foreach ($this->errors as $errmsg) {
349 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
350 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
352 $this->
db->rollback();
368 public function fetch($id, $ref =
'')
373 $sql .=
" cp.rowid,";
375 $sql .=
" cp.fk_user,";
376 $sql .=
" cp.date_create,";
377 $sql .=
" cp.description,";
378 $sql .=
" cp.date_debut,";
379 $sql .=
" cp.date_fin,";
380 $sql .=
" cp.halfday,";
381 $sql .=
" cp.statut,";
382 $sql .=
" cp.fk_validator,";
383 $sql .=
" cp.date_valid,";
384 $sql .=
" cp.fk_user_valid,";
385 $sql .=
" cp.date_approval,";
386 $sql .=
" cp.fk_user_approve,";
387 $sql .=
" cp.date_refuse,";
388 $sql .=
" cp.fk_user_refuse,";
389 $sql .=
" cp.date_cancel,";
390 $sql .=
" cp.fk_user_cancel,";
391 $sql .=
" cp.detail_refuse,";
392 $sql .=
" cp.note_private,";
393 $sql .=
" cp.note_public,";
394 $sql .=
" cp.fk_user_create,";
395 $sql .=
" cp.fk_type,";
396 $sql .=
" cp.entity";
397 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
399 $sql .=
" WHERE cp.rowid = ".((int) $id);
401 $sql .=
" WHERE cp.ref = '".$this->db->escape($ref).
"'";
404 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
408 $obj = $this->
db->fetch_object(
$resql);
410 $this->
id = $obj->rowid;
411 $this->
ref = ($obj->ref ? $obj->ref : $obj->rowid);
412 $this->fk_user = $obj->fk_user;
413 $this->date_create = $this->
db->jdate($obj->date_create);
415 $this->date_debut = $this->
db->jdate($obj->date_debut);
416 $this->date_fin = $this->
db->jdate($obj->date_fin);
417 $this->date_debut_gmt = $this->
db->jdate($obj->date_debut, 1);
418 $this->date_fin_gmt = $this->
db->jdate($obj->date_fin, 1);
419 $this->halfday = $obj->halfday;
420 $this->statut = $obj->statut;
421 $this->fk_validator = $obj->fk_validator;
422 $this->date_valid = $this->
db->jdate($obj->date_valid);
423 $this->fk_user_valid = $obj->fk_user_valid;
424 $this->user_validation_id = $obj->fk_user_valid;
425 $this->date_approval = $this->
db->jdate($obj->date_approval);
426 $this->fk_user_approve = $obj->fk_user_approve;
427 $this->date_refuse = $this->
db->jdate($obj->date_refuse);
428 $this->fk_user_refuse = $obj->fk_user_refuse;
429 $this->date_cancel = $this->
db->jdate($obj->date_cancel);
430 $this->fk_user_cancel = $obj->fk_user_cancel;
431 $this->detail_refuse = $obj->detail_refuse;
432 $this->note_private = $obj->note_private;
433 $this->note_public = $obj->note_public;
434 $this->fk_user_create = $obj->fk_user_create;
435 $this->fk_type = $obj->fk_type;
436 $this->entity = $obj->entity;
448 $this->error =
"Error ".$this->db->lasterror();
463 global $langs, $conf;
466 $sql .=
" cp.rowid,";
469 $sql .=
" cp.fk_user,";
470 $sql .=
" cp.fk_type,";
471 $sql .=
" cp.date_create,";
472 $sql .=
" cp.description,";
473 $sql .=
" cp.date_debut,";
474 $sql .=
" cp.date_fin,";
475 $sql .=
" cp.halfday,";
476 $sql .=
" cp.statut,";
477 $sql .=
" cp.fk_validator,";
478 $sql .=
" cp.date_valid,";
479 $sql .=
" cp.fk_user_valid,";
480 $sql .=
" cp.date_approval,";
481 $sql .=
" cp.fk_user_approve,";
482 $sql .=
" cp.date_refuse,";
483 $sql .=
" cp.fk_user_refuse,";
484 $sql .=
" cp.date_cancel,";
485 $sql .=
" cp.fk_user_cancel,";
486 $sql .=
" cp.detail_refuse,";
488 $sql .=
" uu.lastname as user_lastname,";
489 $sql .=
" uu.firstname as user_firstname,";
490 $sql .=
" uu.login as user_login,";
491 $sql .=
" uu.statut as user_statut,";
492 $sql .=
" uu.photo as user_photo,";
494 $sql .=
" ua.lastname as validator_lastname,";
495 $sql .=
" ua.firstname as validator_firstname,";
496 $sql .=
" ua.login as validator_login,";
497 $sql .=
" ua.statut as validator_statut,";
498 $sql .=
" ua.photo as validator_photo";
500 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
501 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
502 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
503 $sql .=
" AND cp.fk_user IN (".$this->db->sanitize($user_id).
")";
506 if (!empty($filter)) {
511 if (!empty($order)) {
515 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
521 $tab_result = $this->holiday;
531 $obj = $this->
db->fetch_object(
$resql);
533 $tab_result[$i][
'rowid'] = $obj->rowid;
534 $tab_result[$i][
'id'] = $obj->rowid;
535 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
537 $tab_result[$i][
'fk_user'] = $obj->fk_user;
538 $tab_result[$i][
'fk_type'] = $obj->fk_type;
539 $tab_result[$i][
'date_create'] = $this->
db->jdate($obj->date_create);
540 $tab_result[$i][
'description'] = $obj->description;
541 $tab_result[$i][
'date_debut'] = $this->
db->jdate($obj->date_debut);
542 $tab_result[$i][
'date_fin'] = $this->
db->jdate($obj->date_fin);
543 $tab_result[$i][
'date_debut_gmt'] = $this->
db->jdate($obj->date_debut, 1);
544 $tab_result[$i][
'date_fin_gmt'] = $this->
db->jdate($obj->date_fin, 1);
545 $tab_result[$i][
'halfday'] = $obj->halfday;
546 $tab_result[$i][
'statut'] = $obj->statut;
547 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
548 $tab_result[$i][
'date_valid'] = $this->
db->jdate($obj->date_valid);
549 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
550 $tab_result[$i][
'date_approval'] = $this->
db->jdate($obj->date_approval);
551 $tab_result[$i][
'fk_user_approve'] = $obj->fk_user_approve;
552 $tab_result[$i][
'date_refuse'] = $this->
db->jdate($obj->date_refuse);
553 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
554 $tab_result[$i][
'date_cancel'] = $this->
db->jdate($obj->date_cancel);
555 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
556 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
558 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
559 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
560 $tab_result[$i][
'user_login'] = $obj->user_login;
561 $tab_result[$i][
'user_statut'] = $obj->user_statut;
562 $tab_result[$i][
'user_photo'] = $obj->user_photo;
564 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
565 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
566 $tab_result[$i][
'validator_login'] = $obj->validator_login;
567 $tab_result[$i][
'validator_statut'] = $obj->validator_statut;
568 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
574 $this->holiday = $tab_result;
578 $this->error =
"Error ".$this->db->lasterror();
595 $sql .=
" cp.rowid,";
598 $sql .=
" cp.fk_user,";
599 $sql .=
" cp.fk_type,";
600 $sql .=
" cp.date_create,";
601 $sql .=
" cp.tms as date_update,";
602 $sql .=
" cp.description,";
603 $sql .=
" cp.date_debut,";
604 $sql .=
" cp.date_fin,";
605 $sql .=
" cp.halfday,";
606 $sql .=
" cp.statut,";
607 $sql .=
" cp.fk_validator,";
608 $sql .=
" cp.date_valid,";
609 $sql .=
" cp.fk_user_valid,";
610 $sql .=
" cp.date_approval,";
611 $sql .=
" cp.fk_user_approve,";
612 $sql .=
" cp.date_refuse,";
613 $sql .=
" cp.fk_user_refuse,";
614 $sql .=
" cp.date_cancel,";
615 $sql .=
" cp.fk_user_cancel,";
616 $sql .=
" cp.detail_refuse,";
618 $sql .=
" uu.lastname as user_lastname,";
619 $sql .=
" uu.firstname as user_firstname,";
620 $sql .=
" uu.login as user_login,";
621 $sql .=
" uu.statut as user_statut,";
622 $sql .=
" uu.photo as user_photo,";
624 $sql .=
" ua.lastname as validator_lastname,";
625 $sql .=
" ua.firstname as validator_firstname,";
626 $sql .=
" ua.login as validator_login,";
627 $sql .=
" ua.statut as validator_statut,";
628 $sql .=
" ua.photo as validator_photo";
630 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
631 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
632 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
635 if (!empty($filter)) {
640 if (!empty($order)) {
644 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
650 $tab_result = $this->holiday;
660 $obj = $this->
db->fetch_object(
$resql);
662 $tab_result[$i][
'rowid'] = $obj->rowid;
663 $tab_result[$i][
'id'] = $obj->rowid;
664 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
666 $tab_result[$i][
'fk_user'] = $obj->fk_user;
667 $tab_result[$i][
'fk_type'] = $obj->fk_type;
668 $tab_result[$i][
'date_create'] = $this->
db->jdate($obj->date_create);
669 $tab_result[$i][
'date_update'] = $this->
db->jdate($obj->date_update);
670 $tab_result[$i][
'description'] = $obj->description;
671 $tab_result[$i][
'date_debut'] = $this->
db->jdate($obj->date_debut);
672 $tab_result[$i][
'date_fin'] = $this->
db->jdate($obj->date_fin);
673 $tab_result[$i][
'date_debut_gmt'] = $this->
db->jdate($obj->date_debut, 1);
674 $tab_result[$i][
'date_fin_gmt'] = $this->
db->jdate($obj->date_fin, 1);
675 $tab_result[$i][
'halfday'] = $obj->halfday;
676 $tab_result[$i][
'statut'] = $obj->statut;
677 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
678 $tab_result[$i][
'date_valid'] = $this->
db->jdate($obj->date_valid);
679 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
680 $tab_result[$i][
'date_approval'] = $this->
db->jdate($obj->date_approval);
681 $tab_result[$i][
'fk_user_approve'] = $obj->fk_user_approve;
682 $tab_result[$i][
'date_refuse'] = $obj->date_refuse;
683 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
684 $tab_result[$i][
'date_cancel'] = $obj->date_cancel;
685 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
686 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
688 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
689 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
690 $tab_result[$i][
'user_login'] = $obj->user_login;
691 $tab_result[$i][
'user_statut'] = $obj->user_statut;
692 $tab_result[$i][
'user_photo'] = $obj->user_photo;
694 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
695 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
696 $tab_result[$i][
'validator_login'] = $obj->validator_login;
697 $tab_result[$i][
'validator_statut'] = $obj->validator_statut;
698 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
703 $this->holiday = $tab_result;
707 $this->error =
"Error ".$this->db->lasterror();
720 public function validate($user =
null, $notrigger = 0)
722 global $conf, $langs;
723 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
726 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type);
728 if ($checkBalance > 0) {
729 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
732 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
738 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref) || $this->
ref == $this->
id)) {
746 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
747 $sql .=
" fk_user_valid = ".((int) $user->id).
",";
748 $sql .=
" date_valid = '".$this->db->idate(
dol_now()).
"',";
749 if (!empty($this->statut) && is_numeric($this->statut)) {
750 $sql .=
" statut = ".((int) $this->statut).
",";
752 $this->error =
'Property status must be a numeric value';
755 $sql .=
" ref = '".$this->db->escape($num).
"'";
756 $sql .=
" WHERE rowid = ".((int) $this->
id);
760 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
763 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
769 $result = $this->
call_trigger(
'HOLIDAY_VALIDATE', $user);
778 $this->oldref = $this->ref;
781 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
783 $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) .
"'";
784 $sql .=
" WHERE filename LIKE '" . $this->
db->escape($this->
ref) .
"%' AND filepath = 'holiday/" . $this->
db->escape($this->
ref) .
"' and entity = " . ((int) $conf->entity);
788 $this->error = $this->
db->lasterror();
794 $dirsource = $conf->holiday->multidir_output[$this->entity] .
'/' . $oldref;
795 $dirdest = $conf->holiday->multidir_output[$this->entity] .
'/' . $newref;
796 if (!$error && file_exists($dirsource)) {
797 dol_syslog(get_class($this) .
"::validate rename dir " . $dirsource .
" into " . $dirdest);
798 if (@rename($dirsource, $dirdest)) {
801 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^' . preg_quote($oldref,
'/'));
802 foreach ($listoffiles as $fileentry) {
803 $dirsource = $fileentry[
'name'];
804 $dirdest = preg_replace(
'/^' . preg_quote($oldref,
'/') .
'/', $newref, $dirsource);
805 $dirsource = $fileentry[
'path'] .
'/' . $dirsource;
806 $dirdest = $fileentry[
'path'] .
'/' . $dirdest;
807 @rename($dirsource, $dirdest);
817 foreach ($this->errors as $errmsg) {
818 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
819 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
821 $this->
db->rollback();
837 public function approve($user =
null, $notrigger = 0)
839 global $conf, $langs;
842 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type);
844 if ($checkBalance > 0) {
845 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
848 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
854 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
856 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
858 if (!empty($this->date_debut)) {
859 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
863 if (!empty($this->date_fin)) {
864 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
868 $sql .=
" halfday = ".((int) $this->halfday).
",";
869 if (!empty($this->statut) && is_numeric($this->statut)) {
870 $sql .=
" statut = ".((int) $this->statut).
",";
874 if (!empty($this->fk_validator)) {
875 $sql .=
" fk_validator = ".((int) $this->fk_validator).
",";
879 if (!empty($this->date_valid)) {
880 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
882 $sql .=
" date_valid = NULL,";
884 if (!empty($this->fk_user_valid)) {
885 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
887 $sql .=
" fk_user_valid = NULL,";
889 if (!empty($this->date_approval)) {
890 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
892 $sql .=
" date_approval = NULL,";
894 if (!empty($this->fk_user_approve)) {
895 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
897 $sql .=
" fk_user_approve = NULL,";
899 if (!empty($this->date_refuse)) {
900 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
902 $sql .=
" date_refuse = NULL,";
904 if (!empty($this->fk_user_refuse)) {
905 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
907 $sql .=
" fk_user_refuse = NULL,";
909 if (!empty($this->date_cancel)) {
910 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
912 $sql .=
" date_cancel = NULL,";
914 if (!empty($this->fk_user_cancel)) {
915 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
917 $sql .=
" fk_user_cancel = NULL,";
919 if (!empty($this->detail_refuse)) {
920 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
922 $sql .=
" detail_refuse = NULL";
924 $sql .=
" WHERE rowid = ".((int) $this->
id);
928 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
931 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
937 $result = $this->
call_trigger(
'HOLIDAY_APPROVE', $user);
947 foreach ($this->errors as $errmsg) {
948 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
949 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
951 $this->
db->rollback();
966 public function update($user =
null, $notrigger = 0)
968 global $conf, $langs;
971 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type);
973 if ($checkBalance > 0 && $this->statut != self::STATUS_DRAFT) {
974 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
977 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
983 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
985 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
987 if (!empty($this->date_debut)) {
988 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
992 if (!empty($this->date_fin)) {
993 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
997 $sql .=
" halfday = ".$this->halfday.
",";
998 if (!empty($this->statut) && is_numeric($this->statut)) {
999 $sql .=
" statut = ".$this->statut.
",";
1003 if (!empty($this->fk_validator)) {
1004 $sql .=
" fk_validator = '".$this->db->escape($this->fk_validator).
"',";
1008 if (!empty($this->date_valid)) {
1009 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1011 $sql .=
" date_valid = NULL,";
1013 if (!empty($this->fk_user_valid)) {
1014 $sql .=
" fk_user_valid = ".((int) $this->fk_user_valid).
",";
1016 $sql .=
" fk_user_valid = NULL,";
1018 if (!empty($this->date_approval)) {
1019 $sql .=
" date_approval = '".$this->db->idate($this->date_approval).
"',";
1021 $sql .=
" date_approval = NULL,";
1023 if (!empty($this->fk_user_approve)) {
1024 $sql .=
" fk_user_approve = ".((int) $this->fk_user_approve).
",";
1026 $sql .=
" fk_user_approve = NULL,";
1028 if (!empty($this->date_refuse)) {
1029 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
1031 $sql .=
" date_refuse = NULL,";
1033 if (!empty($this->fk_user_refuse)) {
1034 $sql .=
" fk_user_refuse = ".((int) $this->fk_user_refuse).
",";
1036 $sql .=
" fk_user_refuse = NULL,";
1038 if (!empty($this->date_cancel)) {
1039 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
1041 $sql .=
" date_cancel = NULL,";
1043 if (!empty($this->fk_user_cancel)) {
1044 $sql .=
" fk_user_cancel = ".((int) $this->fk_user_cancel).
",";
1046 $sql .=
" fk_user_cancel = NULL,";
1048 if (!empty($this->detail_refuse)) {
1049 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1051 $sql .=
" detail_refuse = NULL";
1054 $sql .=
" WHERE rowid = ".((int) $this->
id);
1058 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1061 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1067 $result = $this->
call_trigger(
'HOLIDAY_MODIFY', $user);
1077 foreach ($this->errors as $errmsg) {
1078 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1079 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1081 $this->
db->rollback();
1084 $this->
db->commit();
1097 public function delete($user, $notrigger = 0)
1099 global $conf, $langs;
1102 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1103 $sql .=
" WHERE rowid=".((int) $this->
id);
1107 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1110 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1116 $result = $this->
call_trigger(
'HOLIDAY_DELETE', $user);
1126 foreach ($this->errors as $errmsg) {
1127 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1128 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1130 $this->
db->rollback();
1133 $this->
db->commit();
1155 foreach ($this->holiday as $infos_CP) {
1166 if ($halfday == 0) {
1167 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1170 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1173 } elseif ($halfday == -1) {
1175 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1176 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1180 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1181 if ($dateStart < $dateEnd) {
1184 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1188 } elseif ($halfday == 1) {
1190 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1191 if ($dateStart < $dateEnd) {
1194 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1198 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1199 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1203 } elseif ($halfday == 2) {
1205 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1206 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1210 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1211 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1216 dol_print_error(
'',
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1235 global $langs, $conf;
1237 $isavailablemorning =
true;
1238 $isavailableafternoon =
true;
1241 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut";
1242 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1243 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1244 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1245 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->
db->idate($timestamp).
"'";
1246 if ($status !=
'-1') {
1247 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1252 $num_rows = $this->
db->num_rows(
$resql);
1253 if ($num_rows > 0) {
1254 $arrayofrecord = array();
1256 while ($i < $num_rows) {
1257 $obj = $this->
db->fetch_object(
$resql);
1260 $arrayofrecord[$obj->rowid] = array(
'date_start'=>$this->
db->jdate($obj->date_start),
'date_end'=>$this->db->jdate($obj->date_end),
'halfday'=>$obj->halfday);
1265 $isavailablemorning =
true;
1266 foreach ($arrayofrecord as $record) {
1267 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1270 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1273 $isavailablemorning =
false;
1276 $isavailableafternoon =
true;
1277 foreach ($arrayofrecord as $record) {
1278 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1281 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1284 $isavailableafternoon =
false;
1292 $result = array(
'morning'=>$isavailablemorning,
'afternoon'=>$isavailableafternoon);
1293 if (!$isavailablemorning) {
1294 $result[
'morning_reason'] =
'leave_request';
1296 if (!$isavailableafternoon) {
1297 $result[
'afternoon_reason'] =
'leave_request';
1311 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0)
1313 global $langs, $hookmanager;
1317 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1318 if (isset($this->statut)) {
1319 $label .=
' '.$this->getLibStatut(5);
1321 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1323 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1328 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1329 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1330 $add_save_lastsearch_values = 1;
1332 if ($add_save_lastsearch_values) {
1333 $url .=
'&save_lastsearch_values=1';
1337 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1340 $result .= $linkstart;
1342 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1344 if ($withpicto != 2) {
1345 $result .= $this->ref;
1347 $result .= $linkend;
1349 $hookmanager->initHooks(array($this->element .
'dao'));
1350 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1351 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1353 $result = $hookmanager->resPrint;
1355 $result .= $hookmanager->resPrint;
1369 return $this->
LibStatut($this->statut, $mode, $this->date_debut);
1381 public function LibStatut($status, $mode = 0, $startdate =
'')
1386 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1394 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1402 $statusType =
'status6';
1403 if (!empty($startdate) && $startdate >=
dol_now()) {
1404 $statusType =
'status4';
1405 $params = array(
'tooltip'=>$this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1407 if ($status == self::STATUS_DRAFT) {
1408 $statusType =
'status0';
1410 if ($status == self::STATUS_VALIDATED) {
1411 $statusType =
'status1';
1413 if ($status == self::STATUS_CANCELED) {
1414 $statusType =
'status5';
1416 if ($status == self::STATUS_REFUSED) {
1417 $statusType =
'status5';
1420 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1432 public function selectStatutCP($selected =
'', $htmlname =
'select_statut', $morecss =
'minwidth125')
1437 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1438 $nb = count($name) + 1;
1441 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1442 $out .=
'<option value="-1"> </option>'.
"\n";
1445 for ($i = 1; $i < $nb; $i++) {
1446 if ($i == $selected) {
1447 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1449 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1453 $out .=
'</select>'.
"\n";
1469 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1470 $sql .=
" value = '".$this->db->escape($value).
"'";
1471 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1473 dol_syslog(get_class($this).
'::updateConfCP name='.$name, LOG_DEBUG);
1474 $result = $this->
db->query($sql);
1492 $sql =
"SELECT value";
1493 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1494 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1496 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1497 $result = $this->
db->query($sql);
1500 $obj = $this->
db->fetch_object($result);
1503 if ($createifnotfound) {
1504 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1505 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->
db->escape($createifnotfound).
"')";
1506 $result = $this->
db->query($sql);
1508 return $createifnotfound;
1510 $this->error = $this->
db->lasterror();
1521 $this->error = $this->
db->lasterror();
1536 global $user, $langs;
1540 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1541 $langs->load(
"holiday");
1546 $month = date(
'm', $now);
1550 $lastUpdate = $this->
getConfCP(
'lastUpdate', $newdateforlastupdate);
1551 $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
1555 if ($month != $monthLastUpdate) {
1558 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1559 $nbUser = count($users);
1561 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1562 $sql .=
" value = '".$this->db->escape($newdateforlastupdate).
"'";
1563 $sql .=
" WHERE name = 'lastUpdate'";
1564 $result = $this->
db->query($sql);
1566 $typeleaves = $this->
getTypes(1, 1);
1569 foreach ($users as $userCounter) {
1570 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1571 if (empty($nbDaysToAdd)) {
1575 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1577 $nowHoliday = $userCounter[
'nb_holiday'];
1578 $newSolde = $nowHoliday + $nbDaysToAdd;
1581 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidaysMonthlyUpdate'), $newSolde, $userCounter[
'type']);
1583 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type']);
1592 $this->
db->commit();
1595 $this->
db->rollback();
1605 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1606 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1609 $num = $this->
db->num_rows(
$resql);
1613 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1614 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1615 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1616 $result = $this->
db->query($sql);
1619 $this->errors[] = $this->
db->lasterror();
1623 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1624 $sql .= ((
float) $nbHoliday);
1625 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1626 $result = $this->
db->query($sql);
1629 $this->errors[] = $this->
db->lasterror();
1633 $this->errors[] = $this->
db->lasterror();
1654 $sql =
"SELECT value";
1655 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1656 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1658 $result = $this->
db->query($sql);
1661 $obj = $this->
db->fetch_object($result);
1682 dol_syslog(get_class($this).
'::createCPusers');
1683 $arrayofusers = $this->
fetchUsers(
false,
true);
1685 foreach ($arrayofusers as $users) {
1686 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1687 $sql .=
" (fk_user, nb_holiday)";
1688 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1696 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1697 $sql .=
" (fk_user, nb_holiday)";
1698 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1716 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday_users";
1717 $sql .=
" WHERE fk_user = ".((int) $user_id);
1719 $this->
db->query($sql);
1732 $sql =
"SELECT nb_holiday";
1733 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1734 $sql .=
" WHERE fk_user = ".(int) $user_id;
1736 $sql .=
" AND fk_type = ".(int) $fk_type;
1739 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1740 $result = $this->
db->query($sql);
1742 $obj = $this->
db->fetch_object($result);
1745 return $obj->nb_holiday;
1762 public function fetchUsers($stringlist =
true, $type =
true, $filters =
'')
1766 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1772 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1773 $sql .=
" DISTINCT";
1776 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1778 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1779 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1780 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1781 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1782 $sql .=
" OR u.entity = 0)";
1784 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1786 $sql .=
" AND u.statut > 0";
1787 $sql .=
" AND u.employee = 1";
1797 $num = $this->
db->num_rows(
$resql);
1802 $obj = $this->
db->fetch_object(
$resql);
1805 $stringlist .= $obj->rowid;
1807 $stringlist .=
', '.$obj->rowid;
1816 $this->error =
"Error ".$this->db->lasterror();
1821 $sql =
"SELECT DISTINCT cpu.fk_user";
1822 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1823 $sql .=
" WHERE cpu.fk_user = u.rowid";
1833 $num = $this->
db->num_rows(
$resql);
1838 $obj = $this->
db->fetch_object(
$resql);
1841 $stringlist .= $obj->fk_user;
1843 $stringlist .=
', '.$obj->fk_user;
1852 $this->error =
"Error ".$this->db->lasterror();
1862 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1863 $sql .=
" DISTINCT";
1865 $sql .=
" u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1866 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1868 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1869 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1870 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1871 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1872 $sql .=
" OR u.entity = 0)";
1874 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1877 $sql .=
" AND u.statut > 0";
1878 $sql .=
" AND u.employee = 1";
1888 $tab_result = $this->holiday;
1889 $num = $this->
db->num_rows(
$resql);
1893 $obj = $this->
db->fetch_object(
$resql);
1895 $tab_result[$i][
'rowid'] = $obj->rowid;
1896 $tab_result[$i][
'id'] = $obj->rowid;
1897 $tab_result[$i][
'name'] = $obj->lastname;
1898 $tab_result[$i][
'lastname'] = $obj->lastname;
1899 $tab_result[$i][
'firstname'] = $obj->firstname;
1900 $tab_result[$i][
'gender'] = $obj->gender;
1901 $tab_result[$i][
'status'] = $obj->statut;
1902 $tab_result[$i][
'employee'] = $obj->employee;
1903 $tab_result[$i][
'photo'] = $obj->photo;
1904 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1914 $this->errors[] =
"Error ".$this->db->lasterror();
1919 $sql =
"SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1920 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1921 $sql .=
" WHERE cpu.fk_user = u.rowid";
1931 $tab_result = $this->holiday;
1932 $num = $this->
db->num_rows(
$resql);
1936 $obj = $this->
db->fetch_object(
$resql);
1938 $tab_result[$i][
'rowid'] = $obj->rowid;
1939 $tab_result[$i][
'id'] = $obj->rowid;
1940 $tab_result[$i][
'name'] = $obj->lastname;
1941 $tab_result[$i][
'lastname'] = $obj->lastname;
1942 $tab_result[$i][
'firstname'] = $obj->firstname;
1943 $tab_result[$i][
'gender'] = $obj->gender;
1944 $tab_result[$i][
'status'] = $obj->statut;
1945 $tab_result[$i][
'employee'] = $obj->employee;
1946 $tab_result[$i][
'photo'] = $obj->photo;
1947 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1949 $tab_result[$i][
'type'] = $obj->fk_type;
1950 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
1958 $this->error =
"Error ".$this->db->lasterror();
1976 $users_validator = array();
1978 $sql =
"SELECT DISTINCT ur.fk_user";
1979 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
1980 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
1982 $sql .=
" SELECT DISTINCT ugu.fk_user";
1983 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
1984 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
1987 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
1988 $result = $this->
db->query($sql);
1990 $num_rows = $this->
db->num_rows($result); $i = 0;
1991 while ($i < $num_rows) {
1992 $objp = $this->
db->fetch_object($result);
1993 array_push($users_validator, $objp->fk_user);
1996 return $users_validator;
1998 $this->error = $this->
db->lasterror();
1999 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2012 $sql =
"SELECT count(u.rowid) as compteur";
2013 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2014 $sql .=
" WHERE u.statut > 0";
2016 $result = $this->
db->query($sql);
2017 $objet = $this->
db->fetch_object($result);
2019 return $objet->compteur;
2029 $sql =
"SELECT count(u.rowid) as compteur";
2030 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
2031 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
2033 $result = $this->
db->query($sql);
2034 $objet = $this->
db->fetch_object($result);
2036 return $objet->compteur;
2048 if (empty($userCP)) {
2051 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2066 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2068 global $conf, $langs;
2076 if ($prev_solde == $new_solde) {
2083 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2084 $sql .=
"date_action,";
2085 $sql .=
"fk_user_action,";
2086 $sql .=
"fk_user_update,";
2087 $sql .=
"type_action,";
2088 $sql .=
"prev_solde,";
2089 $sql .=
"new_solde,";
2091 $sql .=
") VALUES (";
2092 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2093 $sql .=
" ".((int) $fk_user_action).
",";
2094 $sql .=
" ".((int) $fk_user_update).
",";
2095 $sql .=
" '".$this->db->escape($label).
"',";
2096 $sql .=
" ".((float) $prev_solde).
",";
2097 $sql .=
" ".((float) $new_solde).
",";
2098 $sql .=
" ".((int) $fk_type);
2103 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
2107 $this->optRowid = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2112 foreach ($this->errors as $errmsg) {
2113 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2114 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2116 $this->
db->rollback();
2119 $this->
db->commit();
2120 return $this->optRowid;
2134 $sql .=
" cpl.rowid,";
2135 $sql .=
" cpl.date_action,";
2136 $sql .=
" cpl.fk_user_action,";
2137 $sql .=
" cpl.fk_user_update,";
2138 $sql .=
" cpl.type_action,";
2139 $sql .=
" cpl.prev_solde,";
2140 $sql .=
" cpl.new_solde,";
2141 $sql .=
" cpl.fk_type";
2142 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2143 $sql .=
" WHERE cpl.rowid > 0";
2146 if (!empty($filter)) {
2147 $sql .=
" ".$filter;
2151 if (!empty($order)) {
2155 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2161 $tab_result = $this->logs;
2162 $num = $this->
db->num_rows(
$resql);
2171 $obj = $this->
db->fetch_object(
$resql);
2173 $tab_result[$i][
'rowid'] = $obj->rowid;
2174 $tab_result[$i][
'id'] = $obj->rowid;
2175 $tab_result[$i][
'date_action'] = $obj->date_action;
2176 $tab_result[$i][
'fk_user_action'] = $obj->fk_user_action;
2177 $tab_result[$i][
'fk_user_update'] = $obj->fk_user_update;
2178 $tab_result[$i][
'type_action'] = $obj->type_action;
2179 $tab_result[$i][
'prev_solde'] = $obj->prev_solde;
2180 $tab_result[$i][
'new_solde'] = $obj->new_solde;
2181 $tab_result[$i][
'fk_type'] = $obj->fk_type;
2186 $this->logs = $tab_result;
2190 $this->error =
"Error ".$this->db->lasterror();
2207 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2208 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2209 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).
')';
2211 $sql .=
" AND active = ".((int) $active);
2214 $sql .=
" AND affect = ".((int) $affect);
2216 $sql .=
" ORDER BY sortorder";
2218 $result = $this->
db->query($sql);
2220 $num = $this->
db->num_rows($result);
2222 while ($obj = $this->
db->fetch_object($result)) {
2223 $types[$obj->rowid] = array(
'id'=> $obj->rowid,
'rowid'=> $obj->rowid,
'code'=> $obj->code,
'label'=>$obj->label,
'affect'=>$obj->affect,
'delay'=>$obj->delay,
'newbymonth'=>$obj->newbymonth);
2246 $sql =
"SELECT f.rowid, f.statut as status,";
2247 $sql .=
" f.date_create as datec,";
2248 $sql .=
" f.tms as date_modification,";
2249 $sql .=
" f.date_valid as datev,";
2250 $sql .=
" f.date_approval as datea,";
2251 $sql .=
" f.date_refuse as dater,";
2252 $sql .=
" f.fk_user_create as fk_user_creation,";
2253 $sql .=
" f.fk_user_modif as fk_user_modification,";
2254 $sql .=
" f.fk_user_valid as fk_user_validation,";
2255 $sql .=
" f.fk_user_approve as fk_user_approval_done,";
2256 $sql .=
" f.fk_validator as fk_user_approval_expected,";
2257 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2259 $sql .=
" WHERE f.rowid = ".((int) $id);
2260 $sql .=
" AND f.entity = ".$conf->entity;
2265 $obj = $this->
db->fetch_object(
$resql);
2267 $this->
id = $obj->rowid;
2269 $this->date_creation = $this->
db->jdate($obj->datec);
2270 $this->date_modification = $this->
db->jdate($obj->date_modification);
2271 $this->date_validation = $this->
db->jdate($obj->datev);
2272 $this->date_approval = $this->
db->jdate($obj->datea);
2274 if (!empty($obj->fk_user_creation)) {
2275 $cuser =
new User($this->
db);
2276 $cuser->fetch($obj->fk_user_creation);
2277 $this->user_creation = $cuser;
2279 if (!empty($obj->fk_user_valid)) {
2280 $vuser =
new User($this->
db);
2281 $vuser->fetch($obj->fk_user_valid);
2282 $this->user_validation = $vuser;
2284 if (!empty($obj->fk_user_modification)) {
2285 $muser =
new User($this->
db);
2286 $muser->fetch($obj->fk_user_modification);
2287 $this->user_modification = $muser;
2291 if ($obj->fk_user_approval_done) {
2292 $auser =
new User($this->
db);
2293 $auser->fetch($obj->fk_user_approval_done);
2294 $this->user_approve = $auser;
2314 global $user, $langs;
2318 $this->specimen = 1;
2320 $this->fk_user = $user->id;
2322 $this->date_debut =
dol_now();
2323 $this->date_fin =
dol_now() + (24 * 3600);
2324 $this->date_valid =
dol_now();
2325 $this->fk_validator = $user->id;
2342 $this->nb = array();
2344 $sql =
"SELECT count(h.rowid) as nb";
2345 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2346 $sql .=
" WHERE h.statut > 1";
2347 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2348 if (empty($user->rights->expensereport->readall)) {
2349 $userchildids = $user->getAllChildIds(1);
2350 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(join(
',', $userchildids)).
")";
2351 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(join(
',', $userchildids)).
"))";
2356 while ($obj = $this->
db->fetch_object(
$resql)) {
2357 $this->nb[
"holidays"] = $obj->nb;
2363 $this->error = $this->
db->error();
2378 global $conf, $langs;
2386 $sql =
"SELECT h.rowid, h.date_debut";
2387 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2388 $sql .=
" WHERE h.statut = 2";
2389 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2390 if (empty($user->rights->expensereport->read_all)) {
2391 $userchildids = $user->getAllChildIds(1);
2392 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(join(
',', $userchildids)).
")";
2393 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(join(
',', $userchildids)).
"))";
2398 $langs->load(
"members");
2401 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2402 $response->label = $langs->trans(
"HolidaysToApprove");
2403 $response->labelShort = $langs->trans(
"ToApprove");
2404 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2407 while ($obj = $this->
db->fetch_object(
$resql)) {
2408 $response->nbtodo++;
2410 if ($this->
db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2411 $response->nbtodolate++;
2418 $this->error = $this->
db->error();
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class of the module paid holiday.
getTypes($active=-1, $affect=-1)
Return array with list of types.
getCheckOption($name)
Retourne un checked si vrai.
verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday=0)
Check if a user is on holiday (partially or completely) into a period.
validate($user=null, $notrigger=0)
Validate leave request.
info($id)
Load information on object.
updateBalance()
Update balance of vacations and check table of users for holidays is complete.
updateConfCP($name, $value)
Met à jour une option du module Holiday Payés.
const STATUS_VALIDATED
Validated status.
load_state_board()
Load this->nb for dashboard.
const STATUS_DRAFT
Draft status.
createCPusers($single=false, $userid='')
Créer les entrées pour chaque utilisateur au moment de la configuration.
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 le nombre d'utilisateur actif de Dolibarr à celui des utilisateurs des congés payés.
verifDateHolidayForTimestamp($fk_user, $timestamp, $status='-1')
Check that a user is not on holiday for a particular timestamp.
updateSoldeCP($userID='', $nbHoliday='', $fk_type='')
Met à jour le timestamp de la dernière mise à jour du solde des CP.
approve($user=null, $notrigger=0)
Approve leave request.
getNextNumRef($objsoc)
Returns the reference to the following non used Order depending on the active numbering module define...
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)
getNomUrl($withpicto=0, $save_lastsearch_value=-1, $notooltip=0)
Return clicable name (with picto eventually)
initAsSpecimen()
Initialise an instance with random values.
selectStatutCP($selected='', $htmlname='select_statut', $morecss='minwidth125')
Affiche un select HTML des statuts de congés payés.
create($user, $notrigger=0)
Créer un congés payés dans la base de données.
countActiveUsersWithoutCP()
Compte le nombre d'utilisateur actifs dans Dolibarr sans CP.
fetchLog($order, $filter)
Liste le log des congés payés.
update($user=null, $notrigger=0)
Update database.
getCPforUser($user_id, $fk_type=0)
Return balance of holiday for one user.
fetch_users_approver_holiday()
Return list of people with permission to validate leave requests.
__construct($db)
Constructor.
getLibStatut($mode=0)
Returns the label status.
deleteCPuser($user_id)
Supprime un utilisateur du module Congés Payés.
fetchAll($order, $filter)
List all holidays of all users.
const STATUS_CANCELED
Canceled.
countActiveUsers()
Compte le nombre d'utilisateur actifs dans Dolibarr.
fetchByUser($user_id, $order='', $filter='')
List holidays for a particular user or list of users.
const STATUS_APPROVED
Approved.
fetchUsers($stringlist=true, $type=true, $filters='')
Get list of Users or list of vacation balance.
LibStatut($status, $mode=0, $startdate='')
Returns the label of a status.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_dir_list($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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
div float
Buy price without taxes.
$conf db
API class for accounts.