overtime enhancements
This commit is contained in:
68
src/main/resources/done_ext.sql
Normal file
68
src/main/resources/done_ext.sql
Normal file
@ -0,0 +1,68 @@
|
||||
create table done.t_required_worktime (
|
||||
pk_required_worktime int primary key generated always as identity,
|
||||
required time without time zone not null default '8:0'::time,
|
||||
day date not null,
|
||||
fk_login int not null references profile.t_login(pk),
|
||||
unique(day, fk_login)
|
||||
);
|
||||
|
||||
grant select,insert,update,delete on done.t_required_worktime to timetrack;
|
||||
|
||||
create table done.t_overtime (
|
||||
pk_overtime int primary key generated always as identity,
|
||||
worktime_offset time without time zone not null,
|
||||
impact timestamp without time zone not null,
|
||||
fk_login int not null unique references profile.t_login(pk)
|
||||
);
|
||||
|
||||
grant select,insert,update on done.t_overtime to timetrack;
|
||||
|
||||
create table done.t_freetime (
|
||||
pk_freetime int primary key generated always as identity,
|
||||
day date not null,
|
||||
required_worktime time without time zone not null default '0:0'::time,
|
||||
reason text,
|
||||
fk_login int not null references profile.t_login(pk),
|
||||
unique(day, fk_login)
|
||||
);
|
||||
|
||||
grant select,insert,update,delete on done.t_freetime to timetrack;
|
||||
|
||||
create view done.v_daylimit as
|
||||
with x(dayworktime, day, fk_login) as (
|
||||
select coalesce(time_until - time_from, '0'::interval),
|
||||
to_char(time_from, 'DD.MM.YYYY')::date,
|
||||
fk_login
|
||||
from done.t_done
|
||||
), y(daytime_from, daytime_until, day, fk_login) as (
|
||||
select min(time_from), max(time_until),
|
||||
to_char(time_from, 'DD.MM.YYYY')::date,
|
||||
fk_login
|
||||
from done.t_done
|
||||
group by to_char(time_from, 'DD.MM.YYYY')::date, fk_login
|
||||
) select to_char(y.daytime_from, 'HH24:MI') as daytime_from,
|
||||
to_char(y.daytime_until, 'HH24:MI') as daytime_until,
|
||||
to_char(sum(x.dayworktime), 'HH24:MI') as dayworktime,
|
||||
to_char(y.daytime_until - y.daytime_from - sum(x.dayworktime), 'HH24:MI') as breaks,
|
||||
to_char(y.day, 'DD.MM.YYYY')::date as day,
|
||||
y.fk_login
|
||||
from x
|
||||
left join y on y.day = x.day and y.fk_login = x.fk_login
|
||||
group by y.daytime_from, y.daytime_until, y.day, y.fk_login
|
||||
order by y.day desc;
|
||||
|
||||
grant select on done.v_daylimit to timetrack;
|
||||
|
||||
create view done.v_current_overtime as
|
||||
select x.worktime_offset + sum(l.dayworktime::time - r.required) as overtime,
|
||||
to_char(now(), 'DD.MM.YYYY HH24:MI') as impact,
|
||||
x.fk_login
|
||||
from done.t_overtime x
|
||||
left join done.v_daylimit l on l.fk_login = x.fk_login and l.day >= x.impact
|
||||
left join done.t_required_worktime r on r.fk_login = x.fk_login and r.day = l.day
|
||||
where l.day < now()
|
||||
group by x.worktime_offset, x.fk_login;
|
||||
|
||||
grant select on done.v_current_overtime to timetrack;
|
||||
|
||||
create view done.v_version as select 20240103 as version;
|
Reference in New Issue
Block a user