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 =
'';
92 public $date_valid =
'';
97 public $fk_user_valid;
99 public $date_refuse =
'';
104 public $fk_user_refuse;
106 public $date_cancel =
'';
111 public $fk_user_cancel;
113 public $detail_refuse =
'';
120 public $holiday = array();
121 public $events = array();
122 public $logs = array();
124 public $optName =
'';
125 public $optValue =
'';
126 public $optRowid =
'';
170 global $langs, $conf;
171 $langs->load(
"order");
173 if (empty($conf->global->HOLIDAY_ADDON))
175 $conf->global->HOLIDAY_ADDON =
'mod_holiday_madonna';
178 if (!empty($conf->global->HOLIDAY_ADDON))
182 $file = $conf->global->HOLIDAY_ADDON.
".php";
183 $classname = $conf->global->HOLIDAY_ADDON;
186 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
187 foreach ($dirmodels as $reldir)
192 $mybool |= @include_once $dir.$file;
195 if ($mybool ===
false)
201 $obj =
new $classname();
202 $numref = $obj->getNextValue($objsoc, $this);
208 $this->error = $obj->error;
213 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_HOLIDAY_ADDON_NotDefined");
238 $this->
db->rollback();
250 public function create($user, $notrigger = 0)
258 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) { $this->error =
"ErrorBadParameterFkUser";
return -1; }
259 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) { $this->error =
"ErrorBadParameterFkValidator";
return -1; }
260 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) { $this->error =
"ErrorBadParameterFkType";
return -1; }
263 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday(";
266 $sql .=
"date_create,";
267 $sql .=
"description,";
268 $sql .=
"date_debut,";
272 $sql .=
"fk_validator,";
274 $sql .=
"fk_user_create,";
276 $sql .=
") VALUES (";
278 $sql .=
"'".$this->db->escape($this->fk_user).
"',";
279 $sql .=
" '".$this->db->idate($now).
"',";
280 $sql .=
" '".$this->db->escape($this->
description).
"',";
281 $sql .=
" '".$this->db->idate($this->date_debut).
"',";
282 $sql .=
" '".$this->db->idate($this->date_fin).
"',";
283 $sql .=
" ".$this->halfday.
",";
285 $sql .=
" '".$this->db->escape($this->fk_validator).
"',";
286 $sql .=
" ".$this->fk_type.
",";
287 $sql .=
" ".$user->id.
",";
288 $sql .=
" ".$conf->entity;
293 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
296 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
301 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"holiday");
306 $initialref =
'(PROV'.$this->id.
')';
307 if (!empty($this->ref)) $initialref = $this->ref;
309 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"holiday SET ref='".$this->
db->escape($initialref).
"' WHERE rowid=".$this->id;
310 if ($this->
db->query($sql))
312 $this->ref = $initialref;
317 if ($result < 0) $error++;
320 if (!$error && !$notrigger)
324 if ($result < 0) { $error++; }
334 foreach ($this->errors as $errmsg)
336 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
337 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
339 $this->
db->rollback();
355 public function fetch($id, $ref =
'')
360 $sql .=
" cp.rowid,";
362 $sql .=
" cp.fk_user,";
363 $sql .=
" cp.date_create,";
364 $sql .=
" cp.description,";
365 $sql .=
" cp.date_debut,";
366 $sql .=
" cp.date_fin,";
367 $sql .=
" cp.halfday,";
368 $sql .=
" cp.statut,";
369 $sql .=
" cp.fk_validator,";
370 $sql .=
" cp.date_valid,";
371 $sql .=
" cp.fk_user_valid,";
372 $sql .=
" cp.date_refuse,";
373 $sql .=
" cp.fk_user_refuse,";
374 $sql .=
" cp.date_cancel,";
375 $sql .=
" cp.fk_user_cancel,";
376 $sql .=
" cp.detail_refuse,";
377 $sql .=
" cp.note_private,";
378 $sql .=
" cp.note_public,";
379 $sql .=
" cp.fk_user_create,";
380 $sql .=
" cp.fk_type,";
381 $sql .=
" cp.entity";
382 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
383 if ($id > 0) $sql .=
" WHERE cp.rowid = ".$id;
384 else $sql .=
" WHERE cp.ref = '".$this->db->escape($ref).
"'";
386 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
392 $obj = $this->
db->fetch_object(
$resql);
394 $this->
id = $obj->rowid;
395 $this->ref = ($obj->ref ? $obj->ref : $obj->rowid);
396 $this->fk_user = $obj->fk_user;
397 $this->date_create = $this->
db->jdate($obj->date_create);
399 $this->date_debut = $this->
db->jdate($obj->date_debut);
400 $this->date_fin = $this->
db->jdate($obj->date_fin);
401 $this->date_debut_gmt = $this->
db->jdate($obj->date_debut, 1);
402 $this->date_fin_gmt = $this->
db->jdate($obj->date_fin, 1);
403 $this->halfday = $obj->halfday;
404 $this->
statut = $obj->statut;
405 $this->fk_validator = $obj->fk_validator;
406 $this->date_valid = $this->
db->jdate($obj->date_valid);
407 $this->fk_user_valid = $obj->fk_user_valid;
408 $this->date_refuse = $this->
db->jdate($obj->date_refuse);
409 $this->fk_user_refuse = $obj->fk_user_refuse;
410 $this->date_cancel = $this->
db->jdate($obj->date_cancel);
411 $this->fk_user_cancel = $obj->fk_user_cancel;
412 $this->detail_refuse = $obj->detail_refuse;
413 $this->note_private = $obj->note_private;
414 $this->note_public = $obj->note_public;
415 $this->fk_user_create = $obj->fk_user_create;
416 $this->fk_type = $obj->fk_type;
417 $this->entity = $obj->entity;
429 $this->error =
"Error ".$this->db->lasterror();
444 global $langs, $conf;
447 $sql .=
" cp.rowid,";
450 $sql .=
" cp.fk_user,";
451 $sql .=
" cp.fk_type,";
452 $sql .=
" cp.date_create,";
453 $sql .=
" cp.description,";
454 $sql .=
" cp.date_debut,";
455 $sql .=
" cp.date_fin,";
456 $sql .=
" cp.halfday,";
457 $sql .=
" cp.statut,";
458 $sql .=
" cp.fk_validator,";
459 $sql .=
" cp.date_valid,";
460 $sql .=
" cp.fk_user_valid,";
461 $sql .=
" cp.date_refuse,";
462 $sql .=
" cp.fk_user_refuse,";
463 $sql .=
" cp.date_cancel,";
464 $sql .=
" cp.fk_user_cancel,";
465 $sql .=
" cp.detail_refuse,";
467 $sql .=
" uu.lastname as user_lastname,";
468 $sql .=
" uu.firstname as user_firstname,";
469 $sql .=
" uu.login as user_login,";
470 $sql .=
" uu.statut as user_statut,";
471 $sql .=
" uu.photo as user_photo,";
473 $sql .=
" ua.lastname as validator_lastname,";
474 $sql .=
" ua.firstname as validator_firstname,";
475 $sql .=
" ua.login as validator_login,";
476 $sql .=
" ua.statut as validator_statut,";
477 $sql .=
" ua.photo as validator_photo";
479 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
480 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
481 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid";
482 $sql .=
" AND cp.fk_user IN (".$user_id.
")";
485 if (!empty($filter)) {
490 if (!empty($order)) {
494 dol_syslog(get_class($this).
"::fetchByUser", LOG_DEBUG);
500 $tab_result = $this->holiday;
510 $obj = $this->
db->fetch_object(
$resql);
512 $tab_result[$i][
'rowid'] = $obj->rowid;
513 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
515 $tab_result[$i][
'fk_user'] = $obj->fk_user;
516 $tab_result[$i][
'fk_type'] = $obj->fk_type;
517 $tab_result[$i][
'date_create'] = $this->
db->jdate($obj->date_create);
518 $tab_result[$i][
'description'] = $obj->description;
519 $tab_result[$i][
'date_debut'] = $this->
db->jdate($obj->date_debut);
520 $tab_result[$i][
'date_fin'] = $this->
db->jdate($obj->date_fin);
521 $tab_result[$i][
'date_debut_gmt'] = $this->
db->jdate($obj->date_debut, 1);
522 $tab_result[$i][
'date_fin_gmt'] = $this->
db->jdate($obj->date_fin, 1);
523 $tab_result[$i][
'halfday'] = $obj->halfday;
524 $tab_result[$i][
'statut'] = $obj->statut;
525 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
526 $tab_result[$i][
'date_valid'] = $this->
db->jdate($obj->date_valid);
527 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
528 $tab_result[$i][
'date_refuse'] = $this->
db->jdate($obj->date_refuse);
529 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
530 $tab_result[$i][
'date_cancel'] = $this->
db->jdate($obj->date_cancel);
531 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
532 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
534 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
535 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
536 $tab_result[$i][
'user_login'] = $obj->user_login;
537 $tab_result[$i][
'user_statut'] = $obj->user_statut;
538 $tab_result[$i][
'user_photo'] = $obj->user_photo;
540 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
541 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
542 $tab_result[$i][
'validator_login'] = $obj->validator_login;
543 $tab_result[$i][
'validator_statut'] = $obj->validator_statut;
544 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
550 $this->holiday = $tab_result;
554 $this->error =
"Error ".$this->db->lasterror();
571 $sql .=
" cp.rowid,";
574 $sql .=
" cp.fk_user,";
575 $sql .=
" cp.fk_type,";
576 $sql .=
" cp.date_create,";
577 $sql .=
" cp.tms as date_update,";
578 $sql .=
" cp.description,";
579 $sql .=
" cp.date_debut,";
580 $sql .=
" cp.date_fin,";
581 $sql .=
" cp.halfday,";
582 $sql .=
" cp.statut,";
583 $sql .=
" cp.fk_validator,";
584 $sql .=
" cp.date_valid,";
585 $sql .=
" cp.fk_user_valid,";
586 $sql .=
" cp.date_refuse,";
587 $sql .=
" cp.fk_user_refuse,";
588 $sql .=
" cp.date_cancel,";
589 $sql .=
" cp.fk_user_cancel,";
590 $sql .=
" cp.detail_refuse,";
592 $sql .=
" uu.lastname as user_lastname,";
593 $sql .=
" uu.firstname as user_firstname,";
594 $sql .=
" uu.login as user_login,";
595 $sql .=
" uu.statut as user_statut,";
596 $sql .=
" uu.photo as user_photo,";
598 $sql .=
" ua.lastname as validator_lastname,";
599 $sql .=
" ua.firstname as validator_firstname,";
600 $sql .=
" ua.login as validator_login,";
601 $sql .=
" ua.statut as validator_statut,";
602 $sql .=
" ua.photo as validator_photo";
604 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp, ".MAIN_DB_PREFIX.
"user as uu, ".MAIN_DB_PREFIX.
"user as ua";
605 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
606 $sql .=
" AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid ";
609 if (!empty($filter)) {
614 if (!empty($order)) {
618 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
624 $tab_result = $this->holiday;
634 $obj = $this->
db->fetch_object(
$resql);
636 $tab_result[$i][
'rowid'] = $obj->rowid;
637 $tab_result[$i][
'ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
638 $tab_result[$i][
'fk_user'] = $obj->fk_user;
639 $tab_result[$i][
'fk_type'] = $obj->fk_type;
640 $tab_result[$i][
'date_create'] = $this->
db->jdate($obj->date_create);
641 $tab_result[$i][
'date_update'] = $this->
db->jdate($obj->date_update);
642 $tab_result[$i][
'description'] = $obj->description;
643 $tab_result[$i][
'date_debut'] = $this->
db->jdate($obj->date_debut);
644 $tab_result[$i][
'date_fin'] = $this->
db->jdate($obj->date_fin);
645 $tab_result[$i][
'date_debut_gmt'] = $this->
db->jdate($obj->date_debut, 1);
646 $tab_result[$i][
'date_fin_gmt'] = $this->
db->jdate($obj->date_fin, 1);
647 $tab_result[$i][
'halfday'] = $obj->halfday;
648 $tab_result[$i][
'statut'] = $obj->statut;
649 $tab_result[$i][
'fk_validator'] = $obj->fk_validator;
650 $tab_result[$i][
'date_valid'] = $this->
db->jdate($obj->date_valid);
651 $tab_result[$i][
'fk_user_valid'] = $obj->fk_user_valid;
652 $tab_result[$i][
'date_refuse'] = $obj->date_refuse;
653 $tab_result[$i][
'fk_user_refuse'] = $obj->fk_user_refuse;
654 $tab_result[$i][
'date_cancel'] = $obj->date_cancel;
655 $tab_result[$i][
'fk_user_cancel'] = $obj->fk_user_cancel;
656 $tab_result[$i][
'detail_refuse'] = $obj->detail_refuse;
658 $tab_result[$i][
'user_firstname'] = $obj->user_firstname;
659 $tab_result[$i][
'user_lastname'] = $obj->user_lastname;
660 $tab_result[$i][
'user_login'] = $obj->user_login;
661 $tab_result[$i][
'user_statut'] = $obj->user_statut;
662 $tab_result[$i][
'user_photo'] = $obj->user_photo;
664 $tab_result[$i][
'validator_firstname'] = $obj->validator_firstname;
665 $tab_result[$i][
'validator_lastname'] = $obj->validator_lastname;
666 $tab_result[$i][
'validator_login'] = $obj->validator_login;
667 $tab_result[$i][
'validator_statut'] = $obj->validator_statut;
668 $tab_result[$i][
'validator_photo'] = $obj->validator_photo;
673 $this->holiday = $tab_result;
677 $this->error =
"Error ".$this->db->lasterror();
690 public function validate($user = null, $notrigger = 0)
692 global $conf, $langs;
696 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->
id))
705 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
706 if (!empty($this->
statut) && is_numeric($this->
statut)) {
707 $sql .=
" statut = ".$this->statut.
",";
711 $sql .=
" ref = '".$this->db->escape($num).
"'";
712 $sql .=
" WHERE rowid= ".$this->id;
716 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
719 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
727 $result = $this->
call_trigger(
'HOLIDAY_VALIDATE', $user);
728 if ($result < 0) { $error++; }
736 foreach ($this->errors as $errmsg)
738 dol_syslog(get_class($this).
"::validate ".$errmsg, LOG_ERR);
739 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
741 $this->
db->rollback();
757 public function approve($user = null, $notrigger = 0)
759 global $conf, $langs;
763 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
765 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
767 if (!empty($this->date_debut)) {
768 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
772 if (!empty($this->date_fin)) {
773 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
777 $sql .=
" halfday = ".$this->halfday.
",";
778 if (!empty($this->
statut) && is_numeric($this->
statut)) {
779 $sql .=
" statut = ".$this->statut.
",";
783 if (!empty($this->fk_validator)) {
784 $sql .=
" fk_validator = '".$this->db->escape($this->fk_validator).
"',";
788 if (!empty($this->date_valid)) {
789 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
791 $sql .=
" date_valid = NULL,";
793 if (!empty($this->fk_user_valid)) {
794 $sql .=
" fk_user_valid = '".$this->db->escape($this->fk_user_valid).
"',";
796 $sql .=
" fk_user_valid = NULL,";
798 if (!empty($this->date_refuse)) {
799 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
801 $sql .=
" date_refuse = NULL,";
803 if (!empty($this->fk_user_refuse)) {
804 $sql .=
" fk_user_refuse = '".$this->db->escape($this->fk_user_refuse).
"',";
806 $sql .=
" fk_user_refuse = NULL,";
808 if (!empty($this->date_cancel)) {
809 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
811 $sql .=
" date_cancel = NULL,";
813 if (!empty($this->fk_user_cancel)) {
814 $sql .=
" fk_user_cancel = '".$this->db->escape($this->fk_user_cancel).
"',";
816 $sql .=
" fk_user_cancel = NULL,";
818 if (!empty($this->detail_refuse)) {
819 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
821 $sql .=
" detail_refuse = NULL";
824 $sql .=
" WHERE rowid= ".$this->id;
828 dol_syslog(get_class($this).
"::approve", LOG_DEBUG);
831 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
839 $result = $this->
call_trigger(
'HOLIDAY_APPROVE', $user);
840 if ($result < 0) { $error++; }
848 foreach ($this->errors as $errmsg)
850 dol_syslog(get_class($this).
"::approve ".$errmsg, LOG_ERR);
851 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
853 $this->
db->rollback();
868 public function update($user = null, $notrigger = 0)
870 global $conf, $langs;
874 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday SET";
876 $sql .=
" description= '".$this->db->escape($this->
description).
"',";
878 if (!empty($this->date_debut)) {
879 $sql .=
" date_debut = '".$this->db->idate($this->date_debut).
"',";
883 if (!empty($this->date_fin)) {
884 $sql .=
" date_fin = '".$this->db->idate($this->date_fin).
"',";
888 $sql .=
" halfday = ".$this->halfday.
",";
889 if (!empty($this->
statut) && is_numeric($this->
statut)) {
890 $sql .=
" statut = ".$this->statut.
",";
894 if (!empty($this->fk_validator)) {
895 $sql .=
" fk_validator = '".$this->db->escape($this->fk_validator).
"',";
899 if (!empty($this->date_valid)) {
900 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
902 $sql .=
" date_valid = NULL,";
904 if (!empty($this->fk_user_valid)) {
905 $sql .=
" fk_user_valid = '".$this->db->escape($this->fk_user_valid).
"',";
907 $sql .=
" fk_user_valid = NULL,";
909 if (!empty($this->date_refuse)) {
910 $sql .=
" date_refuse = '".$this->db->idate($this->date_refuse).
"',";
912 $sql .=
" date_refuse = NULL,";
914 if (!empty($this->fk_user_refuse)) {
915 $sql .=
" fk_user_refuse = '".$this->db->escape($this->fk_user_refuse).
"',";
917 $sql .=
" fk_user_refuse = NULL,";
919 if (!empty($this->date_cancel)) {
920 $sql .=
" date_cancel = '".$this->db->idate($this->date_cancel).
"',";
922 $sql .=
" date_cancel = NULL,";
924 if (!empty($this->fk_user_cancel)) {
925 $sql .=
" fk_user_cancel = '".$this->db->escape($this->fk_user_cancel).
"',";
927 $sql .=
" fk_user_cancel = NULL,";
929 if (!empty($this->detail_refuse)) {
930 $sql .=
" detail_refuse = '".$this->db->escape($this->detail_refuse).
"'";
932 $sql .=
" detail_refuse = NULL";
935 $sql .=
" WHERE rowid= ".$this->id;
939 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
942 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
951 if ($result < 0) { $error++; }
959 foreach ($this->errors as $errmsg)
961 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
962 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
964 $this->
db->rollback();
980 public function delete($user, $notrigger = 0)
982 global $conf, $langs;
985 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday";
986 $sql .=
" WHERE rowid=".$this->id;
990 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
993 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1001 $result = $this->
call_trigger(
'HOLIDAY_DELETE', $user);
1002 if ($result < 0) { $error++; }
1010 foreach ($this->errors as $errmsg)
1012 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1013 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1015 $this->
db->rollback();
1018 $this->
db->commit();
1040 foreach ($this->holiday as $infos_CP)
1042 if ($infos_CP[
'statut'] == 4)
continue;
1043 if ($infos_CP[
'statut'] == 5)
continue;
1052 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin'])
1056 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut'])
1060 } elseif ($halfday == -1)
1063 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin'])
1065 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1)))
return false;
1067 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut'])
1069 if ($dateStart < $dateEnd)
return false;
1070 if ($dateEnd < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1)))
return false;
1072 } elseif ($halfday == 1)
1075 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin'])
1077 if ($dateStart < $dateEnd)
return false;
1078 if ($dateStart > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1)))
return false;
1080 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut'])
1082 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1)))
return false;
1084 } elseif ($halfday == 2)
1087 if ($dateStart >= $infos_CP[
'date_debut'] && $dateStart <= $infos_CP[
'date_fin'])
1089 if ($dateStart < $infos_CP[
'date_fin'] || in_array($infos_CP[
'halfday'], array(0, -1)))
return false;
1091 if ($dateEnd <= $infos_CP[
'date_fin'] && $dateEnd >= $infos_CP[
'date_debut'])
1093 if ($dateEnd > $infos_CP[
'date_debut'] || in_array($infos_CP[
'halfday'], array(0, 1)))
return false;
1096 dol_print_error(
'',
'Bad value of parameter halfday when calling function verifDateHolidayCP');
1115 global $langs, $conf;
1117 $isavailablemorning =
true;
1118 $isavailableafternoon =
true;
1121 $sql =
"SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut";
1122 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as cp";
1123 $sql .=
" WHERE cp.entity IN (".getEntity(
'holiday').
")";
1124 $sql .=
" AND cp.fk_user = ".(int) $fk_user;
1125 $sql .=
" AND cp.date_debut <= '".$this->db->idate($timestamp).
"' AND cp.date_fin >= '".$this->
db->idate($timestamp).
"'";
1126 if ($status !=
'-1') $sql .=
" AND cp.statut IN (".$this->db->sanitize($this->
db->escape($status)).
")";
1131 $num_rows = $this->
db->num_rows(
$resql);
1134 $arrayofrecord = array();
1136 while ($i < $num_rows)
1138 $obj = $this->
db->fetch_object(
$resql);
1141 $arrayofrecord[$obj->rowid] = array(
'date_start'=>$this->
db->jdate($obj->date_start),
'date_end'=>$this->
db->jdate($obj->date_end),
'halfday'=>$obj->halfday);
1146 $isavailablemorning =
true;
1147 foreach ($arrayofrecord as $record)
1149 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == 2)
continue;
1150 if ($timestamp == $record[
'date_start'] && $record[
'halfday'] == -1)
continue;
1151 $isavailablemorning =
false;
1154 $isavailableafternoon =
true;
1155 foreach ($arrayofrecord as $record)
1157 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 2)
continue;
1158 if ($timestamp == $record[
'date_end'] && $record[
'halfday'] == 1)
continue;
1159 $isavailableafternoon =
false;
1165 $result = array(
'morning'=>$isavailablemorning,
'afternoon'=>$isavailableafternoon);
1166 if (!$isavailablemorning) $result[
'morning_reason'] =
'leave_request';
1167 if (!$isavailableafternoon) $result[
'afternoon_reason'] =
'leave_request';
1179 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1)
1185 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Holiday").
'</u>';
1186 if (isset($this->
statut)) {
1187 $label .=
' '.$this->getLibStatut(5);
1189 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1191 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1196 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1197 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
1198 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
1201 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1204 $result .= $linkstart;
1205 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1206 if ($withpicto != 2) $result .= $this->ref;
1207 $result .= $linkend;
1233 public function LibStatut($status, $mode = 0, $startdate =
'')
1236 if (empty($this->labelStatus) || empty($this->labelStatusShort))
1240 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans(
'DraftCP');
1241 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans(
'ToReviewCP');
1242 $this->labelStatus[self::STATUS_APPROVED] = $langs->trans(
'ApprovedCP');
1243 $this->labelStatus[self::STATUS_CANCELED] = $langs->trans(
'CancelCP');
1244 $this->labelStatus[self::STATUS_REFUSED] = $langs->trans(
'RefuseCP');
1245 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans(
'DraftCP');
1246 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans(
'ToReviewCP');
1247 $this->labelStatusShort[self::STATUS_APPROVED] = $langs->trans(
'ApprovedCP');
1248 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans(
'CancelCP');
1249 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->trans(
'RefuseCP');
1252 $statusType =
'status6';
1253 if (!empty($startdate) && $startdate >
dol_now()) $statusType =
'status4';
1254 if ($status == self::STATUS_DRAFT) $statusType =
'status0';
1255 if ($status == self::STATUS_VALIDATED) $statusType =
'status1';
1256 if ($status == self::STATUS_CANCELED) $statusType =
'status5';
1257 if ($status == self::STATUS_REFUSED) $statusType =
'status5';
1259 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1276 $name = array(
'DraftCP',
'ToReviewCP',
'ApprovedCP',
'CancelCP',
'RefuseCP');
1277 $nb = count($name) + 1;
1280 $out =
'<select name="'.$htmlname.
'" id="'.$htmlname.
'" class="flat">'.
"\n";
1281 $out .=
'<option value="-1"> </option>'.
"\n";
1284 for ($i = 1; $i < $nb; $i++) {
1285 if ($i == $selected) {
1286 $out .=
'<option value="'.$i.
'" selected>'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1288 $out .=
'<option value="'.$i.
'">'.$langs->trans($name[$i - 1]).
'</option>'.
"\n";
1292 $out .=
'</select>'.
"\n";
1308 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1309 $sql .=
" value = '".$this->db->escape($value).
"'";
1310 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1312 dol_syslog(get_class($this).
'::updateConfCP name='.$name.
'', LOG_DEBUG);
1313 $result = $this->
db->query($sql);
1331 $sql =
"SELECT value";
1332 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1333 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1335 dol_syslog(get_class($this).
'::getConfCP name='.$name.
' createifnotfound='.$createifnotfound, LOG_DEBUG);
1336 $result = $this->
db->query($sql);
1339 $obj = $this->
db->fetch_object($result);
1343 if ($createifnotfound)
1345 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_config(name, value)";
1346 $sql .=
" VALUES('".$this->db->escape($name).
"', '".$this->
db->escape($createifnotfound).
"')";
1347 $result = $this->
db->query($sql);
1350 return $createifnotfound;
1352 $this->error = $this->
db->lasterror();
1363 $this->error = $this->
db->lasterror();
1378 global $user, $langs;
1382 if (empty($userID) && empty($nbHoliday) && empty($fk_type))
1384 $langs->load(
"holiday");
1389 $month = date(
'm', $now);
1393 $lastUpdate = $this->
getConfCP(
'lastUpdate', $newdateforlastupdate);
1394 $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
1398 if ($month != $monthLastUpdate)
1403 $nbUser = count($users);
1405 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_config SET";
1406 $sql .=
" value = '".$this->db->escape($newdateforlastupdate).
"'";
1407 $sql .=
" WHERE name = 'lastUpdate'";
1408 $result = $this->
db->query($sql);
1410 $typeleaves = $this->
getTypes(1, 1);
1413 foreach ($users as $userCounter) {
1414 $nbDaysToAdd = (isset($typeleaves[$userCounter[
'type']][
'newByMonth']) ? $typeleaves[$userCounter[
'type']][
'newByMonth'] : 0);
1415 if (empty($nbDaysToAdd))
continue;
1417 dol_syslog(
"We update leave type id ".$userCounter[
'type'].
" for user id ".$userCounter[
'rowid'], LOG_DEBUG);
1419 $nowHoliday = $userCounter[
'nb_holiday'];
1420 $newSolde = $nowHoliday + $nbDaysToAdd;
1423 $this->
addLogCP($user->id, $userCounter[
'rowid'], $langs->trans(
'HolidaysMonthlyUpdate'), $newSolde, $userCounter[
'type']);
1425 $result = $this->
updateSoldeCP($userCounter[
'rowid'], $newSolde, $userCounter[
'type'], $langs->trans(
'HolidaysMonthlyUpdate'));
1436 $this->
db->commit();
1439 $this->
db->rollback();
1449 $sql =
"SELECT nb_holiday FROM ".MAIN_DB_PREFIX.
"holiday_users";
1450 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1454 $num = $this->
db->num_rows(
$resql);
1459 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"holiday_users SET";
1460 $sql .=
" nb_holiday = ".$nbHoliday;
1461 $sql .=
" WHERE fk_user = ".(int) $userID.
" AND fk_type = ".(
int) $fk_type;
1462 $result = $this->
db->query($sql);
1466 $this->errors[] = $this->
db->lasterror();
1470 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1472 $sql .=
", ".(int) $userID.
", ".(
int) $fk_type.
")";
1473 $result = $this->
db->query($sql);
1477 $this->errors[] = $this->
db->lasterror();
1481 $this->errors[] = $this->
db->lasterror();
1503 $sql =
"SELECT value";
1504 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_config";
1505 $sql .=
" WHERE name = '".$this->db->escape($name).
"'";
1507 $result = $this->
db->query($sql);
1510 $obj = $this->
db->fetch_object($result);
1532 dol_syslog(get_class($this).
'::createCPusers');
1533 $arrayofusers = $this->
fetchUsers(
false,
true);
1535 foreach ($arrayofusers as $users)
1537 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1538 $sql .=
" (fk_user, nb_holiday)";
1539 $sql .=
" VALUES (".((int) $users[
'rowid']).
"', '0')";
1545 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_users";
1546 $sql .=
" (fk_user, nb_holiday)";
1547 $sql .=
" VALUES (".((int) $userid).
"', '0')";
1563 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"holiday_users";
1564 $sql .=
" WHERE fk_user = ".((int) $user_id);
1566 $this->
db->query($sql);
1579 $sql =
"SELECT nb_holiday";
1580 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users";
1581 $sql .=
" WHERE fk_user = ".(int) $user_id;
1582 if ($fk_type > 0) $sql .=
" AND fk_type = ".(int) $fk_type;
1584 dol_syslog(get_class($this).
'::getCPforUser user_id='.$user_id.
' type_id='.$fk_type, LOG_DEBUG);
1585 $result = $this->
db->query($sql);
1588 $obj = $this->
db->fetch_object($result);
1590 if ($obj)
return $obj->nb_holiday;
1605 public function fetchUsers($stringlist =
true, $type =
true, $filters =
'')
1609 dol_syslog(get_class($this).
"::fetchUsers", LOG_DEBUG);
1617 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1618 $sql .=
" DISTINCT";
1621 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1623 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1625 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1626 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1627 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1628 $sql .=
" OR u.entity = 0)";
1630 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1632 $sql .=
" AND u.statut > 0";
1633 if ($filters) $sql .= $filters;
1640 $num = $this->
db->num_rows(
$resql);
1646 $obj = $this->
db->fetch_object(
$resql);
1649 $stringlist .= $obj->rowid;
1651 $stringlist .=
', '.$obj->rowid;
1660 $this->error =
"Error ".$this->db->lasterror();
1665 $sql =
"SELECT DISTINCT cpu.fk_user";
1666 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1667 $sql .=
" WHERE cpu.fk_user = u.rowid";
1668 if ($filters) $sql .= $filters;
1675 $num = $this->
db->num_rows(
$resql);
1681 $obj = $this->
db->fetch_object(
$resql);
1684 $stringlist .= $obj->fk_user;
1686 $stringlist .=
', '.$obj->fk_user;
1695 $this->error =
"Error ".$this->db->lasterror();
1706 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1707 $sql .=
" DISTINCT";
1709 $sql .=
" u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1710 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1712 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1714 $sql .=
", ".MAIN_DB_PREFIX.
"usergroup_user as ug";
1715 $sql .=
" WHERE ((ug.fk_user = u.rowid";
1716 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1717 $sql .=
" OR u.entity = 0)";
1719 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
1722 $sql .=
" AND u.statut > 0";
1723 if ($filters) $sql .= $filters;
1731 $tab_result = $this->holiday;
1732 $num = $this->
db->num_rows(
$resql);
1736 $obj = $this->
db->fetch_object(
$resql);
1738 $tab_result[$i][
'rowid'] = $obj->rowid;
1739 $tab_result[$i][
'name'] = $obj->lastname;
1740 $tab_result[$i][
'lastname'] = $obj->lastname;
1741 $tab_result[$i][
'firstname'] = $obj->firstname;
1742 $tab_result[$i][
'gender'] = $obj->gender;
1743 $tab_result[$i][
'status'] = $obj->statut;
1744 $tab_result[$i][
'employee'] = $obj->employee;
1745 $tab_result[$i][
'photo'] = $obj->photo;
1746 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1756 $this->errors[] =
"Error ".$this->db->lasterror();
1761 $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";
1762 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_users as cpu, ".MAIN_DB_PREFIX.
"user as u";
1763 $sql .=
" WHERE cpu.fk_user = u.rowid";
1764 if ($filters) $sql .= $filters;
1772 $tab_result = $this->holiday;
1773 $num = $this->
db->num_rows(
$resql);
1778 $obj = $this->
db->fetch_object(
$resql);
1780 $tab_result[$i][
'rowid'] = $obj->rowid;
1781 $tab_result[$i][
'name'] = $obj->lastname;
1782 $tab_result[$i][
'lastname'] = $obj->lastname;
1783 $tab_result[$i][
'firstname'] = $obj->firstname;
1784 $tab_result[$i][
'gender'] = $obj->gender;
1785 $tab_result[$i][
'status'] = $obj->statut;
1786 $tab_result[$i][
'employee'] = $obj->employee;
1787 $tab_result[$i][
'photo'] = $obj->photo;
1788 $tab_result[$i][
'fk_user'] = $obj->fk_user;
1790 $tab_result[$i][
'type'] = $obj->fk_type;
1791 $tab_result[$i][
'nb_holiday'] = $obj->nb_holiday;
1799 $this->error =
"Error ".$this->db->lasterror();
1817 $users_validator = array();
1819 $sql =
"SELECT DISTINCT ur.fk_user";
1820 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
1821 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
1823 $sql .=
" SELECT DISTINCT ugu.fk_user";
1824 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
1825 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'";
1828 dol_syslog(get_class($this).
"::fetch_users_approver_holiday sql=".$sql);
1829 $result = $this->
db->query($sql);
1832 $num_rows = $this->
db->num_rows($result); $i = 0;
1833 while ($i < $num_rows)
1835 $objp = $this->
db->fetch_object($result);
1836 array_push($users_validator, $objp->fk_user);
1839 return $users_validator;
1841 $this->error = $this->
db->lasterror();
1842 dol_syslog(get_class($this).
"::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
1855 $sql =
"SELECT count(u.rowid) as compteur";
1856 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1857 $sql .=
" WHERE u.statut > 0";
1859 $result = $this->
db->query($sql);
1860 $objet = $this->
db->fetch_object($result);
1862 return $objet->compteur;
1872 $sql =
"SELECT count(u.rowid) as compteur";
1873 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX.
"holiday_users hu ON (hu.fk_user=u.rowid)";
1874 $sql .=
" WHERE u.statut > 0 AND hu.fk_user IS NULL";
1876 $result = $this->
db->query($sql);
1877 $objet = $this->
db->fetch_object($result);
1879 return $objet->compteur;
1891 if (empty($userCP)) $userCP = 0;
1892 dol_syslog(get_class($this).
'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.
' userCP='.$userCP);
1907 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
1909 global $conf, $langs;
1917 if ($prev_solde == $new_solde)
return 0;
1922 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"holiday_logs (";
1923 $sql .=
"date_action,";
1924 $sql .=
"fk_user_action,";
1925 $sql .=
"fk_user_update,";
1926 $sql .=
"type_action,";
1927 $sql .=
"prev_solde,";
1928 $sql .=
"new_solde,";
1930 $sql .=
") VALUES (";
1931 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
1932 $sql .=
" '".$this->db->escape($fk_user_action).
"',";
1933 $sql .=
" '".$this->db->escape($fk_user_update).
"',";
1934 $sql .=
" '".$this->db->escape($label).
"',";
1935 $sql .=
" '".$this->db->escape($prev_solde).
"',";
1936 $sql .=
" '".$this->db->escape($new_solde).
"',";
1937 $sql .=
" ".$fk_type;
1943 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1948 $this->optRowid = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"holiday_logs");
1954 foreach ($this->errors as $errmsg)
1956 dol_syslog(get_class($this).
"::addLogCP ".$errmsg, LOG_ERR);
1957 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1959 $this->
db->rollback();
1962 $this->
db->commit();
1963 return $this->optRowid;
1979 $sql .=
" cpl.rowid,";
1980 $sql .=
" cpl.date_action,";
1981 $sql .=
" cpl.fk_user_action,";
1982 $sql .=
" cpl.fk_user_update,";
1983 $sql .=
" cpl.type_action,";
1984 $sql .=
" cpl.prev_solde,";
1985 $sql .=
" cpl.new_solde,";
1986 $sql .=
" cpl.fk_type";
1987 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday_logs as cpl";
1988 $sql .=
" WHERE cpl.rowid > 0";
1991 if (!empty($filter)) {
1992 $sql .=
" ".$filter;
1996 if (!empty($order)) {
2000 dol_syslog(get_class($this).
"::fetchLog", LOG_DEBUG);
2006 $tab_result = $this->logs;
2007 $num = $this->
db->num_rows(
$resql);
2016 $obj = $this->
db->fetch_object(
$resql);
2018 $tab_result[$i][
'rowid'] = $obj->rowid;
2019 $tab_result[$i][
'date_action'] = $obj->date_action;
2020 $tab_result[$i][
'fk_user_action'] = $obj->fk_user_action;
2021 $tab_result[$i][
'fk_user_update'] = $obj->fk_user_update;
2022 $tab_result[$i][
'type_action'] = $obj->type_action;
2023 $tab_result[$i][
'prev_solde'] = $obj->prev_solde;
2024 $tab_result[$i][
'new_solde'] = $obj->new_solde;
2025 $tab_result[$i][
'fk_type'] = $obj->fk_type;
2030 $this->logs = $tab_result;
2034 $this->error =
"Error ".$this->db->lasterror();
2051 $sql =
"SELECT rowid, code, label, affect, delay, newByMonth";
2052 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types";
2053 $sql .=
" WHERE (fk_country IS NULL OR fk_country = ".$mysoc->country_id.
')';
2054 if ($active >= 0) $sql .=
" AND active = ".((int) $active);
2055 if ($affect >= 0) $sql .=
" AND affect = ".((int) $affect);
2057 $result = $this->
db->query($sql);
2060 $num = $this->
db->num_rows($result);
2063 while ($obj = $this->
db->fetch_object($result))
2065 $types[$obj->rowid] = array(
'rowid'=> $obj->rowid,
'code'=> $obj->code,
'label'=>$obj->label,
'affect'=>$obj->affect,
'delay'=>$obj->delay,
'newByMonth'=>$obj->newByMonth);
2086 $sql =
"SELECT f.rowid,";
2087 $sql .=
" f.date_create as datec,";
2088 $sql .=
" f.tms as date_modification,";
2089 $sql .=
" f.date_valid as datev,";
2091 $sql .=
" f.date_refuse as dater,";
2092 $sql .=
" f.fk_user_create as fk_user_creation,";
2093 $sql .=
" f.fk_user_modif as fk_user_modification,";
2094 $sql .=
" f.fk_user_valid,";
2095 $sql .=
" f.fk_validator as fk_user_approve,";
2096 $sql .=
" f.fk_user_refuse as fk_user_refuse";
2097 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as f";
2098 $sql .=
" WHERE f.rowid = ".$id;
2099 $sql .=
" AND f.entity = ".$conf->entity;
2106 $obj = $this->
db->fetch_object(
$resql);
2108 $this->
id = $obj->rowid;
2110 $this->date_creation = $this->
db->jdate($obj->datec);
2111 $this->date_modification = $this->
db->jdate($obj->date_modification);
2112 $this->date_validation = $this->
db->jdate($obj->datev);
2113 $this->date_approbation = $this->
db->jdate($obj->datea);
2115 $cuser =
new User($this->
db);
2116 $cuser->fetch($obj->fk_user_author);
2117 $this->user_creation = $cuser;
2119 if ($obj->fk_user_creation)
2121 $cuser =
new User($this->
db);
2122 $cuser->fetch($obj->fk_user_creation);
2123 $this->user_creation = $cuser;
2125 if ($obj->fk_user_valid)
2127 $vuser =
new User($this->
db);
2128 $vuser->fetch($obj->fk_user_valid);
2129 $this->user_validation = $vuser;
2131 if ($obj->fk_user_modification)
2133 $muser =
new User($this->
db);
2134 $muser->fetch($obj->fk_user_modification);
2135 $this->user_modification = $muser;
2137 if ($obj->fk_user_approve)
2139 $auser =
new User($this->
db);
2140 $auser->fetch($obj->fk_user_approve);
2141 $this->user_approve = $auser;
2160 global $user, $langs;
2164 $this->specimen = 1;
2168 $this->date_debut =
dol_now();
2169 $this->date_fin =
dol_now() + (24 * 3600);
2170 $this->date_valid =
dol_now();
2171 $this->fk_validator = 1;
2188 $this->nb = array();
2190 $sql =
"SELECT count(h.rowid) as nb";
2191 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2192 $sql .=
" WHERE h.statut > 1";
2193 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2194 if (empty($user->rights->expensereport->readall))
2196 $userchildids = $user->getAllChildIds(1);
2197 $sql .=
" AND (h.fk_user IN (".join(
',', $userchildids).
")";
2198 $sql .=
" OR h.fk_validator IN (".join(
',', $userchildids).
"))";
2203 while ($obj = $this->
db->fetch_object(
$resql)) {
2204 $this->nb[
"holidays"] = $obj->nb;
2210 $this->error = $this->
db->error();
2225 global $conf, $langs;
2227 if ($user->socid)
return -1;
2231 $sql =
"SELECT h.rowid, h.date_debut";
2232 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as h";
2233 $sql .=
" WHERE h.statut = 2";
2234 $sql .=
" AND h.entity IN (".getEntity(
'holiday').
")";
2235 if (empty($user->rights->expensereport->read_all))
2237 $userchildids = $user->getAllChildIds(1);
2238 $sql .=
" AND (h.fk_user IN (".join(
',', $userchildids).
")";
2239 $sql .=
" OR h.fk_validator IN (".join(
',', $userchildids).
"))";
2245 $langs->load(
"members");
2248 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2249 $response->label = $langs->trans(
"HolidaysToApprove");
2250 $response->labelShort = $langs->trans(
"ToApprove");
2251 $response->url = DOL_URL_ROOT.
'/holiday/list.php?search_statut=2&mainmenu=hrm&leftmenu=holiday';
2254 while ($obj = $this->
db->fetch_object(
$resql))
2256 $response->nbtodo++;
2258 if ($this->
db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2259 $response->nbtodolate++;
2266 $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.
Class of the module paid holiday.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
getTypes($active=-1, $affect=-1)
Return array with list of types.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
fetchUsers($stringlist=true, $type=true, $filters= '')
Get list of Users or list of vacation balance.
getLibStatut($mode=0)
Returns the label status.
getCPforUser($user_id, $fk_type=0)
Retourne le solde de congés payés pour un utilisateur.
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.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
getConfCP($name, $createifnotfound= '')
Return value of a conf parameterfor leave module TODO Move this into llx_const table.
update($user=null, $notrigger=0)
Update database.
selectStatutCP($selected= '', $htmlname= 'select_statut')
Affiche un select HTML des statuts de congés payés.
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.
$conf db
API class for accounts.
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 '...
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.
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...
load_state_board()
Load this->nb for dashboard.
addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
addLogCP
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
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.
const STATUS_VALIDATED
Validated status.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
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.
getNomUrl($withpicto=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
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, ...)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
LibStatut($status, $mode=0, $startdate= '')
Returns the label of a status.