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';
73 public $date_create =
'';
80 public $date_debut =
'';
81 public $date_fin =
'';
82 public $date_debut_gmt =
'';
83 public $date_fin_gmt =
'';
95 public $date_valid =
'';
100 public $fk_user_valid;
105 public $date_approbation;
110 public $date_refuse =
'';
115 public $fk_user_refuse;
120 public $date_cancel =
'';
125 public $fk_user_cancel;
128 public $detail_refuse =
'';
135 public $holiday = array();
136 public $events = array();
137 public $logs = array();
139 public $optName =
'';
140 public $optValue =
'';
141 public $optRowid =
'';
185 global $langs, $conf;
186 $langs->load(
"order");
188 if (empty($conf->global->HOLIDAY_ADDON)) {
189 $conf->global->HOLIDAY_ADDON =
'mod_holiday_madonna';
192 if (!empty($conf->global->HOLIDAY_ADDON)) {
195 $file = $conf->global->HOLIDAY_ADDON.
".php";
196 $classname = $conf->global->HOLIDAY_ADDON;
199 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
200 foreach ($dirmodels as $reldir) {
204 $mybool |= @include_once $dir.$file;
207 if ($mybool ===
false) {
212 $obj =
new $classname();
213 $numref = $obj->getNextValue($objsoc, $this);
218 $this->error = $obj->error;
223 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_HOLIDAY_ADDON_NotDefined");
247 $this->
db->rollback();
259 public function create($user, $notrigger = 0)
267 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
268 $this->error =
"ErrorBadParameterFkUser";
return -1;
270 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
271 $this->error =
"ErrorBadParameterFkValidator";
return -1;
273 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
274 $this->error =
"ErrorBadParameterFkType";
return -1;
278 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday(";
281 $sql .=
"date_create,";
282 $sql .=
"description,";
283 $sql .=
"date_debut,";
287 $sql .=
"fk_validator,";
289 $sql .=
"fk_user_create,";
291 $sql .=
") VALUES (";
293 $sql .=
" ".((int) $this->fk_user).
",";
294 $sql .=
" '".$this->db->idate($now).
"',";
295 $sql .=
" '".$this->db->escape($this->
description).
"',";
296 $sql .=
" '".$this->db->idate($this->date_debut).
"',";
297 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
298 $sql .=
" ".((int) $this->halfday).
",";
300 $sql .=
" ".((int) $this->fk_validator).
",";
301 $sql .=
" ".((int) $this->fk_type).
",";
302 $sql .=
" ".((int) $user->id).
",";
303 $sql .=
" ".((int) $conf->entity);
308 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
311 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
315 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"holiday");
319 $initialref =
'(PROV'.$this->id.
')';
320 if (!empty($this->
ref)) {
321 $initialref = $this->ref;
324 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"holiday SET ref='".$this->
db->escape($initialref).
"' WHERE rowid=".((int) $this->
id);
325 if ($this->
db->query($sql)) {
326 $this->
ref = $initialref;
335 if (!$error && !$notrigger) {
349 foreach ($this->errors as $errmsg) {
350 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
351 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
353 $this->
db->rollback();
369 public function fetch($id, $ref =
'')
374 $sql .=
" cp.rowid,";
376 $sql .=
" cp.fk_user,";
377 $sql .=
" cp.date_create,";
378 $sql .=
" cp.description,";
379 $sql .=
" cp.date_debut,";
380 $sql .=
" cp.date_fin,";
381 $sql .=
" cp.halfday,";
382 $sql .=
" cp.statut,";
383 $sql .=
" cp.fk_validator,";
384 $sql .=
" cp.date_valid,";
385 $sql .=
" cp.fk_user_valid,";
386 $sql .=
" cp.date_refuse,";
387 $sql .=
" cp.fk_user_refuse,";
388 $sql .=
" cp.date_cancel,";
389 $sql .=
" cp.fk_user_cancel,";
390 $sql .=
" cp.detail_refuse,";
391 $sql .=
" cp.note_private,";
392 $sql .=
" cp.note_public,";
393 $sql .=
" cp.fk_user_create,";
394 $sql .=
" cp.fk_type,";
395 $sql .=
" cp.entity";
396 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
398 $sql .=
" WHERE cp.rowid = ".((int) $id);
400 $sql .=
" WHERE cp.ref = '".$this->db->escape($ref).
"'";
403 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
407 $obj = $this->
db->fetch_object(
$resql);
409 $this->
id = $obj->rowid;
410 $this->
ref = ($obj->ref ? $obj->ref : $obj->rowid);
411 $this->fk_user = $obj->fk_user;
412 $this->date_create = $this->
db->jdate($obj->date_create);
414 $this->date_debut = $this->
db->jdate($obj->date_debut);
415 $this->date_fin = $this->
db->jdate($obj->date_fin);
416 $this->date_debut_gmt = $this->
db->jdate($obj->date_debut, 1);
417 $this->date_fin_gmt = $this->
db->jdate($obj->date_fin, 1);
418 $this->halfday = $obj->halfday;
419 $this->statut = $obj->statut;
420 $this->fk_validator = $obj->fk_validator;
421 $this->date_valid = $this->
db->jdate($obj->date_valid);
422 $this->fk_user_valid = $obj->fk_user_valid;
423 $this->date_refuse = $this->
db->jdate($obj->date_refuse);
424 $this->fk_user_refuse = $obj->fk_user_refuse;
425 $this->date_cancel = $this->
db->jdate($obj->date_cancel);
426 $this->fk_user_cancel = $obj->fk_user_cancel;
427 $this->detail_refuse = $obj->detail_refuse;
428 $this->note_private = $obj->note_private;
429 $this->note_public = $obj->note_public;
430 $this->fk_user_create = $obj->fk_user_create;
431 $this->fk_type = $obj->fk_type;
432 $this->entity = $obj->entity;
444 $this->error =
"Error ".$this->db->lasterror();
459 global $langs, $conf;
462 $sql .=
" cp.rowid,";
465 $sql .=
" cp.fk_user,";
466 $sql .=
" cp.fk_type,";
467 $sql .=
" cp.date_create,";
468 $sql .=
" cp.description,";
469 $sql .=
" cp.date_debut,";
470 $sql .=
" cp.date_fin,";
471 $sql .=
" cp.halfday,";
472 $sql .=
" cp.statut,";
473 $sql .=
" cp.fk_validator,";
474 $sql .=
" cp.date_valid,";
475 $sql .=
" cp.fk_user_valid,";
476 $sql .=
" cp.date_refuse,";
477 $sql .=
" cp.fk_user_refuse,";
478 $sql .=
" cp.date_cancel,";
479 $sql .=
" cp.fk_user_cancel,";
480 $sql .=
" cp.detail_refuse,";
482 $sql .=
" uu.lastname as user_lastname,";
483 $sql .=
" uu.firstname as user_firstname,";
484 $sql .=
" uu.login as user_login,";
485 $sql .=
" uu.statut as user_statut,";
486 $sql .=
" uu.photo as user_photo,";
488 $sql .=
" ua.lastname as validator_lastname,";
489 $sql .=
" ua.firstname as validator_firstname,";
490 $sql .=
" ua.login as validator_login,";
491 $sql .=
" ua.statut as validator_statut,";
492 $sql .=
" ua.photo as validator_photo";
494 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
495 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
496 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
497 $sql .=
" AND cp.fk_user IN (".$this->db->sanitize($user_id).
")";
500 if (!empty($filter)) {
505 if (!empty($order)) {
509 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
515 $tab_result = $this->holiday;
525 $obj = $this->
db->fetch_object(
$resql);
527 $tab_result[$i][
'rowid'] = $obj->rowid;
528 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
530 $tab_result[$i][
'fk_user'] = $obj->fk_user;
531 $tab_result[$i][
'fk_type'] = $obj->fk_type;
532 $tab_result[$i][
'date_create'] = $this->
db->jdate($obj->date_create);
533 $tab_result[$i][
'description'] = $obj->description;
534 $tab_result[$i][
'date_debut'] = $this->
db->jdate($obj->date_debut);
535 $tab_result[$i][
'date_fin'] = $this->
db->jdate($obj->date_fin);
536 $tab_result[$i][
'date_debut_gmt'] = $this->
db->jdate($obj->date_debut, 1);
537 $tab_result[$i][
'date_fin_gmt'] = $this->
db->jdate($obj->date_fin, 1);
538 $tab_result[$i][
'halfday'] = $obj->halfday;
539 $tab_result[$i][
'statut'] = $obj->statut;
540 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
541 $tab_result[$i][
'date_valid'] = $this->
db->jdate($obj->date_valid);
542 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
543 $tab_result[$i][
'date_refuse'] = $this->
db->jdate($obj->date_refuse);
544 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
545 $tab_result[$i][
'date_cancel'] = $this->
db->jdate($obj->date_cancel);
546 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
547 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
549 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
550 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
551 $tab_result[$i][
'user_login'] = $obj->user_login;
552 $tab_result[$i][
'user_statut'] = $obj->user_statut;
553 $tab_result[$i][
'user_photo'] = $obj->user_photo;
555 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
556 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
557 $tab_result[$i][
'validator_login'] = $obj->validator_login;
558 $tab_result[$i][
'validator_statut'] = $obj->validator_statut;
559 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
565 $this->holiday = $tab_result;
569 $this->error =
"Error ".$this->db->lasterror();
586 $sql .=
" cp.rowid,";
589 $sql .=
" cp.fk_user,";
590 $sql .=
" cp.fk_type,";
591 $sql .=
" cp.date_create,";
592 $sql .=
" cp.tms as date_update,";
593 $sql .=
" cp.description,";
594 $sql .=
" cp.date_debut,";
595 $sql .=
" cp.date_fin,";
596 $sql .=
" cp.halfday,";
597 $sql .=
" cp.statut,";
598 $sql .=
" cp.fk_validator,";
599 $sql .=
" cp.date_valid,";
600 $sql .=
" cp.fk_user_valid,";
601 $sql .=
" cp.date_refuse,";
602 $sql .=
" cp.fk_user_refuse,";
603 $sql .=
" cp.date_cancel,";
604 $sql .=
" cp.fk_user_cancel,";
605 $sql .=
" cp.detail_refuse,";
607 $sql .=
" uu.lastname as user_lastname,";
608 $sql .=
" uu.firstname as user_firstname,";
609 $sql .=
" uu.login as user_login,";
610 $sql .=
" uu.statut as user_statut,";
611 $sql .=
" uu.photo as user_photo,";
613 $sql .=
" ua.lastname as validator_lastname,";
614 $sql .=
" ua.firstname as validator_firstname,";
615 $sql .=
" ua.login as validator_login,";
616 $sql .=
" ua.statut as validator_statut,";
617 $sql .=
" ua.photo as validator_photo";
619 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
620 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
621 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
624 if (!empty($filter)) {
629 if (!empty($order)) {
633 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
639 $tab_result = $this->holiday;
649 $obj = $this->
db->fetch_object(
$resql);
651 $tab_result[$i][
'rowid'] = $obj->rowid;
652 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
653 $tab_result[$i][
'fk_user'] = $obj->fk_user;
654 $tab_result[$i][
'fk_type'] = $obj->fk_type;
655 $tab_result[$i][
'date_create'] = $this->
db->jdate($obj->date_create);
656 $tab_result[$i][
'date_update'] = $this->
db->jdate($obj->date_update);
657 $tab_result[$i][
'description'] = $obj->description;
658 $tab_result[$i][
'date_debut'] = $this->
db->jdate($obj->date_debut);
659 $tab_result[$i][
'date_fin'] = $this->
db->jdate($obj->date_fin);
660 $tab_result[$i][
'date_debut_gmt'] = $this->
db->jdate($obj->date_debut, 1);
661 $tab_result[$i][
'date_fin_gmt'] = $this->
db->jdate($obj->date_fin, 1);
662 $tab_result[$i][
'halfday'] = $obj->halfday;
663 $tab_result[$i][
'statut'] = $obj->statut;
664 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
665 $tab_result[$i][
'date_valid'] = $this->
db->jdate($obj->date_valid);
666 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
667 $tab_result[$i][
'date_refuse'] = $obj->date_refuse;
668 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
669 $tab_result[$i][
'date_cancel'] = $obj->date_cancel;
670 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
671 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
673 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
674 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
675 $tab_result[$i][
'user_login'] = $obj->user_login;
676 $tab_result[$i][
'user_statut'] = $obj->user_statut;
677 $tab_result[$i][
'user_photo'] = $obj->user_photo;
679 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
680 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
681 $tab_result[$i][
'validator_login'] = $obj->validator_login;
682 $tab_result[$i][
'validator_statut'] = $obj->validator_statut;
683 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
688 $this->holiday = $tab_result;
692 $this->error =
"Error ".$this->db->lasterror();
705 public function validate($user = null, $notrigger = 0)
707 global $conf, $langs;
708 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
711 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type);
713 if ($checkBalance > 0) {
714 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
717 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
723 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref) || $this->
ref == $this->
id)) {
731 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
732 if (!empty($this->statut) && is_numeric($this->statut)) {
733 $sql .=
" statut = ".((int) $this->statut).
",";
737 $sql .=
" ref = '".$this->db->escape($num).
"'";
738 $sql .=
" WHERE rowid = ".((int) $this->
id);
742 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
745 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
751 $result = $this->
call_trigger(
'HOLIDAY_VALIDATE', $user);
760 $this->oldref = $this->ref;
763 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
765 $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) .
"'";
766 $sql .=
" WHERE filename LIKE '" . $this->
db->escape($this->
ref) .
"%' AND filepath = 'holiday/" . $this->
db->escape($this->
ref) .
"' and entity = " . ((int) $conf->entity);
770 $this->error = $this->
db->lasterror();
776 $dirsource = $conf->holiday->multidir_output[$this->entity] .
'/' . $oldref;
777 $dirdest = $conf->holiday->multidir_output[$this->entity] .
'/' . $newref;
778 if (!$error && file_exists($dirsource)) {
779 dol_syslog(get_class($this) .
"::validate rename dir " . $dirsource .
" into " . $dirdest);
780 if (@rename($dirsource, $dirdest)) {
783 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^' . preg_quote($oldref,
'/'));
784 foreach ($listoffiles as $fileentry) {
785 $dirsource = $fileentry[
'name'];
786 $dirdest = preg_replace(
'/^' . preg_quote($oldref,
'/') .
'/', $newref, $dirsource);
787 $dirsource = $fileentry[
'path'] .
'/' . $dirsource;
788 $dirdest = $fileentry[
'path'] .
'/' . $dirdest;
789 @rename($dirsource, $dirdest);
799 foreach ($this->errors as $errmsg) {
800 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
801 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
803 $this->
db->rollback();
819 public function approve($user = null, $notrigger = 0)
821 global $conf, $langs;
824 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type);
826 if ($checkBalance > 0) {
827 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
830 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
836 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
838 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
840 if (!empty($this->date_debut)) {
841 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
845 if (!empty($this->date_fin)) {
846 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
850 $sql .=
" halfday = ".((int) $this->halfday).
",";
851 if (!empty($this->statut) && is_numeric($this->statut)) {
852 $sql .=
" statut = ".((int) $this->statut).
",";
856 if (!empty($this->fk_validator)) {
857 $sql .=
" fk_validator = '".$this->db->escape($this->fk_validator).
"',";
861 if (!empty($this->date_valid)) {
862 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
864 $sql .=
" date_valid = NULL,";
866 if (!empty($this->fk_user_valid)) {
867 $sql .=
" fk_user_valid = '".$this->db->escape($this->fk_user_valid).
"',";
869 $sql .=
" fk_user_valid = NULL,";
871 if (!empty($this->date_refuse)) {
872 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
874 $sql .=
" date_refuse = NULL,";
876 if (!empty($this->fk_user_refuse)) {
877 $sql .=
" fk_user_refuse = '".$this->db->escape($this->fk_user_refuse).
"',";
879 $sql .=
" fk_user_refuse = NULL,";
881 if (!empty($this->date_cancel)) {
882 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
884 $sql .=
" date_cancel = NULL,";
886 if (!empty($this->fk_user_cancel)) {
887 $sql .=
" fk_user_cancel = '".$this->db->escape($this->fk_user_cancel).
"',";
889 $sql .=
" fk_user_cancel = NULL,";
891 if (!empty($this->detail_refuse)) {
892 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
894 $sql .=
" detail_refuse = NULL";
896 $sql .=
" WHERE rowid = ".((int) $this->
id);
900 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
903 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
909 $result = $this->
call_trigger(
'HOLIDAY_APPROVE', $user);
919 foreach ($this->errors as $errmsg) {
920 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
921 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
923 $this->
db->rollback();
938 public function update($user = null, $notrigger = 0)
940 global $conf, $langs;
943 $checkBalance =
getDictionaryValue(
'c_holiday_types',
'block_if_negative', $this->fk_type);
945 if ($checkBalance > 0 && $this->statut != self::STATUS_DRAFT) {
946 $balance = $this->
getCPforUser($this->fk_user, $this->fk_type);
949 $this->error =
'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
955 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
957 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
959 if (!empty($this->date_debut)) {
960 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
964 if (!empty($this->date_fin)) {
965 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
969 $sql .=
" halfday = ".$this->halfday.
",";
970 if (!empty($this->statut) && is_numeric($this->statut)) {
971 $sql .=
" statut = ".$this->statut.
",";
975 if (!empty($this->fk_validator)) {
976 $sql .=
" fk_validator = '".$this->db->escape($this->fk_validator).
"',";
980 if (!empty($this->date_valid)) {
981 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
983 $sql .=
" date_valid = NULL,";
985 if (!empty($this->fk_user_valid)) {
986 $sql .=
" fk_user_valid = '".$this->db->escape($this->fk_user_valid).
"',";
988 $sql .=
" fk_user_valid = NULL,";
990 if (!empty($this->date_refuse)) {
991 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
993 $sql .=
" date_refuse = NULL,";
995 if (!empty($this->fk_user_refuse)) {
996 $sql .=
" fk_user_refuse = '".$this->db->escape($this->fk_user_refuse).
"',";
998 $sql .=
" fk_user_refuse = NULL,";
1000 if (!empty($this->date_cancel)) {
1001 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
1003 $sql .=
" date_cancel = NULL,";
1005 if (!empty($this->fk_user_cancel)) {
1006 $sql .=
" fk_user_cancel = '".$this->db->escape($this->fk_user_cancel).
"',";
1008 $sql .=
" fk_user_cancel = NULL,";
1010 if (!empty($this->detail_refuse)) {
1011 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
1013 $sql .=
" detail_refuse = NULL";
1016 $sql .=
" WHERE rowid = ".((int) $this->
id);
1020 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1023 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1029 $result = $this->
call_trigger(
'HOLIDAY_MODIFY', $user);
1039 foreach ($this->errors as $errmsg) {
1040 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1041 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1043 $this->
db->rollback();
1046 $this->
db->commit();
1059 public function delete($user, $notrigger = 0)
1061 global $conf, $langs;
1064 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
1065 $sql .=
" WHERE rowid=".((int) $this->
id);
1069 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1072 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1078 $result = $this->
call_trigger(
'HOLIDAY_DELETE', $user);
1088 foreach ($this->errors as $errmsg) {
1089 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1090 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1092 $this->
db->rollback();
1095 $this->
db->commit();
1117 foreach ($this->holiday as $infos_CP) {
1118 if ($infos_CP[
'statut'] == 4) {
1121 if ($infos_CP[
'statut'] == 5) {
1128 if ($halfday == 0) {
1129 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1132 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1135 } elseif ($halfday == -1) {
1137 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1138 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1142 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1143 if ($dateStart < $dateEnd) {
1146 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1150 } elseif ($halfday == 1) {
1152 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1153 if ($dateStart < $dateEnd) {
1156 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1160 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1161 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1165 } elseif ($halfday == 2) {
1167 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin']) {
1168 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1))) {
1172 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut']) {
1173 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1))) {
1178 dol_print_error(
'',
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1197 global $langs, $conf;
1199 $isavailablemorning =
true;
1200 $isavailableafternoon =
true;
1203 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut";
1204 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1205 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1206 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1207 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->
db->idate($timestamp).
"'";
1208 if ($status !=
'-1') {
1209 $sql .=
" AND cp.statut IN (".$this->db->sanitize($status).
")";
1214 $num_rows = $this->
db->num_rows(
$resql);
1215 if ($num_rows > 0) {
1216 $arrayofrecord = array();
1218 while ($i < $num_rows) {
1219 $obj = $this->
db->fetch_object(
$resql);
1222 $arrayofrecord[$obj->rowid] = array(
'date_start'=>$this->
db->jdate($obj->date_start),
'date_end'=>$this->
db->jdate($obj->date_end),
'halfday'=>$obj->halfday);
1227 $isavailablemorning =
true;
1228 foreach ($arrayofrecord as $record) {
1229 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2) {
1232 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1) {
1235 $isavailablemorning =
false;
1238 $isavailableafternoon =
true;
1239 foreach ($arrayofrecord as $record) {
1240 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2) {
1243 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1) {
1246 $isavailableafternoon =
false;
1254 $result = array(
'morning'=>$isavailablemorning,
'afternoon'=>$isavailableafternoon);
1255 if (!$isavailablemorning) {
1256 $result[
'morning_reason'] =
'leave_request';
1258 if (!$isavailableafternoon) {
1259 $result[
'afternoon_reason'] =
'leave_request';
1273 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0)
1275 global $langs, $hookmanager;
1279 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1280 if (isset($this->statut)) {
1281 $label .=
' '.$this->getLibStatut(5);
1283 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1285 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1290 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1291 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1292 $add_save_lastsearch_values = 1;
1294 if ($add_save_lastsearch_values) {
1295 $url .=
'&save_lastsearch_values=1';
1299 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1302 $result .= $linkstart;
1304 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1306 if ($withpicto != 2) {
1307 $result .= $this->ref;
1309 $result .= $linkend;
1311 $hookmanager->initHooks(array($this->element .
'dao'));
1312 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1313 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1315 $result = $hookmanager->resPrint;
1317 $result .= $hookmanager->resPrint;
1331 return $this->
LibStatut($this->statut, $mode, $this->date_debut);
1343 public function LibStatut($status, $mode = 0, $startdate =
'')
1348 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1351 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1352 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'ToReviewCP');
1353 $this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv(
'ApprovedCP');
1354 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'CancelCP');
1355 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv(
'RefuseCP');
1356 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'DraftCP');
1357 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'ToReviewCP');
1358 $this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv(
'ApprovedCP');
1359 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'CancelCP');
1360 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv(
'RefuseCP');
1364 $statusType =
'status6';
1365 if (!empty($startdate) && $startdate >=
dol_now()) {
1366 $statusType =
'status4';
1367 $params = array(
'tooltip'=>$this->labelStatus[$status].
' - '.$langs->trans(
"Forthcoming"));
1369 if ($status == self::STATUS_DRAFT) {
1370 $statusType =
'status0';
1372 if ($status == self::STATUS_VALIDATED) {
1373 $statusType =
'status1';
1375 if ($status == self::STATUS_CANCELED) {
1376 $statusType =
'status5';
1378 if ($status == self::STATUS_REFUSED) {
1379 $statusType =
'status5';
1382 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode,
'', $params);
1394 public function selectStatutCP($selected =
'', $htmlname =
'select_statut', $morecss =
'minwidth125')
1399 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1400 $nb = count($name) + 1;
1403 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat'.($morecss ?
' '.$morecss :
'').
'">'.
"\n";
1404 $out .=
'<option value="-1"> </option>'.
"\n";
1407 for ($i = 1; $i < $nb; $i++) {
1408 if ($i == $selected) {
1409 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1411 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1415 $out .=
'</select>'.
"\n";
1431 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1432 $sql .=
" value = '".$this->db->escape($value).
"'";
1433 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1435 dol_syslog(get_class($this).
'::updateConfCP name='.$name.
'', LOG_DEBUG);
1436 $result = $this->
db->query($sql);
1454 $sql =
"SELECT value";
1455 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1456 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1458 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1459 $result = $this->
db->query($sql);
1462 $obj = $this->
db->fetch_object($result);
1465 if ($createifnotfound) {
1466 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1467 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->
db->escape($createifnotfound).
"')";
1468 $result = $this->
db->query($sql);
1470 return $createifnotfound;
1472 $this->error = $this->
db->lasterror();
1483 $this->error = $this->
db->lasterror();
1498 global $user, $langs;
1502 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1503 $langs->load(
"holiday");
1508 $month = date(
'm', $now);
1512 $lastUpdate = $this->
getConfCP(
'lastUpdate', $newdateforlastupdate);
1513 $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
1517 if ($month != $monthLastUpdate) {
1520 $users = $this->
fetchUsers(
false,
false,
' AND u.statut > 0');
1521 $nbUser = count($users);
1523 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1524 $sql .=
" value = '".$this->db->escape($newdateforlastupdate).
"'";
1525 $sql .=
" WHERE name = 'lastUpdate'";
1526 $result = $this->
db->query($sql);
1528 $typeleaves = $this->
getTypes(1, 1);
1531 foreach ($users as $userCounter) {
1532 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newbymonth']) ? $typeleaves[$userCounter[
'type']][
'newbymonth'] : 0);
1533 if (empty($nbDaysToAdd)) {
1537 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1539 $nowHoliday = $userCounter[
'nb_holiday'];
1540 $newSolde = $nowHoliday + $nbDaysToAdd;
1543 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidaysMonthlyUpdate'), $newSolde, $userCounter[
'type']);
1545 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type'], $langs->trans(
'HolidaysMonthlyUpdate'));
1554 $this->
db->commit();
1557 $this->
db->rollback();
1567 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1568 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1571 $num = $this->
db->num_rows(
$resql);
1575 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1576 $sql .=
" nb_holiday = ".((float) $nbHoliday);
1577 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1578 $result = $this->
db->query($sql);
1581 $this->errors[] = $this->
db->lasterror();
1585 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1586 $sql .= ((
float) $nbHoliday);
1587 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1588 $result = $this->
db->query($sql);
1591 $this->errors[] = $this->
db->lasterror();
1595 $this->errors[] = $this->
db->lasterror();
1616 $sql =
"SELECT value";
1617 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1618 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1620 $result = $this->
db->query($sql);
1623 $obj = $this->
db->fetch_object($result);
1644 dol_syslog(get_class($this).
'::createCPusers');
1645 $arrayofusers = $this->
fetchUsers(
false,
true);
1647 foreach ($arrayofusers as $users) {
1648 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1649 $sql .=
" (fk_user, nb_holiday)";
1650 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1658 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1659 $sql .=
" (fk_user, nb_holiday)";
1660 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1678 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday_users";
1679 $sql .=
" WHERE fk_user = ".((int) $user_id);
1681 $this->
db->query($sql);
1694 $sql =
"SELECT nb_holiday";
1695 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1696 $sql .=
" WHERE fk_user = ".(int) $user_id;
1698 $sql .=
" AND fk_type = ".(int) $fk_type;
1701 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1702 $result = $this->
db->query($sql);
1704 $obj = $this->
db->fetch_object($result);
1707 return $obj->nb_holiday;
1724 public function fetchUsers($stringlist =
true, $type =
true, $filters =
'')
1728 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1734 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1735 $sql .=
" DISTINCT";
1738 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1740 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1741 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1742 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1743 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1744 $sql .=
" OR u.entity = 0)";
1746 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1748 $sql .=
" AND u.statut > 0";
1749 $sql .=
" AND u.employee = 1";
1759 $num = $this->
db->num_rows(
$resql);
1764 $obj = $this->
db->fetch_object(
$resql);
1767 $stringlist .= $obj->rowid;
1769 $stringlist .=
', '.$obj->rowid;
1778 $this->error =
"Error ".$this->db->lasterror();
1783 $sql =
"SELECT DISTINCT cpu.fk_user";
1784 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1785 $sql .=
" WHERE cpu.fk_user = u.rowid";
1795 $num = $this->
db->num_rows(
$resql);
1800 $obj = $this->
db->fetch_object(
$resql);
1803 $stringlist .= $obj->fk_user;
1805 $stringlist .=
', '.$obj->fk_user;
1814 $this->error =
"Error ".$this->db->lasterror();
1824 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1825 $sql .=
" DISTINCT";
1827 $sql .=
" u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1828 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1830 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1831 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1832 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1833 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1834 $sql .=
" OR u.entity = 0)";
1836 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1839 $sql .=
" AND u.statut > 0";
1840 $sql .=
" AND u.employee = 1";
1850 $tab_result = $this->holiday;
1851 $num = $this->
db->num_rows(
$resql);
1855 $obj = $this->
db->fetch_object(
$resql);
1857 $tab_result[$i][
'rowid'] = $obj->rowid;
1858 $tab_result[$i][
'name'] = $obj->lastname;
1859 $tab_result[$i][
'lastname'] = $obj->lastname;
1860 $tab_result[$i][
'firstname'] = $obj->firstname;
1861 $tab_result[$i][
'gender'] = $obj->gender;
1862 $tab_result[$i][
'status'] = $obj->statut;
1863 $tab_result[$i][
'employee'] = $obj->employee;
1864 $tab_result[$i][
'photo'] = $obj->photo;
1865 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1875 $this->errors[] =
"Error ".$this->db->lasterror();
1880 $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";
1881 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1882 $sql .=
" WHERE cpu.fk_user = u.rowid";
1892 $tab_result = $this->holiday;
1893 $num = $this->
db->num_rows(
$resql);
1897 $obj = $this->
db->fetch_object(
$resql);
1899 $tab_result[$i][
'rowid'] = $obj->rowid;
1900 $tab_result[$i][
'name'] = $obj->lastname;
1901 $tab_result[$i][
'lastname'] = $obj->lastname;
1902 $tab_result[$i][
'firstname'] = $obj->firstname;
1903 $tab_result[$i][
'gender'] = $obj->gender;
1904 $tab_result[$i][
'status'] = $obj->statut;
1905 $tab_result[$i][
'employee'] = $obj->employee;
1906 $tab_result[$i][
'photo'] = $obj->photo;
1907 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1909 $tab_result[$i][
'type'] = $obj->fk_type;
1910 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
1918 $this->error =
"Error ".$this->db->lasterror();
1936 $users_validator = array();
1938 $sql =
"SELECT DISTINCT ur.fk_user";
1939 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
1940 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
1942 $sql .=
" SELECT DISTINCT ugu.fk_user";
1943 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
1944 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
1947 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
1948 $result = $this->
db->query($sql);
1950 $num_rows = $this->
db->num_rows($result); $i = 0;
1951 while ($i < $num_rows) {
1952 $objp = $this->
db->fetch_object($result);
1953 array_push($users_validator, $objp->fk_user);
1956 return $users_validator;
1958 $this->error = $this->
db->lasterror();
1959 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
1972 $sql =
"SELECT count(u.rowid) as compteur";
1973 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1974 $sql .=
" WHERE u.statut > 0";
1976 $result = $this->
db->query($sql);
1977 $objet = $this->
db->fetch_object($result);
1979 return $objet->compteur;
1989 $sql =
"SELECT count(u.rowid) as compteur";
1990 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
1991 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
1993 $result = $this->
db->query($sql);
1994 $objet = $this->
db->fetch_object($result);
1996 return $objet->compteur;
2008 if (empty($userCP)) {
2011 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
2026 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2028 global $conf, $langs;
2036 if ($prev_solde == $new_solde) {
2043 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
2044 $sql .=
"date_action,";
2045 $sql .=
"fk_user_action,";
2046 $sql .=
"fk_user_update,";
2047 $sql .=
"type_action,";
2048 $sql .=
"prev_solde,";
2049 $sql .=
"new_solde,";
2051 $sql .=
") VALUES (";
2052 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
2053 $sql .=
" ".((int) $fk_user_action).
",";
2054 $sql .=
" ".((int) $fk_user_update).
",";
2055 $sql .=
" '".$this->db->escape($label).
"',";
2056 $sql .=
" ".((float) $prev_solde).
",";
2057 $sql .=
" ".((float) $new_solde).
",";
2058 $sql .=
" ".((int) $fk_type);
2063 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
2067 $this->optRowid = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
2072 foreach ($this->errors as $errmsg) {
2073 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
2074 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2076 $this->
db->rollback();
2079 $this->
db->commit();
2080 return $this->optRowid;
2094 $sql .=
" cpl.rowid,";
2095 $sql .=
" cpl.date_action,";
2096 $sql .=
" cpl.fk_user_action,";
2097 $sql .=
" cpl.fk_user_update,";
2098 $sql .=
" cpl.type_action,";
2099 $sql .=
" cpl.prev_solde,";
2100 $sql .=
" cpl.new_solde,";
2101 $sql .=
" cpl.fk_type";
2102 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
2103 $sql .=
" WHERE cpl.rowid > 0";
2106 if (!empty($filter)) {
2107 $sql .=
" ".$filter;
2111 if (!empty($order)) {
2115 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2121 $tab_result = $this->logs;
2122 $num = $this->
db->num_rows(
$resql);
2131 $obj = $this->
db->fetch_object(
$resql);
2133 $tab_result[$i][
'rowid'] = $obj->rowid;
2134 $tab_result[$i][
'date_action'] = $obj->date_action;
2135 $tab_result[$i][
'fk_user_action'] = $obj->fk_user_action;
2136 $tab_result[$i][
'fk_user_update'] = $obj->fk_user_update;
2137 $tab_result[$i][
'type_action'] = $obj->type_action;
2138 $tab_result[$i][
'prev_solde'] = $obj->prev_solde;
2139 $tab_result[$i][
'new_solde'] = $obj->new_solde;
2140 $tab_result[$i][
'fk_type'] = $obj->fk_type;
2145 $this->logs = $tab_result;
2149 $this->error =
"Error ".$this->db->lasterror();
2166 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth";
2167 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2168 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).
')';
2170 $sql .=
" AND active = ".((int) $active);
2173 $sql .=
" AND affect = ".((int) $affect);
2175 $sql .=
" ORDER BY sortorder";
2177 $result = $this->
db->query($sql);
2179 $num = $this->
db->num_rows($result);
2181 while ($obj = $this->
db->fetch_object($result)) {
2182 $types[$obj->rowid] = array(
'rowid'=> $obj->rowid,
'code'=> $obj->code,
'label'=>$obj->label,
'affect'=>$obj->affect,
'delay'=>$obj->delay,
'newbymonth'=>$obj->newbymonth);
2205 $sql =
"SELECT f.rowid, f.statut as status,";
2206 $sql .=
" f.date_create as datec,";
2207 $sql .=
" f.tms as date_modification,";
2208 $sql .=
" f.date_valid as datev,";
2209 $sql .=
" f.date_approve as datea,";
2210 $sql .=
" f.date_refuse as dater,";
2211 $sql .=
" f.fk_user_create as fk_user_creation,";
2212 $sql .=
" f.fk_user_modif as fk_user_modification,";
2213 $sql .=
" f.fk_user_valid as fk_user_approve_done,";
2214 $sql .=
" f.fk_validator as fk_user_approve_expected,";
2215 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2216 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2217 $sql .=
" WHERE f.rowid = ".((int) $id);
2218 $sql .=
" AND f.entity = ".$conf->entity;
2223 $obj = $this->
db->fetch_object(
$resql);
2225 $this->
id = $obj->rowid;
2227 $this->date_creation = $this->
db->jdate($obj->datec);
2228 $this->date_modification = $this->
db->jdate($obj->date_modification);
2229 $this->date_validation = $this->
db->jdate($obj->datev);
2230 $this->date_approbation = $this->
db->jdate($obj->datea);
2232 if (!empty($obj->fk_user_creation)) {
2233 $cuser =
new User($this->
db);
2234 $cuser->fetch($obj->fk_user_creation);
2235 $this->user_creation = $cuser;
2237 if (!empty($obj->fk_user_approve_done)) {
2238 $vuser =
new User($this->
db);
2239 $vuser->fetch($obj->fk_user_approve_done);
2240 $this->user_validation = $vuser;
2242 if (!empty($obj->fk_user_modification)) {
2243 $muser =
new User($this->
db);
2244 $muser->fetch($obj->fk_user_modification);
2245 $this->user_modification = $muser;
2249 if ($obj->fk_user_approve_done) {
2250 $auser =
new User($this->
db);
2251 $auser->fetch($obj->fk_user_approve_done);
2252 $this->user_approve = $auser;
2255 if (!empty($obj->fk_user_approve_expected)) {
2256 $auser =
new User($this->
db);
2257 $auser->fetch($obj->fk_user_approve_expected);
2258 $this->user_approve = $auser;
2278 global $user, $langs;
2282 $this->specimen = 1;
2284 $this->fk_user = $user->id;
2286 $this->date_debut =
dol_now();
2287 $this->date_fin =
dol_now() + (24 * 3600);
2288 $this->date_valid =
dol_now();
2289 $this->fk_validator = $user->id;
2306 $this->nb = array();
2308 $sql =
"SELECT count(h.rowid) as nb";
2309 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2310 $sql .=
" WHERE h.statut > 1";
2311 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2312 if (empty($user->rights->expensereport->readall)) {
2313 $userchildids = $user->getAllChildIds(1);
2314 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(join(
',', $userchildids)).
")";
2315 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(join(
',', $userchildids)).
"))";
2320 while ($obj = $this->
db->fetch_object(
$resql)) {
2321 $this->nb[
"holidays"] = $obj->nb;
2327 $this->error = $this->
db->error();
2342 global $conf, $langs;
2350 $sql =
"SELECT h.rowid, h.date_debut";
2351 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2352 $sql .=
" WHERE h.statut = 2";
2353 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2354 if (empty($user->rights->expensereport->read_all)) {
2355 $userchildids = $user->getAllChildIds(1);
2356 $sql .=
" AND (h.fk_user IN (".$this->db->sanitize(join(
',', $userchildids)).
")";
2357 $sql .=
" OR h.fk_validator IN (".$this->db->sanitize(join(
',', $userchildids)).
"))";
2362 $langs->load(
"members");
2365 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2366 $response->label = $langs->trans(
"HolidaysToApprove");
2367 $response->labelShort = $langs->trans(
"ToApprove");
2368 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_status=2&mainmenu=hrm&leftmenu=holiday';
2371 while ($obj = $this->
db->fetch_object(
$resql)) {
2372 $response->nbtodo++;
2374 if ($this->
db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2375 $response->nbtodolate++;
2382 $this->error = $this->
db->error();
getNextNumRef($objsoc)
Returns the reference to the following non used Order depending on the active numbering module define...
validate($user=null, $notrigger=0)
Validate leave request.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield= 'rowid')
Return the value of a filed into a dictionary for the record $id.
Class of the module paid holiday.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getTypes($active=-1, $affect=-1)
Return array with list of types.
fetchUsers($stringlist=true, $type=true, $filters= '')
Get list of Users or list of vacation balance.
$conf db
API class for accounts.
getLibStatut($mode=0)
Returns the label status.
getCPforUser($user_id, $fk_type=0)
Return balance of holiday for one user.
dol_now($mode= 'auto')
Return date for now.
deleteCPuser($user_id)
Supprime un utilisateur du module Congés Payés.
Class to manage Dolibarr users.
updateConfCP($name, $value)
Met à jour une option du module Holiday Payés.
updateSoldeCP($userID= '', $nbHoliday= '', $fk_type= '')
Met à jour le timestamp de la dernière mise à jour du solde des CP.
getConfCP($name, $createifnotfound= '')
Return value of a conf parameter for leave module TODO Move this into llx_const table.
update($user=null, $notrigger=0)
Update database.
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...
updateBalance()
Update balance of vacations and check table of users for holidays is complete.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
initAsSpecimen()
Initialise an instance with random values.
fetch($id, $ref= '')
Load object in memory from database.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
fetchLog($order, $filter)
Liste le log des congés payés.
const STATUS_DRAFT
Draft status.
info($id)
Load information on object.
fetchByUser($user_id, $order= '', $filter= '')
List holidays for a particular user or list of users.
countActiveUsers()
Compte le nombre d'utilisateur actifs dans Dolibarr.
create($user, $notrigger=0)
Créer un congés payés dans la base de données.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
selectStatutCP($selected= '', $htmlname= 'select_statut', $morecss= 'minwidth125')
Affiche un select HTML des statuts de congés payés.
approve($user=null, $notrigger=0)
Approve leave request.
verifDateHolidayForTimestamp($fk_user, $timestamp, $status= '-1')
Check that a user is not on holiday for a particular timestamp.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
const STATUS_APPROVED
Approved.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday=0)
Check if a user is on holiday (partially or completely) into a period.
fetchAll($order, $filter)
List all holidays of all users.
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...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve', $idforemptyvalue= '-1')
Convert a html select field into an ajax combobox.
load_state_board()
Load this->nb for dashboard.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
addLogCP
div float
Buy price without taxes.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
getNomUrl($withpicto=0, $save_lastsearch_value=-1, $notooltip=0)
Return clicable name (with picto eventually)
const STATUS_VALIDATED
Validated status.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
verifNbUsers($userDolibarrWithoutCP, $userCP)
Compare le nombre d'utilisateur actif de Dolibarr à celui des utilisateurs des congés payés...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
__construct($db)
Constructor.
const STATUS_CANCELED
Canceled.
const STATUS_REFUSED
Refused.
countActiveUsersWithoutCP()
Compte le nombre d'utilisateur actifs dans Dolibarr sans CP.
createCPusers($single=false, $userid= '')
Créer les entrées pour chaque utilisateur au moment de la configuration.
getCheckOption($name)
Retourne un checked si vrai.
fetch_users_approver_holiday()
Return list of people with permission to validate leave requests.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
LibStatut($status, $mode=0, $startdate= '')
Returns the label of a status.