+EXEC: delete from public.sessions where id_user='e9e6880b-75c7-70b5-ce61-49cf6d62630f' and remote_addr='::1' and user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36';
+EXEC: update public.sessions set sessiondata='{"schemata":"demo15"}' where id='d8ab0f6e-d3ff-da01-9c1f-3bf94bc58a9c'
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-06-05'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-06-05') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-06-05'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-06-05'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-06-05') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-06-05'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-06-05'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-06-05') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-06-05'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-06-05'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-06-05') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-06-05'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-07-31') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-07-31'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-07-31') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-07-31'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-07-31') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-07-31'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-07-31') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-07-31'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-10-02') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-10-02'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-10-02') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-10-02'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-10-02') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-10-02'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=2,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','27a6cfdb-4660-1b93-ef87-7f1619610561') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=2,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=2,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=2,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+ timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='21',contracthours='84:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+taffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'27a6cfdb-4660-1b93-ef87-7f1619610561' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+taffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='524:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='21',contracthours='84:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='21',contracthours='84:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='524:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','10f3831e-5651-96f0-2bf7-249c106bce8c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='21',contracthours='84:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='180:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='524:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='524:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='180:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='180:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='180:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=0,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'10f3831e-5651-96f0-2bf7-249c106bce8c' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-10-26'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and (daydate > date('2022-12-04') or daydate < date('2020-10-26'))
+ OR (id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' AND daydate not between date('2020-10-26') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='10f3831e-5651-96f0-2bf7-249c106bce8c' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=2,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=0,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2022-03-14'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+ as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=2,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+nd2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=0,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','73f58f5d-6ca3-0d1f-4bc4-510cabb30173') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2022-03-14'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=2,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=0,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=2,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2022-03-14'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2022-03-14'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+rval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+idhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'73f58f5d-6ca3-0d1f-4bc4-510cabb30173' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='73f58f5d-6ca3-0d1f-4bc4-510cabb30173' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','f678699b-2be3-c2a0-067d-2fec6ce45e61') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+p.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='308:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=2,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='917:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='308:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'f678699b-2be3-c2a0-067d-2fec6ce45e61' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+ as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='308:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='f678699b-2be3-c2a0-067d-2fec6ce45e61' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=2,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='315:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1=null,timeend1=null,timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='de536f11-6513-6d09-9b68-8e3ffc387c30';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='917:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-01') and id not in ('42870479-28e7-e952-2a96-301d0035c9bb');
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='308:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='308:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=2,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='917:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+rs=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','78f6e494-b919-2416-0187-640e454d6846') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='308:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='308:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='315:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=1,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=2,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+idhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='917:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='315:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='308:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+s.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='315:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='301:00:00' where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'78f6e494-b919-2416-0187-640e454d6846' as id_staff, null as payedpause,
+ '07:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '07:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='78f6e494-b919-2416-0187-640e454d6846' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='78f6e494-b919-2416-0187-640e454d6846' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='78f6e494-b919-2416-0187-640e454d6846' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='78f6e494-b919-2416-0187-640e454d6846' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+terval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1=null,timeend1=null,timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='3241c58c-3733-d93b-4acb-dbad468ee078';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+terval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-02') and id not in ('efb65c65-7f0b-b740-b280-ae138978af87');
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','ec24d067-154f-2712-52c9-ed19e5251b20') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+etween rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='524:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'ec24d067-154f-2712-52c9-ed19e5251b20' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='ec24d067-154f-2712-52c9-ed19e5251b20' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='524:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='180:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+urs,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='10:00',timeend1='14:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='de536f11-6513-6d09-9b68-8e3ffc387c30';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-01') and id not in ('42870479-28e7-e952-2a96-301d0035c9bb');
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='524:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2022-08-08'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','a4e63a91-bd60-7343-9ce9-80c6d1600938') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+l and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='180:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=3,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+ timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=3,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=4,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='524:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='180:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='176:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=6,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=7,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='08:00',timeend1='12:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='3241c58c-3733-d93b-4acb-dbad468ee078';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='180:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+s.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-02') and id not in ('efb65c65-7f0b-b740-b280-ae138978af87');
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2022-08-08'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='172:00:00' where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'a4e63a91-bd60-7343-9ce9-80c6d1600938' as id_staff, null as payedpause,
+ '04:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '04:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='a4e63a91-bd60-7343-9ce9-80c6d1600938' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=6,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=7,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f74b9c10-7409-54fd-b8e8-e6f898d299e0')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-10-01') and date('2022-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: insert into demo15.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0faf88cb-b59c-b0e9-dedf-887834b11e74','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9bba4e8a-e9f3-9287-6023-d53a7282b6db','5f755fbe-d122-8b1e-bc29-0c257866903b') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=6,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f8af1914-dcc8-1482-b978-9c20339eb3aa','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'5f755fbe-d122-8b1e-bc29-0c257866903b' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' group by rp.id);
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('01eedb60-0eda-058e-9e26-4d5b72751963','5f755fbe-d122-8b1e-bc29-0c257866903b') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('2ad15899-0e9c-1942-d758-1d5fc92aa24b','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'5f755fbe-d122-8b1e-bc29-0c257866903b' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942','5f755fbe-d122-8b1e-bc29-0c257866903b') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=7,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('e6ad6258-9c36-8e68-1082-473dfcadfaa9','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'5f755fbe-d122-8b1e-bc29-0c257866903b' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='276d6198-0983-ec8a-febf-ec4ee54fae43';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: delete from demo15.staffreportperiod sp where id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('55d323b3-9990-b2a0-c441-315770790f8c','5f755fbe-d122-8b1e-bc29-0c257866903b') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-10-01'))) and date(date_trunc('week',date('2021-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'5f755fbe-d122-8b1e-bc29-0c257866903b' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='5f755fbe-d122-8b1e-bc29-0c257866903b' group by rp.id);
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('276d6198-0983-ec8a-febf-ec4ee54fae43','5f755fbe-d122-8b1e-bc29-0c257866903b') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '276d6198-0983-ec8a-febf-ec4ee54fae43')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-10-01') and date('2021-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: INSERT INTO demo15.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('f74b9c10-7409-54fd-b8e8-e6f898d299e0','06966d49-f1b1-fade-c263-0350b688eeaf') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='0faf88cb-b59c-b0e9-dedf-887834b11e74';
+EXEC: insert into demo15.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'06966d49-f1b1-fade-c263-0350b688eeaf' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2020-09-28'::timestamp,'2022-12-04'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: DELETE FROM demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and (daydate > date('2022-12-04') or daydate < date('2020-09-28'))
+ OR (id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' AND daydate not between date('2020-09-28') and date('2022-12-04'));
+EXEC: delete from demo15.staffreportperiod sp where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod not in (
+select rp.id from demo15.reportperiod rp left join demo15.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' group by rp.id);
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-12-01'))) and date(date_trunc('week',date('2022-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'e6ad6258-9c36-8e68-1082-473dfcadfaa9')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-06-01') and date('2022-07-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='9bba4e8a-e9f3-9287-6023-d53a7282b6db';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0faf88cb-b59c-b0e9-dedf-887834b11e74')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-12-01') and date('2022-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-10-01'))) and date(date_trunc('week',date('2020-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='45',contracthours='360:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='f8af1914-dcc8-1482-b978-9c20339eb3aa';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2020-11-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9bba4e8a-e9f3-9287-6023-d53a7282b6db')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2020-10-01') and date('2020-11-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-02-01'))) and date(date_trunc('week',date('2022-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperiod set maxdays='44',contracthours='352:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='01eedb60-0eda-058e-9e26-4d5b72751963';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'f8af1914-dcc8-1482-b978-9c20339eb3aa')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-02-01') and date('2022-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2020-12-01'))) and date(date_trunc('week',date('2021-01-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='f74b9c10-7409-54fd-b8e8-e6f898d299e0';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='2ad15899-0e9c-1942-d758-1d5fc92aa24b';
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-10-01'))) and date(date_trunc('week',date('2022-11-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=5,last44date=date('2021-01-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '01eedb60-0eda-058e-9e26-4d5b72751963')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2020-12-01') and date('2021-01-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-04-01'))) and date(date_trunc('week',date('2022-05-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2ad15899-0e9c-1942-d758-1d5fc92aa24b')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2022-04-01') and date('2022-05-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-03-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='43',contracthours='344:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='e6ad6258-9c36-8e68-1082-473dfcadfaa9';
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=1,status44hcount=6,last44date=date('2021-03-29'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0c8f8e8a-f19b-e0e0-0477-ecb9b2f7b942')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-02-01') and date('2021-03-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2022-06-01'))) and date(date_trunc('week',date('2022-07-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod set maxdays='131',contracthours='1048:00:00' where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and id_reportperiod='55d323b3-9990-b2a0-c441-315770790f8c';
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and daydate between date(date_trunc('week',date('2021-04-01'))) and date(date_trunc('week',date('2021-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=7,last44date=date('2021-04-05'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '55d323b3-9990-b2a0-c441-315770790f8c')
+ where pd.id_staff='06966d49-f1b1-fade-c263-0350b688eeaf' and pd.daydate between date('2021-04-01') and date('2021-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='10:00',timeend1='15:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='de536f11-6513-6d09-9b68-8e3ffc387c30';
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-01') and id not in ('42870479-28e7-e952-2a96-301d0035c9bb');
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='08:00',timeend1='13:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='3241c58c-3733-d93b-4acb-dbad468ee078';
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-02') and id not in ('efb65c65-7f0b-b740-b280-ae138978af87');
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='08:00',timeend1='13:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='3241c58c-3733-d93b-4acb-dbad468ee078';
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-02') and id not in ('efb65c65-7f0b-b740-b280-ae138978af87');
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='08:00',timeend1='13:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='3241c58c-3733-d93b-4acb-dbad468ee078';
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-02') and id not in ('efb65c65-7f0b-b740-b280-ae138978af87');
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2022-08-08'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='10:00',timeend1='14:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='de536f11-6513-6d09-9b68-8e3ffc387c30';
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-01') and id not in ('42870479-28e7-e952-2a96-301d0035c9bb');
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='08:00',timeend1='14:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='3241c58c-3733-d93b-4acb-dbad468ee078';
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-02') and id not in ('efb65c65-7f0b-b740-b280-ae138978af87');
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='10:00',timeend1='16:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='de536f11-6513-6d09-9b68-8e3ffc387c30';
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-01') and id not in ('42870479-28e7-e952-2a96-301d0035c9bb');
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='10:00',timeend1='15:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='de536f11-6513-6d09-9b68-8e3ffc387c30';
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-01') and id not in ('42870479-28e7-e952-2a96-301d0035c9bb');
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2022-08-08'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: UPDATE demo15.staffreportperioddays SET timestart1='10:00',timeend1='15:00',timestart2=null,timeend2=null,pausestart1=null,pauseend1=null,pausestart2=null,pauseend2=null,payedpause=null,timepause='00:00',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='de536f11-6513-6d09-9b68-8e3ffc387c30';
+EXEC: DELETE FROM demo15.timetracker WHERE id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate=date('2022-08-01') and id not in ('42870479-28e7-e952-2a96-301d0035c9bb');
+EXEC: update demo15.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from demo15.staffreportperioddays where id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update demo15.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from demo15.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from demo15.staffreportperioddays where id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and daydate between date(date_trunc('week',date('2022-08-01'))) and date(date_trunc('week',date('2022-09-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update demo15.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2022-08-08'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from demo15.staffreportperioddays pd
+ join demo15.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '0ed3eb53-bc4f-9d95-e90c-0b20dbd38e44')
+ where pd.id_staff='27a6cfdb-4660-1b93-ef87-7f1619610561' and pd.daydate between date('2022-08-01') and date('2022-09-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from public.sessions where id_user='e9e6880b-75c7-70b5-ce61-49cf6d62630f' and remote_addr='::1' and user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36';
+EXEC: update public.sessions set sessiondata='{"schemata":"kraeltgen"}' where id='0f0f9696-a244-2b4c-e0d9-9051e3909571'
+EXEC: INSERT INTO kraeltgen.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('a0538335-1f82-8312-8a62-2e42ea74ed20','e3ed2959-a411-2f14-b40a-27251d8f6d0c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2021-08-09'::timestamp,'2021-08-26'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2021-10-03'::timestamp,'2022-07-10'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2022-07-11'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-08-01'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-10-03'::timestamp,'2023-10-08'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: DELETE FROM kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and (daydate > date('2023-10-08') or daydate < date('2021-08-09'))
+ OR (id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' AND daydate not between date('2021-08-09') and date('2021-08-26') AND daydate not between date('2021-10-03') and date('2022-07-10') AND daydate not between date('2022-07-11') and date('2022-07-31') AND daydate not between date('2022-08-01') and date('2022-10-02') AND daydate not between date('2022-10-03') and date('2023-10-08'));
+EXEC: delete from kraeltgen.staffreportperiod sp where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod not in (
+select rp.id from kraeltgen.reportperiod rp left join kraeltgen.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by rp.id);
+EXEC: INSERT INTO kraeltgen.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('ec6261df-f5df-d1b9-7ca1-639d79e82bfe','e3ed2959-a411-2f14-b40a-27251d8f6d0c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2021-08-09'::timestamp,'2021-08-26'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2021-10-03'::timestamp,'2022-07-10'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2022-07-11'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-08-01'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-10-03'::timestamp,'2023-10-08'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: DELETE FROM kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and (daydate > date('2023-10-08') or daydate < date('2021-08-09'))
+ OR (id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' AND daydate not between date('2021-08-09') and date('2021-08-26') AND daydate not between date('2021-10-03') and date('2022-07-10') AND daydate not between date('2022-07-11') and date('2022-07-31') AND daydate not between date('2022-08-01') and date('2022-10-02') AND daydate not between date('2022-10-03') and date('2023-10-08'));
+EXEC: delete from kraeltgen.staffreportperiod sp where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod not in (
+select rp.id from kraeltgen.reportperiod rp left join kraeltgen.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by rp.id);
+EXEC: INSERT INTO kraeltgen.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('d1fe1b59-0129-bb85-53da-a4f9f69d9b83','e3ed2959-a411-2f14-b40a-27251d8f6d0c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2021-08-09'::timestamp,'2021-08-26'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2021-10-03'::timestamp,'2022-07-10'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2022-07-11'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-08-01'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-10-03'::timestamp,'2023-10-08'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: DELETE FROM kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and (daydate > date('2023-10-08') or daydate < date('2021-08-09'))
+ OR (id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' AND daydate not between date('2021-08-09') and date('2021-08-26') AND daydate not between date('2021-10-03') and date('2022-07-10') AND daydate not between date('2022-07-11') and date('2022-07-31') AND daydate not between date('2022-08-01') and date('2022-10-02') AND daydate not between date('2022-10-03') and date('2023-10-08'));
+EXEC: delete from kraeltgen.staffreportperiod sp where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod not in (
+select rp.id from kraeltgen.reportperiod rp left join kraeltgen.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by rp.id);
+EXEC: INSERT INTO kraeltgen.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('35fda5d9-36ef-528b-4339-286589719039','e3ed2959-a411-2f14-b40a-27251d8f6d0c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2021-08-09'::timestamp,'2021-08-26'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2021-10-03'::timestamp,'2022-07-10'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2022-07-11'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-08-01'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-10-03'::timestamp,'2023-10-08'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: DELETE FROM kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and (daydate > date('2023-10-08') or daydate < date('2021-08-09'))
+ OR (id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' AND daydate not between date('2021-08-09') and date('2021-08-26') AND daydate not between date('2021-10-03') and date('2022-07-10') AND daydate not between date('2022-07-11') and date('2022-07-31') AND daydate not between date('2022-08-01') and date('2022-10-02') AND daydate not between date('2022-10-03') and date('2023-10-08'));
+EXEC: delete from kraeltgen.staffreportperiod sp where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod not in (
+select rp.id from kraeltgen.reportperiod rp left join kraeltgen.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by rp.id);
+EXEC: INSERT INTO kraeltgen.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('b8cf8db4-da76-6cd2-7f7e-c44dd40fedae','e3ed2959-a411-2f14-b40a-27251d8f6d0c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2021-08-09'::timestamp,'2021-08-26'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2021-10-03'::timestamp,'2022-07-10'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2022-07-11'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-08-01'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-10-03'::timestamp,'2023-10-08'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: DELETE FROM kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and (daydate > date('2023-10-08') or daydate < date('2021-08-09'))
+ OR (id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' AND daydate not between date('2021-08-09') and date('2021-08-26') AND daydate not between date('2021-10-03') and date('2022-07-10') AND daydate not between date('2022-07-11') and date('2022-07-31') AND daydate not between date('2022-08-01') and date('2022-10-02') AND daydate not between date('2022-10-03') and date('2023-10-08'));
+EXEC: delete from kraeltgen.staffreportperiod sp where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod not in (
+select rp.id from kraeltgen.reportperiod rp left join kraeltgen.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by rp.id);
+EXEC: INSERT INTO kraeltgen.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('3aabb859-2b24-c8eb-f362-ea11fc60e1e4','e3ed2959-a411-2f14-b40a-27251d8f6d0c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2021-08-09'::timestamp,'2021-08-26'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2021-10-03'::timestamp,'2022-07-10'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2022-07-11'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-08-01'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-10-03'::timestamp,'2023-10-08'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: DELETE FROM kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and (daydate > date('2023-10-08') or daydate < date('2021-08-09'))
+ OR (id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' AND daydate not between date('2021-08-09') and date('2021-08-26') AND daydate not between date('2021-10-03') and date('2022-07-10') AND daydate not between date('2022-07-11') and date('2022-07-31') AND daydate not between date('2022-08-01') and date('2022-10-02') AND daydate not between date('2022-10-03') and date('2023-10-08'));
+EXEC: delete from kraeltgen.staffreportperiod sp where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod not in (
+select rp.id from kraeltgen.reportperiod rp left join kraeltgen.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by rp.id);
+EXEC: INSERT INTO kraeltgen.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('c6ecc3c5-6c48-659b-84f3-c671b0d78d5e','e3ed2959-a411-2f14-b40a-27251d8f6d0c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2021-08-09'::timestamp,'2021-08-26'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2021-10-03'::timestamp,'2022-07-10'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2022-07-11'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-08-01'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-10-03'::timestamp,'2023-10-08'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: DELETE FROM kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and (daydate > date('2023-10-08') or daydate < date('2021-08-09'))
+ OR (id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' AND daydate not between date('2021-08-09') and date('2021-08-26') AND daydate not between date('2021-10-03') and date('2022-07-10') AND daydate not between date('2022-07-11') and date('2022-07-31') AND daydate not between date('2022-08-01') and date('2022-10-02') AND daydate not between date('2022-10-03') and date('2023-10-08'));
+EXEC: delete from kraeltgen.staffreportperiod sp where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod not in (
+select rp.id from kraeltgen.reportperiod rp left join kraeltgen.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by rp.id);
+EXEC: INSERT INTO kraeltgen.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('951dde5e-a2b0-932a-e5a3-02502245ed39','e3ed2959-a411-2f14-b40a-27251d8f6d0c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2021-08-09'::timestamp,'2021-08-26'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2021-10-03'::timestamp,'2022-07-10'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2022-07-11'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-08-01'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-10-03'::timestamp,'2023-10-08'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: DELETE FROM kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and (daydate > date('2023-10-08') or daydate < date('2021-08-09'))
+ OR (id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' AND daydate not between date('2021-08-09') and date('2021-08-26') AND daydate not between date('2021-10-03') and date('2022-07-10') AND daydate not between date('2022-07-11') and date('2022-07-31') AND daydate not between date('2022-08-01') and date('2022-10-02') AND daydate not between date('2022-10-03') and date('2023-10-08'));
+EXEC: delete from kraeltgen.staffreportperiod sp where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod not in (
+select rp.id from kraeltgen.reportperiod rp left join kraeltgen.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by rp.id);
+EXEC: INSERT INTO kraeltgen.staffreportperiod (id_reportperiod, id_staff)
+ VALUES ('9d8d0448-32ac-7e59-daef-c0a3a1336150','e3ed2959-a411-2f14-b40a-27251d8f6d0c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2021-08-09'::timestamp,'2021-08-26'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2021-10-03'::timestamp,'2022-07-10'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '08:00:00' as wdcontracthours
+FROM generate_series( '2022-07-11'::timestamp,'2022-07-31'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '08:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-08-01'::timestamp,'2022-10-02'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: insert into kraeltgen.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
+SELECT date_trunc('day', dd)::date as daydate,'e3ed2959-a411-2f14-b40a-27251d8f6d0c' as id_staff, null as payedpause,
+ '05:00:00' as wdcontracthours
+FROM generate_series( '2022-10-03'::timestamp,'2023-10-08'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday
+do update set wdcontracthours = '05:00:00';
+EXEC: DELETE FROM kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and (daydate > date('2023-10-08') or daydate < date('2021-08-09'))
+ OR (id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' AND daydate not between date('2021-08-09') and date('2021-08-26') AND daydate not between date('2021-10-03') and date('2022-07-10') AND daydate not between date('2022-07-11') and date('2022-07-31') AND daydate not between date('2022-08-01') and date('2022-10-02') AND daydate not between date('2022-10-03') and date('2023-10-08'));
+EXEC: delete from kraeltgen.staffreportperiod sp where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod not in (
+select rp.id from kraeltgen.reportperiod rp left join kraeltgen.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
+where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by rp.id);
+EXEC: update kraeltgen.staffreportperiod set maxdays='10',contracthours='80:00:00' where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod='a0538335-1f82-8312-8a62-2e42ea74ed20';
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2021-07-01'))) and date(date_trunc('week',date('2021-08-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2021-07-01'))) and date(date_trunc('week',date('2021-08-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=1,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=1,last44date=date('2021-08-30'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'a0538335-1f82-8312-8a62-2e42ea74ed20')
+ where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and pd.daydate between date('2021-07-01') and date('2021-08-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update kraeltgen.staffreportperiod set maxdays='5',contracthours='25:00:00' where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod='ec6261df-f5df-d1b9-7ca1-639d79e82bfe';
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2021-09-01'))) and date(date_trunc('week',date('2021-10-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2021-09-01'))) and date(date_trunc('week',date('2021-10-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=6,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=2,last44date=date('2021-10-25'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'ec6261df-f5df-d1b9-7ca1-639d79e82bfe')
+ where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and pd.daydate between date('2021-09-01') and date('2021-10-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update kraeltgen.staffreportperiod set maxdays='8',contracthours='40:00:00' where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod='d1fe1b59-0129-bb85-53da-a4f9f69d9b83';
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2021-12-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2021-12-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=13,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=4,last44date=date('2021-12-27'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'd1fe1b59-0129-bb85-53da-a4f9f69d9b83')
+ where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and pd.daydate between date('2021-11-01') and date('2021-12-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update kraeltgen.staffreportperiod set maxdays='26',contracthours='130:00:00' where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod='35fda5d9-36ef-528b-4339-286589719039';
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2022-01-01'))) and date(date_trunc('week',date('2022-06-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2022-01-01'))) and date(date_trunc('week',date('2022-06-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=34,suppvacancysunwork=2,suppvacancy44hours=1,status44hcount=3,last44date=date('2022-06-27'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '35fda5d9-36ef-528b-4339-286589719039')
+ where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and pd.daydate between date('2022-01-01') and date('2022-06-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update kraeltgen.staffreportperiod set maxdays='38',contracthours='235:00:00' where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod='b8cf8db4-da76-6cd2-7f7e-c44dd40fedae';
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=43,suppvacancysunwork=2,suppvacancy44hours=2,status44hcount=6,last44date=date('2022-12-26'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'b8cf8db4-da76-6cd2-7f7e-c44dd40fedae')
+ where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and pd.daydate between date('2022-07-01') and date('2022-12-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update kraeltgen.staffreportperiod set maxdays='26',contracthours='130:00:00' where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod='3aabb859-2b24-c8eb-f362-ea11fc60e1e4';
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2023-01-01'))) and date(date_trunc('week',date('2023-06-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2023-01-01'))) and date(date_trunc('week',date('2023-06-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=7,last44date=date('2023-01-02'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3aabb859-2b24-c8eb-f362-ea11fc60e1e4')
+ where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and pd.daydate between date('2023-01-01') and date('2023-06-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update kraeltgen.staffreportperiod set maxdays='14',contracthours='70:00:00' where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod='c6ecc3c5-6c48-659b-84f3-c671b0d78d5e';
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2023-07-01'))) and date(date_trunc('week',date('2023-12-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2023-07-01'))) and date(date_trunc('week',date('2023-12-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'c6ecc3c5-6c48-659b-84f3-c671b0d78d5e')
+ where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and pd.daydate between date('2023-07-01') and date('2023-12-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update kraeltgen.staffreportperiod set maxdays='0',contracthours='00:00:00' where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod='951dde5e-a2b0-932a-e5a3-02502245ed39';
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2024-01-01'))) and date(date_trunc('week',date('2024-06-30')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2024-01-01'))) and date(date_trunc('week',date('2024-06-30')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '951dde5e-a2b0-932a-e5a3-02502245ed39')
+ where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and pd.daydate between date('2024-01-01') and date('2024-06-30')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: update kraeltgen.staffreportperiod set maxdays='0',contracthours='00:00:00' where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and id_reportperiod='9d8d0448-32ac-7e59-daef-c0a3a1336150';
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and timeend1 and pauseend1 between timestart1 and timeend1 then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and timeend2 and pauseend2 between timestart2 and timeend1 then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2024-07-01'))) and date(date_trunc('week',date('2024-12-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and daydate between date(date_trunc('week',date('2024-07-01'))) and date(date_trunc('week',date('2024-12-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '9d8d0448-32ac-7e59-daef-c0a3a1336150')
+ where pd.id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' and pd.daydate between date('2024-07-01') and date('2024-12-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: insert into kraeltgen.staffvacancyyear (id_staff,vacyear)
+ select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kraeltgen.staffreportperioddays where id_staff='e3ed2959-a411-2f14-b40a-27251d8f6d0c' group by id_staff,vyear order by id_staff,vyear
+ on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
+EXEC: delete from public.sessions where id_user='e9e6880b-75c7-70b5-ce61-49cf6d62630f' and remote_addr='::1' and user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36';
+EXEC: update public.sessions set sessiondata='{"schemata":"davincenzo"}' where id='2d9ce32a-1604-664f-e6bb-a0d1c175ffce'
+EXEC: update public.sessions set sessiondata='{"schemata":"kraeltgen"}' where id='2d9ce32a-1604-664f-e6bb-a0d1c175ffce'
+EXEC: UPDATE kraeltgen.staffreportperioddays SET timestart1='18:00',timeend1='00:15',timestart2=null,timeend2=null,pausestart1='22:00',pauseend1='22:30',pausestart2=null,pauseend2=null,payedpause=null,timepause='00:30',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='c9b126e5-394b-2aa1-512b-a1c8ece8e00c';
+EXEC: DELETE FROM kraeltgen.timetracker WHERE id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate=date('2022-07-06') and id not in ('');
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and case when timeend1 < timestart1 then timeend1::interval + '24:00:00'::interval else timeend1::interval end and pauseend1 between timestart1 and case when timeend1 < timestart1 then timeend1::interval + '24:00:00'::interval else timeend1::interval end then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and case when timeend2 < timestart2 then timeend2::interval + '24:00:00'::interval else timeend2::interval end and pauseend2 between timestart2 and case when timeend2 < timestart2 then timeend2::interval + '24:00:00'::interval else timeend2::interval end then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=49,suppvacancysunwork=2,suppvacancy44hours=1,status44hcount=4,last44date=date('2022-12-26'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'b8cf8db4-da76-6cd2-7f7e-c44dd40fedae')
+ where pd.id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and pd.daydate between date('2022-07-01') and date('2022-12-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: UPDATE kraeltgen.staffreportperioddays SET timestart1='18:00',timeend1='00:30',timestart2=null,timeend2=null,pausestart1='22:00',pauseend1='22:30',pausestart2=null,pauseend2=null,payedpause=null,timepause='00:30',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='80cf2666-ce43-b67d-8cf9-d408d1fb4a45';
+EXEC: DELETE FROM kraeltgen.timetracker WHERE id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate=date('2022-07-07') and id not in ('');
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and case when timeend1 < timestart1 then timeend1::interval + '24:00:00'::interval else timeend1::interval end and pauseend1 between timestart1 and case when timeend1 < timestart1 then timeend1::interval + '24:00:00'::interval else timeend1::interval end then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and case when timeend2 < timestart2 then timeend2::interval + '24:00:00'::interval else timeend2::interval end and pauseend2 between timestart2 and case when timeend2 < timestart2 then timeend2::interval + '24:00:00'::interval else timeend2::interval end then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=49,suppvacancysunwork=2,suppvacancy44hours=1,status44hcount=4,last44date=date('2022-12-26'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'b8cf8db4-da76-6cd2-7f7e-c44dd40fedae')
+ where pd.id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and pd.daydate between date('2022-07-01') and date('2022-12-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: UPDATE kraeltgen.staffreportperioddays SET timestart1='18:00',timeend1='01:00',timestart2=null,timeend2=null,pausestart1='18:00',pauseend1='18:30',pausestart2=null,pauseend2=null,payedpause=null,timepause='00:30',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='c125efcc-0da9-020a-bceb-d17c26129970';
+EXEC: DELETE FROM kraeltgen.timetracker WHERE id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate=date('2022-07-08') and id not in ('');
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and case when timeend1 < timestart1 then timeend1::interval + '24:00:00'::interval else timeend1::interval end and pauseend1 between timestart1 and case when timeend1 < timestart1 then timeend1::interval + '24:00:00'::interval else timeend1::interval end then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and case when timeend2 < timestart2 then timeend2::interval + '24:00:00'::interval else timeend2::interval end and pauseend2 between timestart2 and case when timeend2 < timestart2 then timeend2::interval + '24:00:00'::interval else timeend2::interval end then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=49,suppvacancysunwork=2,suppvacancy44hours=1,status44hcount=4,last44date=date('2022-12-26'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'b8cf8db4-da76-6cd2-7f7e-c44dd40fedae')
+ where pd.id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and pd.daydate between date('2022-07-01') and date('2022-12-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: UPDATE kraeltgen.staffreportperioddays SET timestart1='18:00',timeend1='02:00',timestart2=null,timeend2=null,pausestart1='22:00',pauseend1='22:30',pausestart2=null,pauseend2=null,payedpause=null,timepause='00:30',daycomment=null,vacancycomment=null,vacancyhours=null,vacillcomment=null,vacillhours=null,vacextracomment=null,vacextrahours=null,recupcomment=null,recuperationhours=null,partunempcomment=null,partunemplhours=null,otherpaidhourscomment=null,otherpaidhours=null WHERE id='9bcb58e4-dd4c-4029-846c-e10e294a9786';
+EXEC: DELETE FROM kraeltgen.timetracker WHERE id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate=date('2022-07-09') and id not in ('');
+EXEC: update kraeltgen.staffreportperioddays spds set
+ workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end,
+ dayhours=(ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption ,
+ contracthours=case when ds.worktime::interval + ds.vachours::interval + ds.vacillhours::interval + ds.vacextrahours::interval + ds.otherpaidhours::interval + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end
+ from (
+ select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
+ case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
+ case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
+ case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
+ case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
+ case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
+ preds.interruption,
+ (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2) as worktime,
+ (preds.pdt1+preds.pdt2) as timepause,
+ wdcontracthours
+ from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
+ case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then '24:00:00'::interval + timeend1::interval - timestart1::interval else timeend1::interval - timestart1::interval end else '00:00:00'::interval end as dt1,
+ case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then '24:00:00'::interval + timeend2::interval - timestart2::interval else timeend2::interval - timestart2::interval end else '00:00:00'::interval end as dt2,
+ case when pausestart1 between timestart1 and case when timeend1 < timestart1 then timeend1::interval + '24:00:00'::interval else timeend1::interval end and pauseend1 between timestart1 and case when timeend1 < timestart1 then timeend1::interval + '24:00:00'::interval else timeend1::interval end then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
+ case when pausestart1 between timestart2 and case when timeend2 < timestart2 then timeend2::interval + '24:00:00'::interval else timeend2::interval end and pauseend2 between timestart2 and case when timeend2 < timestart2 then timeend2::interval + '24:00:00'::interval else timeend2::interval end then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
+ case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then
+ timestart2::interval - timeend1::interval
+ else null end as interruption,
+ wdcontracthours
+ from kraeltgen.staffreportperioddays where id in (select id from kraeltgen.staffreportperioddays where id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) preds) ds where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperioddays spds set
+ nighthours=nh from (
+ select id,daydate,timestart1,timeend1, timestart2,timeend2,
+ coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
+ (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
+ + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
+ (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
+ from kraeltgen.staffreportperioddays s where
+ (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
+ or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
+ and id in (select id from kraeltgen.staffreportperioddays where id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and daydate between date(date_trunc('week',date('2022-07-01'))) and date(date_trunc('week',date('2022-12-31')) + interval '6 days'))
+ ) ds
+ where spds.id=ds.id;
+EXEC: update kraeltgen.staffreportperiod rpd set
+ --contracthours=csp.contracthours,
+ workhours=csp.workhours,
+ vacancyill=csp.vacillhours,
+ vacancynormal=csp.vacancynormal,
+ vacancyextra=csp.vacextrahours,
+ otherpaidhours=csp.otherpaidhours,
+ partunemplhours=csp.partunemplhours,
+ totalhours=csp.totalhours,
+ nighthours=csp.nighthours,
+ recuperationhours=csp.recuperationhours,statussuncount=49,suppvacancysunwork=2,suppvacancy44hours=1,status44hcount=4,last44date=date('2022-12-26'),avgtotalweekhours=null,hoursdiff=csp.diffhours
+ FROM (
+ select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
+ select dp.id,
+ sum(pd.workhours) as workhours,
+ sum(pd.dayhours) as totalhours,
+ sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
+ sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
+ sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
+ sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
+ sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
+ sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
+ sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours,
+ coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
+ coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
+ coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
+ coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
+ from kraeltgen.staffreportperioddays pd
+ join kraeltgen.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'b8cf8db4-da76-6cd2-7f7e-c44dd40fedae')
+ where pd.id_staff='afe52b22-342a-204a-f5c0-492ac2b23319' and pd.daydate between date('2022-07-01') and date('2022-12-31')
+ group by dp.id,dp.payedhours,dp.transferedhourscalc
+ ) rp) csp where csp.id=rpd.id;
+EXEC: delete from public.sessions where id_user='e9e6880b-75c7-70b5-ce61-49cf6d62630f' and remote_addr='::1' and user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36';
+EXEC: UPDATE demo.workplandays SET start1='10:00', end1='14:00', start2='18:00', end2='22:00', pause=null, pausestart1='14:00', pauseend1='14:30', pausestart2='17:30', pauseend2='18:00' WHERE id='c7957c42-81f9-96f8-0f5d-ad7515503674';
+EXEC: UPDATE demo.workplans SET weekhours='40:30:00', weekdays=6, freeweekdayslist='["7"]' WHERE id='fbd5ac24-becf-c358-45c4-65518415ebb8'
+EXEC: update demo.workplandays set start1='10:00:00',end1='14:00:00',start2='18:00:00',end2='22:00:00', pause=null,pausestart1='14:00:00',pauseend1='14:30:00',pausestart2='17:30:00',pauseend2='18:00:00' where id='d33cbba0-9602-54e1-98b8-401ab199dc5a';
+EXEC: update demo.workplandays set start1='10:00:00',end1='14:00:00',start2='18:00:00',end2='22:00:00', pause=null,pausestart1='14:00:00',pauseend1='14:30:00',pausestart2='17:30:00',pauseend2='18:00:00' where id='f39ad346-e714-7876-5689-2994e1312b36';
+EXEC: update demo.workplandays set start1='10:00:00',end1='14:00:00',start2='18:00:00',end2='22:00:00', pause=null,pausestart1='14:00:00',pauseend1='14:30:00',pausestart2='17:30:00',pauseend2='18:00:00' where id='c59edca6-4e4f-39a9-0427-5a7aeaec58cc';
+EXEC: update demo.workplandays set start1='10:00:00',end1='14:00:00',start2='18:00:00',end2='22:00:00', pause=null,pausestart1='14:00:00',pauseend1='14:30:00',pausestart2='17:30:00',pauseend2='18:00:00' where id='2616bad1-9854-3fce-885b-5ceaa63d0f15';
+EXEC: UPDATE demo.workplandays SET start1=null, end1=null, start2=null, end2=null, pause=null, pausestart1=null, pauseend1=null, pausestart2=null, pauseend2=null WHERE id='3436f93a-c588-4d5d-0c91-7df00c36695a';
+EXEC: UPDATE demo.workplans SET weekhours='40:00:00', weekdays=5, freeweekdayslist='["7","6"]' WHERE id='fbd5ac24-becf-c358-45c4-65518415ebb8'
+EXEC: UPDATE demo.workplandays SET start1='10:00', end1='14:30', start2='18:00', end2='22:00', pause='00:30', wpd1.pausestart1=null, pauseend1=null, pausestart2='17:30', pauseend2='18:00' WHERE id='c7957c42-81f9-96f8-0f5d-ad7515503674';
+EXEC: UPDATE demo.workplans SET weekhours='40:00:00', weekdays=5, freeweekdayslist='["7","6"]' WHERE id='fbd5ac24-becf-c358-45c4-65518415ebb8'
+EXEC: UPDATE demo.workplandays SET start1='10:00', end1='14:30', start2='18:00', end2='22:00', pause='00:30', pausestart1='14:00', pauseend1='14:30', pausestart2='17:30', pauseend2='18:00' WHERE id='c7957c42-81f9-96f8-0f5d-ad7515503674';
+EXEC: UPDATE demo.workplans SET weekhours='40:00:00', weekdays=5, freeweekdayslist='["7","6"]' WHERE id='fbd5ac24-becf-c358-45c4-65518415ebb8'
+EXEC: delete from public.sessions where id_user='e9e6880b-75c7-70b5-ce61-49cf6d62630f' and remote_addr='192.168.178.50' and user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackertype=null WHERE id='26be2229-3d60-a1df-457d-791bc10ca104';
+EXEC: UPDATE public.companies SET company='Restaurant Demo' WHERE id='26be2229-3d60-a1df-457d-791bc10ca104';
+EXEC: UPDATE public.companies SET comregister=null WHERE id='26be2229-3d60-a1df-457d-791bc10ca104';
+EXEC: UPDATE public.companies SET company='Restaurant Demo' WHERE id='26be2229-3d60-a1df-457d-791bc10ca104';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+;
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: delete from public.sessions where id_user='e9e6880b-75c7-70b5-ce61-49cf6d62630f' and remote_addr='::1' and user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET vatnumber=null WHERE id='e028cdac-fb5d-5c68-b39f-a8876422a61e';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+;
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+;
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackeruser='ksaffran@dks.lu' WHERE id='';
+EXEC: UPDATE public.companies SET timetrackerpassword='ntHesDUDWeQVs' WHERE id='';