v20330420
authorKilian Saffran <ksaffran@dks.lu>
Wed, 20 Apr 2022 08:34:33 +0000 (10:34 +0200)
committerKilian Saffran <ksaffran@dks.lu>
Wed, 20 Apr 2022 08:34:33 +0000 (10:34 +0200)
19 files changed:
app/curl.log [deleted file]
app/lib/version.php
app/log/sql.log [deleted file]
app/tmpl/module/index/index.js
app/tmpl/module/periods/periodday.js
app/tmpl/module/periods/staffperiodweeks.js
app/tmpl/module/staff/staff.js
app/tmpl/module/staff/staffcontract.js
app/tmpl/module/staff/staffmonths.js
app/tmpl/module/staff/staffperiods.js
app/tmpl/module/staff/staffvacancy.js
app/tmpl/module/timeclock/timeclock.js
app/tmpl/module/timetrack/app.js
app/tmpl/module/timetrack/renderer.js
app/tmpl/module/timetrack/shell.js
app/tmpl/module/timetrack/sqlite.js
app/tmpl/module/timetrack/sync.js
app/tmpl/module/timetrack/timeclock.nfc.js
app/tmpl/module/vacancydays/vacmonthly.js

diff --git a/app/curl.log b/app/curl.log
deleted file mode 100644 (file)
index 8b13789..0000000
+++ /dev/null
@@ -1 +0,0 @@
-
index 864098e..253754c 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-$cfg["appversion"] = '1.15.2';
+$cfg["appversion"] = '1.15.4';
   if ($cfg["debug"] == 1){
     $cfg["appversion"] = date('YmdHi');//$cfg["version"];
   } 
diff --git a/app/log/sql.log b/app/log/sql.log
deleted file mode 100644 (file)
index 235be94..0000000
+++ /dev/null
@@ -1,15862 +0,0 @@
-QUERY: select us.id,cp.schemata from public.users us left join public.companies cp on (us.id_company=cp.id) where lower(us.username)=lower('ksaffran@dks.lu') and us.userpassword = 'a1b496fa520a1c52edd076ca7a59e56667e7ebeb5ba5ba966d2d01628e165359' and us.isblocked is null;
-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/100.0.4896.88 Safari/537.36';
-QUERY: insert into public.sessions (id_user,id,remote_addr,user_agent,sessiondata) VALUES( 'e9e6880b-75c7-70b5-ce61-49cf6d62630f',public.getuuid(), '::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36',('{"schemata":"demo"}'::text)::json) returning id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select terms from public.users where id='e9e6880b-75c7-70b5-ce61-49cf6d62630f';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT distinct(us.schema_name),case when cp.company is null then 'schema:' || us.schema_name else company end as company ,
-    us.schema_name AS schemaname,
-    case when datasetname is null then 'schema:' || us.schema_name else datasetname end as datasetname
-   FROM ( select schema_name from information_schema.schemata where schema_owner != 'postgres' and schema_name != 'public') us
-     JOIN companies cp ON cp.schemata = us.schema_name AND cp.isdeleted IS null and cp.company is not null and cp.portal='app';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,trackername from demo.timetrackerconfig order by trackername
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM demo.staffgroups sg LEFT JOIN demo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: select ttr.*, st.* ,stg.groupname,'<span style="font-weight: bold;">' || COALESCE(coalesce(st.surname,'') || ' ', '') || COALESCE(st.prename, '') || '</span><br/>' || '<span style="color:' || coalesce(st.color,'') || ';font-style: italic;">'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from demo.staff st 
-LEFT JOIN demo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from demo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='demo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM demo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by startdate,enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,trackername from demo.timetrackerconfig order by trackername
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM demo.staffgroups sg LEFT JOIN demo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from demo.staff st 
-LEFT JOIN demo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from demo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='demo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM demo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by startdate,enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
--06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-30') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-30') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-30') between startdate and enddate) or (startdate <= date('2020-06-30') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '2020-06-29' as datebefore,
-          '16:30' as timebefore,
-          '2020-07-01' as dateafter,
-          '10:30' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-30') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-30') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-30') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-30') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-30') between startdate and enddate) or (startdate <= date('2020-06-30') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '2020-06-29' as datebefore,
-          '16:30' as timebefore,
-          '2020-07-01' as dateafter,
-          '10:30' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-30') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-30') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-30') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-30') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
--06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,trackername from demo.timetrackerconfig order by trackername
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM demo.staffgroups sg LEFT JOIN demo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM demo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERYARRAY: select ttr.*, st.* ,stg.groupname,'<span style="font-weight: bold;">' || COALESCE(coalesce(st.surname,'') || ' ', '') || COALESCE(st.prename, '') || '</span><br/>' || '<span style="color:' || coalesce(st.color,'') || ';font-style: italic;">'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from demo.staff st 
-LEFT JOIN demo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from demo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='demo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by startdate,enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM demo.staffgroups sg LEFT JOIN demo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: select id,trackername from demo.timetrackerconfig order by trackername
-| COALESCE(coalesce(st.surname,'') || ' ', '') || COALESCE(st.prename, '') || '</span><br/>' || '<span style="color:' || coalesce(st.color,'') || ';font-style: italic;">'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from demo.staff st 
-LEFT JOIN demo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from demo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='demo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM demo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by startdate,enddate;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by startdate,enddate;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE demo.staffreportperioddays SET timestart1='09:00',timeend1='17:00',timestart2=null,timeend2=null,pausestart1='11:00',pauseend1='11: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='ddddfe81-02bf-4f72-ecb8-453facbff515';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from demo.staffreportperiod srp
-    join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by rp.startdate,rp.enddate)
-    sper ) prp where id='2583c916-2d07-f42d-9c85-18ee42959317'; 
-EXEC: update demo.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from demo.staffreportperioddays where id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update demo.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from demo.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from demo.staffreportperioddays 
-where daydate between date('2020-07-01') and date('2020-08-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from demo.staffreportperiod where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and id_reportperiod in (select id from demo.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2020-07-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and sr.daydate between  date('2020-07-01')  and date(date_trunc('week',date('2020-08-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days')
-                    --where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-07-01') and date('2020-08-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update demo.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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-08-31'),avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from demo.staffreportperioddays pd 
-  join demo.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2583c916-2d07-f42d-9c85-18ee42959317')
-  where pd.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and  pd.daydate between date('2020-07-01') and date('2020-08-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE demo.staffreportperioddays SET timestart1='09:00',timeend1='17:00',timestart2=null,timeend2=null,pausestart1='11:00',pauseend1='11: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='ddddfe81-02bf-4f72-ecb8-453facbff515';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from demo.staffreportperiod srp
-    join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by rp.startdate,rp.enddate)
-    sper ) prp where id='2583c916-2d07-f42d-9c85-18ee42959317'; 
-EXEC: update demo.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from demo.staffreportperioddays where id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update demo.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from demo.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from demo.staffreportperioddays 
-where daydate between date('2020-07-01') and date('2020-08-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from demo.staffreportperiod where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and id_reportperiod in (select id from demo.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2020-07-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and sr.daydate between  date('2020-07-01')  and date(date_trunc('week',date('2020-08-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days')
-                    --where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-07-01') and date('2020-08-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update demo.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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-08-31'),avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from demo.staffreportperioddays pd 
-  join demo.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2583c916-2d07-f42d-9c85-18ee42959317')
-  where pd.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and  pd.daydate between date('2020-07-01') and date('2020-08-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,trackername from demo.timetrackerconfig order by trackername
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM demo.staffgroups sg LEFT JOIN demo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: select ttr.*, st.* ,stg.groupname,'<span style="font-weight: bold;">' || COALESCE(coalesce(st.surname,'') || ' ', '') || COALESCE(st.prename, '') || '</span><br/>' || '<span style="color:' || coalesce(st.color,'') || ';font-style: italic;">'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from demo.staff st 
-LEFT JOIN demo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from demo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='demo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM demo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by startdate,enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE demo.staffreportperioddays SET timestart1='09:00',timeend1='17:00',timestart2=null,timeend2=null,pausestart1='11:00',pauseend1='11: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='ddddfe81-02bf-4f72-ecb8-453facbff515';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from demo.staffreportperiod srp
-    join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by rp.startdate,rp.enddate)
-    sper ) prp where id='2583c916-2d07-f42d-9c85-18ee42959317'; 
-EXEC: update demo.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from demo.staffreportperioddays where id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update demo.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from demo.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from demo.staffreportperioddays 
-where daydate between date('2020-07-01') and date('2020-08-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from demo.staffreportperiod where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and id_reportperiod in (select id from demo.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2020-07-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and sr.daydate between  date('2020-07-01')  and date(date_trunc('week',date('2020-08-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days')
-                    --where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-07-01') and date('2020-08-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update demo.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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-08-31'),avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from demo.staffreportperioddays pd 
-  join demo.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2583c916-2d07-f42d-9c85-18ee42959317')
-  where pd.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and  pd.daydate between date('2020-07-01') and date('2020-08-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM demo.staffgroups sg LEFT JOIN demo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: select id,trackername from demo.timetrackerconfig order by trackername
-QUERYARRAY: select ttr.*, st.* ,stg.groupname,'<span style="font-weight: bold;">' || COALESCE(coalesce(st.surname,'') || ' ', '') || COALESCE(st.prename, '') || '</span><br/>' || '<span style="color:' || coalesce(st.color,'') || ';font-style: italic;">'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from demo.staff st 
-LEFT JOIN demo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from demo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='demo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM demo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM demo.staffgroups sg LEFT JOIN demo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: select id,trackername from demo.timetrackerconfig order by trackername
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM demo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERYARRAY: select ttr.*, st.* ,stg.groupname,'<span style="font-weight: bold;">' || COALESCE(coalesce(st.surname,'') || ' ', '') || COALESCE(st.prename, '') || '</span><br/>' || '<span style="color:' || coalesce(st.color,'') || ';font-style: italic;">'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from demo.staff st 
-LEFT JOIN demo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from demo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='demo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by startdate,enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE demo.staffreportperioddays SET timestart1='09:00',timeend1='16:00',timestart2=null,timeend2=null,pausestart1='11:00',pauseend1='11: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='ddddfe81-02bf-4f72-ecb8-453facbff515';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from demo.staffreportperiod srp
-    join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by rp.startdate,rp.enddate)
-    sper ) prp where id='2583c916-2d07-f42d-9c85-18ee42959317'; 
-EXEC: update demo.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from demo.staffreportperioddays where id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update demo.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from demo.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from demo.staffreportperioddays 
-where daydate between date('2020-07-01') and date('2020-08-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from demo.staffreportperiod where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and id_reportperiod in (select id from demo.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2020-07-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and sr.daydate between  date('2020-07-01')  and date(date_trunc('week',date('2020-08-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days')
-                    --where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-07-01') and date('2020-08-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update demo.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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-08-31'),avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from demo.staffreportperioddays pd 
-  join demo.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2583c916-2d07-f42d-9c85-18ee42959317')
-  where pd.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and  pd.daydate between date('2020-07-01') and date('2020-08-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,trackername from demo.timetrackerconfig order by trackername
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM demo.staffgroups sg LEFT JOIN demo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: select ttr.*, st.* ,stg.groupname,'<span style="font-weight: bold;">' || COALESCE(coalesce(st.surname,'') || ' ', '') || COALESCE(st.prename, '') || '</span><br/>' || '<span style="color:' || coalesce(st.color,'') || ';font-style: italic;">'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from demo.staff st 
-LEFT JOIN demo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from demo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='demo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM demo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by startdate,enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate < date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE demo.staffreportperioddays SET timestart1='09:00',timeend1='16:00',timestart2=null,timeend2=null,pausestart1='11:00',pauseend1='11: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='ddddfe81-02bf-4f72-ecb8-453facbff515';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from demo.staffreportperiod srp
-    join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by rp.startdate,rp.enddate)
-    sper ) prp where id='2583c916-2d07-f42d-9c85-18ee42959317'; 
-EXEC: update demo.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from demo.staffreportperioddays where id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update demo.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from demo.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from demo.staffreportperioddays where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from demo.staffreportperioddays 
-where daydate between date('2020-07-01') and date('2020-08-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from demo.staffreportperiod where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and id_reportperiod in (select id from demo.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2020-07-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and sr.daydate between  date('2020-07-01')  and date(date_trunc('week',date('2020-08-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date(date_trunc('week',date('2020-07-01'))) and date(date_trunc('week',date('2020-08-31')) + interval '6 days')
-                    --where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-07-01') and date('2020-08-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update demo.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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-08-31'),avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours,nighthours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.nighthours,'00:00:00'::interval)) as nighthours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from demo.staffreportperioddays pd 
-  join demo.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '2583c916-2d07-f42d-9c85-18ee42959317')
-  where pd.id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and  pd.daydate between date('2020-07-01') and date('2020-08-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from demo.reportperiod where id='2583c916-2d07-f42d-9c85-18ee42959317'
--06-29') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from demo.staffreportperioddays where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate > date('2020-06-29') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2020-07-01') and date('2020-08-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from demo.staffreportperioddays
-                    where id_staff= '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2020-06-29') then startdate else date('2020-06-29') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2020-09-06') then date('2020-09-06')
-    else enddate end as staffperiodend from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' 
-    and startdate < date('2020-09-06')
-  ) sc 
-  join demo.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from demo.staffreportperioddays lpd
-  left join demo.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from demo.worktimes where isdefault=true) wkdef
-  where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and lpd.daydate between date('2020-06-29') and date('2020-09-06')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from demo.timetracker 
-where daydate between date('2020-07-01') and date('2020-08-31') and id_staff ='5d606bb6-4c9c-24ea-20da-d8f2da9eb597') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select weekhours from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and ((date('2020-06-29') between startdate and enddate) or (startdate <= date('2020-06-29') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(case when maxdayhours > '12:30:00'::interval then '12:30:00'::interval else maxdayhours end ,'HH24:MI') as maxdayhours,
-          to_char('12:30:00'::interval * (1+maxhourspercents),'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char('12:30:00'::interval,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2020-06-30' as dateafter,
-          '11:00' as timeafter
-  from demo.worktimes wk where maxhourspercents is not null and maxdayhours <= '12:30:00' LIMIT 1
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM demo.staffreportperioddays pd
-             JOIN demo.staff st ON pd.id_staff = st.id and st.id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM demo.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join demo.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from demo.worktimes where isdefault =true) wkstd
-          left join demo.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from demo.timetracker where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and daydate between date('2020-06-29') and date('2020-09-06') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2020-06-29') and date('2020-09-06')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from demo.timetracker where daydate=date('2020-06-29') and id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, '5d606bb6-4c9c-24ea-20da-d8f2da9eb597' as id_staff,date('2020-06-29') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,trackername from demo.timetrackerconfig order by trackername
-QUERYARRAY: select ttr.*, st.* ,stg.groupname,'<span style="font-weight: bold;">' || COALESCE(coalesce(st.surname,'') || ' ', '') || COALESCE(st.prename, '') || '</span><br/>' || '<span style="color:' || coalesce(st.color,'') || ';font-style: italic;">'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from demo.staff st 
-LEFT JOIN demo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from demo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='demo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM demo.staffgroups sg LEFT JOIN demo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM demo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from demo.staff where id='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from demo.staffcontract where id_staff='5d606bb6-4c9c-24ea-20da-d8f2da9eb597' order by startdate,enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from demo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from demo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join demo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join demo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join demo.staff st on (pd.id_staff=st.id)
- LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM demo.staffreportperiod srp
-     LEFT JOIN demo.staff st ON srp.id_staff = st.id
-     LEFT JOIN demo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN demo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '5d606bb6-4c9c-24ea-20da-d8f2da9eb597'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='demo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select terms from public.users where id='e9e6880b-75c7-70b5-ce61-49cf6d62630f';
-QUERYARRAY: SELECT distinct(us.schema_name),case when cp.company is null then 'schema:' || us.schema_name else company end as company ,
-    us.schema_name AS schemaname,
-    case when datasetname is null then 'schema:' || us.schema_name else datasetname end as datasetname
-   FROM ( select schema_name from information_schema.schemata where schema_owner != 'postgres' and schema_name != 'public') us
-     JOIN companies cp ON cp.schemata = us.schema_name AND cp.isdeleted IS null and cp.company is not null and cp.portal='app';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select sessiondata from public.sessions where id='076166fe-8ad4-2888-5824-f4809df3b810'
-EXEC: update public.sessions set sessiondata='{"schemata":"davincenzo"}' where id='076166fe-8ad4-2888-5824-f4809df3b810'
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select terms from public.users where id='e9e6880b-75c7-70b5-ce61-49cf6d62630f';
-QUERYARRAY: SELECT distinct(us.schema_name),case when cp.company is null then 'schema:' || us.schema_name else company end as company ,
-    us.schema_name AS schemaname,
-    case when datasetname is null then 'schema:' || us.schema_name else datasetname end as datasetname
-   FROM ( select schema_name from information_schema.schemata where schema_owner != 'postgres' and schema_name != 'public') us
-     JOIN companies cp ON cp.schemata = us.schema_name AND cp.isdeleted IS null and cp.company is not null and cp.portal='app';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM davincenzo.staffgroups sg LEFT JOIN davincenzo.staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL  GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM davincenzo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERYARRAY: select id,trackername from davincenzo.timetrackerconfig order by trackername
-QUERYARRAY: select ttr.*, st.* ,stg.groupname,'<span style="font-weight: bold;">' || COALESCE(coalesce(st.surname,'') || ' ', '') || COALESCE(st.prename, '') || '</span><br/>' || '<span style="color:' || coalesce(st.color,'') || ';font-style: italic;">'|| coalesce(st.job,'') || '</span>' AS staffname,sc.staffstatus from davincenzo.staff st 
-LEFT JOIN davincenzo.staffgroups stg ON st.id_staffgroup = stg.id 
-left join (select id_staff, case when min(startdate) <= current_date and (max(enddate) is null or max(enddate) >= current_date) then 'current' 
-       when min(startdate) > current_date then 'futur' when max(enddate) < current_date then 'past' else null end as staffstatus,min(startdate)as startdate,max(enddate) as enddate from (select id_staff,startdate,case when enddate is null then current_date else enddate end as enddate from davincenzo.staffcontract) scc group by id_staff) sc on (st.id=sc.id_staff) 
-cross join (select timetrackertype,case when timetrackertype is not null then true else null end as istimetrackerenabled,periodtypes from  public.companies where schemata='davincenzo') ttr
-where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from davincenzo.staff where id='1f2b91e5-2ac4-509c-b054-ec7f5a22e0c3' and isdeleted is null;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM davincenzo.staffreportperiod srp
-     LEFT JOIN davincenzo.staff st ON srp.id_staff = st.id
-     LEFT JOIN davincenzo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN davincenzo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '1f2b91e5-2ac4-509c-b054-ec7f5a22e0c3'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from davincenzo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from davincenzo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join davincenzo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join davincenzo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join davincenzo.staff st on (pd.id_staff=st.id)
- LEFT JOIN davincenzo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '1f2b91e5-2ac4-509c-b054-ec7f5a22e0c3'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERYARRAY: select id_staff || '_' || mmonth || '_' || myear as id,surname || ' ' || prename as staffname ,id_staff,groupname,
-  -- vacancyhours,vacillhours,vacextrahours,vacancycomment,vacillcomment,vacextracomment,mday,daydate,vactotal,
-  mmonth,myear, case when regexp_replace(string_agg(case when mday='01' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='01' then vcomment else null end,','),',,',',','g') end as c01,string_agg(case when mday='01' then vtypes else null end,'') as t01,to_char(sum(case when mday='01' then vactotal else null end),'HH24:MI') as d01,case when regexp_replace(string_agg(case when mday='02' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='02' then vcomment else null end,','),',,',',','g') end as c02,string_agg(case when mday='02' then vtypes else null end,'') as t02,to_char(sum(case when mday='02' then vactotal else null end),'HH24:MI') as d02,case when regexp_replace(string_agg(case when mday='03' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='03' then vcomment else null end,','),',,',',','g') end as c03,string_agg(case when mday='03' then vtypes else null end,'') as t03,to_char(sum(case when mday='03' then vactotal else null end),'HH24:MI') as d03,case when regexp_replace(string_agg(case when mday='04' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='04' then vcomment else null end,','),',,',',','g') end as c04,string_agg(case when mday='04' then vtypes else null end,'') as t04,to_char(sum(case when mday='04' then vactotal else null end),'HH24:MI') as d04,case when regexp_replace(string_agg(case when mday='05' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='05' then vcomment else null end,','),',,',',','g') end as c05,string_agg(case when mday='05' then vtypes else null end,'') as t05,to_char(sum(case when mday='05' then vactotal else null end),'HH24:MI') as d05,case when regexp_replace(string_agg(case when mday='06' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='06' then vcomment else null end,','),',,',',','g') end as c06,string_agg(case when mday='06' then vtypes else null end,'') as t06,to_char(sum(case when mday='06' then vactotal else null end),'HH24:MI') as d06,case when regexp_replace(string_agg(case when mday='07' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='07' then vcomment else null end,','),',,',',','g') end as c07,string_agg(case when mday='07' then vtypes else null end,'') as t07,to_char(sum(case when mday='07' then vactotal else null end),'HH24:MI') as d07,case when regexp_replace(string_agg(case when mday='08' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='08' then vcomment else null end,','),',,',',','g') end as c08,string_agg(case when mday='08' then vtypes else null end,'') as t08,to_char(sum(case when mday='08' then vactotal else null end),'HH24:MI') as d08,case when regexp_replace(string_agg(case when mday='09' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='09' then vcomment else null end,','),',,',',','g') end as c09,string_agg(case when mday='09' then vtypes else null end,'') as t09,to_char(sum(case when mday='09' then vactotal else null end),'HH24:MI') as d09,case when regexp_replace(string_agg(case when mday='10' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='10' then vcomment else null end,','),',,',',','g') end as c10,string_agg(case when mday='10' then vtypes else null end,'') as t10,to_char(sum(case when mday='10' then vactotal else null end),'HH24:MI') as d10,case when regexp_replace(string_agg(case when mday='11' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='11' then vcomment else null end,','),',,',',','g') end as c11,string_agg(case when mday='11' then vtypes else null end,'') as t11,to_char(sum(case when mday='11' then vactotal else null end),'HH24:MI') as d11,case when regexp_replace(string_agg(case when mday='12' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='12' then vcomment else null end,','),',,',',','g') end as c12,string_agg(case when mday='12' then vtypes else null end,'') as t12,to_char(sum(case when mday='12' then vactotal else null end),'HH24:MI') as d12,case when regexp_replace(string_agg(case when mday='13' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='13' then vcomment else null end,','),',,',',','g') end as c13,string_agg(case when mday='13' then vtypes else null end,'') as t13,to_char(sum(case when mday='13' then vactotal else null end),'HH24:MI') as d13,case when regexp_replace(string_agg(case when mday='14' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='14' then vcomment else null end,','),',,',',','g') end as c14,string_agg(case when mday='14' then vtypes else null end,'') as t14,to_char(sum(case when mday='14' then vactotal else null end),'HH24:MI') as d14,case when regexp_replace(string_agg(case when mday='15' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='15' then vcomment else null end,','),',,',',','g') end as c15,string_agg(case when mday='15' then vtypes else null end,'') as t15,to_char(sum(case when mday='15' then vactotal else null end),'HH24:MI') as d15,case when regexp_replace(string_agg(case when mday='16' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='16' then vcomment else null end,','),',,',',','g') end as c16,string_agg(case when mday='16' then vtypes else null end,'') as t16,to_char(sum(case when mday='16' then vactotal else null end),'HH24:MI') as d16,case when regexp_replace(string_agg(case when mday='17' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='17' then vcomment else null end,','),',,',',','g') end as c17,string_agg(case when mday='17' then vtypes else null end,'') as t17,to_char(sum(case when mday='17' then vactotal else null end),'HH24:MI') as d17,case when regexp_replace(string_agg(case when mday='18' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='18' then vcomment else null end,','),',,',',','g') end as c18,string_agg(case when mday='18' then vtypes else null end,'') as t18,to_char(sum(case when mday='18' then vactotal else null end),'HH24:MI') as d18,case when regexp_replace(string_agg(case when mday='19' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='19' then vcomment else null end,','),',,',',','g') end as c19,string_agg(case when mday='19' then vtypes else null end,'') as t19,to_char(sum(case when mday='19' then vactotal else null end),'HH24:MI') as d19,case when regexp_replace(string_agg(case when mday='20' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='20' then vcomment else null end,','),',,',',','g') end as c20,string_agg(case when mday='20' then vtypes else null end,'') as t20,to_char(sum(case when mday='20' then vactotal else null end),'HH24:MI') as d20,case when regexp_replace(string_agg(case when mday='21' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='21' then vcomment else null end,','),',,',',','g') end as c21,string_agg(case when mday='21' then vtypes else null end,'') as t21,to_char(sum(case when mday='21' then vactotal else null end),'HH24:MI') as d21,case when regexp_replace(string_agg(case when mday='22' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='22' then vcomment else null end,','),',,',',','g') end as c22,string_agg(case when mday='22' then vtypes else null end,'') as t22,to_char(sum(case when mday='22' then vactotal else null end),'HH24:MI') as d22,case when regexp_replace(string_agg(case when mday='23' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='23' then vcomment else null end,','),',,',',','g') end as c23,string_agg(case when mday='23' then vtypes else null end,'') as t23,to_char(sum(case when mday='23' then vactotal else null end),'HH24:MI') as d23,case when regexp_replace(string_agg(case when mday='24' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='24' then vcomment else null end,','),',,',',','g') end as c24,string_agg(case when mday='24' then vtypes else null end,'') as t24,to_char(sum(case when mday='24' then vactotal else null end),'HH24:MI') as d24,case when regexp_replace(string_agg(case when mday='25' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='25' then vcomment else null end,','),',,',',','g') end as c25,string_agg(case when mday='25' then vtypes else null end,'') as t25,to_char(sum(case when mday='25' then vactotal else null end),'HH24:MI') as d25,case when regexp_replace(string_agg(case when mday='26' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='26' then vcomment else null end,','),',,',',','g') end as c26,string_agg(case when mday='26' then vtypes else null end,'') as t26,to_char(sum(case when mday='26' then vactotal else null end),'HH24:MI') as d26,case when regexp_replace(string_agg(case when mday='27' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='27' then vcomment else null end,','),',,',',','g') end as c27,string_agg(case when mday='27' then vtypes else null end,'') as t27,to_char(sum(case when mday='27' then vactotal else null end),'HH24:MI') as d27,case when regexp_replace(string_agg(case when mday='28' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='28' then vcomment else null end,','),',,',',','g') end as c28,string_agg(case when mday='28' then vtypes else null end,'') as t28,to_char(sum(case when mday='28' then vactotal else null end),'HH24:MI') as d28,case when regexp_replace(string_agg(case when mday='29' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='29' then vcomment else null end,','),',,',',','g') end as c29,string_agg(case when mday='29' then vtypes else null end,'') as t29,to_char(sum(case when mday='29' then vactotal else null end),'HH24:MI') as d29,case when regexp_replace(string_agg(case when mday='30' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='30' then vcomment else null end,','),',,',',','g') end as c30,string_agg(case when mday='30' then vtypes else null end,'') as t30,to_char(sum(case when mday='30' then vactotal else null end),'HH24:MI') as d30,case when regexp_replace(string_agg(case when mday='31' then vcomment else null end,','),',,',',','g') = ',' then null else regexp_replace(string_agg(case when mday='31' then vcomment else null end,','),',,',',','g') end as c31,string_agg(case when mday='31' then vtypes else null end,'') as t31,to_char(sum(case when mday='31' then vactotal else null end),'HH24:MI') as d31, to_char(sum(vacillhours),'HH24:MI') as totalill,
-  to_char(sum(vacextrahours),'HH24:MI') as totalextra,
-  to_char(sum(vacancyhours),'HH24:MI') as totalvac from (
-  select st.prename,st.surname,spd.id_staff,to_char(spd.daydate,'YYYY') as vacyear,spd.daydate,sg.id as id_staffgroup,sg.groupname,
-    coalesce(spd.vacancyhours::interval,'00:00:00'::interval) + coalesce(spd.vacillhours::interval,'00:00:00'::interval) + coalesce(spd.vacextrahours::interval,'00:00:00'::interval) as vactotal,
-      spd.vacancyhours,spd.vacillhours,spd.vacextrahours,
-      spd.vacancycomment, spd.vacillcomment, spd.vacextracomment,
-      case when spd.vacancyhours is not null then 'n' else '' end || case when spd.vacillhours is not null then 'i' else '' end || case when spd.vacextrahours  is not null then 'e' else '' end as vtypes,
-      coalesce(spd.vacancycomment,'') || ',' || coalesce(spd.vacillcomment,'') || ',' || coalesce(spd.vacextracomment,'') as vcomment,
-      to_char(spd.daydate,'DD') as mday,
-      to_char(spd.daydate,'MM') as mmonth,
-      to_char(spd.daydate,'YYYY') as myear
-      from davincenzo.staffreportperioddays spd 
-      join davincenzo.staff st on (st.id=spd.id_staff)
-      join davincenzo.staffgroups sg on (st.id_staffgroup=sg.id)
-      where (spd.vacancyhours is not null or spd.vacillhours is not null or spd.vacextrahours is not null)  and id_staff='1f2b91e5-2ac4-509c-b054-ec7f5a22e0c3'  
-      ) vd group by staffname,groupname,id_staff,myear,mmonth order by myear,staffname,mmonth
-QUERYARRAY: select id,id_staff,vacyear,to_char(vachours,'HH24:MI') as vachours from davincenzo.staffvacancyyear where id_staff='1f2b91e5-2ac4-509c-b054-ec7f5a22e0c3' order by vacyear;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM davincenzo.staffreportperiod srp
-     LEFT JOIN davincenzo.staff st ON srp.id_staff = st.id
-     LEFT JOIN davincenzo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN davincenzo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '1f2b91e5-2ac4-509c-b054-ec7f5a22e0c3'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select st.prename,st.surname, coalesce(st.prename,'') || ' ' || coalesce(st.surname,'') as staffname,
-  srp.id as id_staffreportperiod,
-  pd.id_staff,
-  psplit.id_reportperiod as id_reportperiod,
-  min(daydate) as startdate,
-  max(daydate) as enddate,
-  to_char(min(daydate),'YYYY/MM') as ymonth,
-  coalesce(case when position('-' in to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text)) > 0 then '-' || replace(to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text),'-','') else to_char(sum(pd.dayhours)-sum(pd.contracthours), 'HH24:MI'::text) end,'00:00') as hoursdiff,
-  coalesce(to_char(sum(pd.contracthours), 'HH24:MI'::text),'00:00') as contracthours,
-  coalesce(to_char(sum(pd.workhours), 'HH24:MI'::text),'00:00') as workhours,
-  to_char(sum(pd.dayhours), 'HH24:MI'::text) as totalhours,
-  to_char(sum(coalesce(pd.vacancyhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancynormal,
-  to_char(sum(coalesce(pd.vacillhours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyill,
-  to_char(sum(coalesce(pd.vacextrahours,'00:00:00'::time)), 'HH24:MI'::text) as vacancyextra,
-  to_char(sum(coalesce(pd.otherpaidhours,'00:00:00'::time)), 'HH24:MI'::text) as otherpaidhours,
-  to_char(sum(coalesce(pd.partunemplhours,'00:00:00'::time)), 'HH24:MI'::text) as partunemplhours,
-  to_char(sum(coalesce(pd.recuperationhours,'00:00:00'::time)), 'HH24:MI'::text) as recuperationhours,
-  to_char(sum(coalesce(pd.nighthours,'00:00:00'::interval)), 'HH24:MI'::text) as nighthours,
-  sgr.groupname
-  from davincenzo.staffreportperioddays pd
-  join (
-  select id as id_reportperiod,date(date_trunc('month',date(substartdate))) as splitter,date(substartdate) as startdate, date(date(substartdate) + subinterval::interval - interval '1 day') as enddate  from (
- select rpx.id,rpx.subinterval, date(generate_series(rpx.startdate::timestamp,rpx.enddate::timestamp,rpx.subinterval::interval)) as substartdate from davincenzo.reportperiod rpx
- ) gp
- ) psplit on (pd.daydate between psplit.startdate and psplit.enddate)
- join davincenzo.staffreportperiod srp on (pd.id_staff=srp.id_staff and srp.id_reportperiod=psplit.id_reportperiod)
- join davincenzo.reportperiod rp on (rp.id=srp.id_reportperiod)
- join davincenzo.staff st on (pd.id_staff=st.id)
- LEFT JOIN davincenzo.staffgroups sgr ON st.id_staffgroup = sgr.id
- WHERE st.isdeleted IS NULL  AND srp.id_staff = '1f2b91e5-2ac4-509c-b054-ec7f5a22e0c3'  
- group by srp.id,pd.id_staff,st.prename,st.surname,psplit.id_reportperiod,psplit.splitter,sgr.groupname
- ORDER BY sgr.groupname,staffname, srp.id_staff,startdate desc,enddate desc;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT distinct(us.schema_name),case when cp.company is null then 'schema:' || us.schema_name else company end as company ,
-    us.schema_name AS schemaname,
-    case when datasetname is null then 'schema:' || us.schema_name else datasetname end as datasetname
-   FROM ( select schema_name from information_schema.schemata where schema_owner != 'postgres' and schema_name != 'public') us
-     JOIN companies cp ON cp.schemata = us.schema_name AND cp.isdeleted IS null and cp.company is not null and cp.portal='app';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM davincenzo.reportperiod rp ORDER BY    startdate, enddate;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM davincenzo.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM davincenzo.staffreportperiod srp
-     LEFT JOIN davincenzo.staff st ON srp.id_staff = st.id
-     LEFT JOIN davincenzo.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN davincenzo.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = '06b40eee-f644-be05-3d93-05c235070691'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='davincenzo';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT distinct(us.schema_name),case when cp.company is null then 'schema:' || us.schema_name else company end as company ,
-    us.schema_name AS schemaname,
-    case when datasetname is null then 'schema:' || us.schema_name else datasetname end as datasetname
-   FROM ( select schema_name from information_schema.schemata where schema_owner != 'postgres' and schema_name != 'public') us
-     JOIN companies cp ON cp.schemata = us.schema_name AND cp.isdeleted IS null and cp.company is not null and cp.portal='app';
-QUERY: select terms from public.users where id='e9e6880b-75c7-70b5-ce61-49cf6d62630f';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select sessiondata from public.sessions where id='076166fe-8ad4-2888-5824-f4809df3b810'
-EXEC: update public.sessions set sessiondata='{"schemata":"lousdiner"}' where id='076166fe-8ad4-2888-5824-f4809df3b810'
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT distinct(us.schema_name),case when cp.company is null then 'schema:' || us.schema_name else company end as company ,
-    us.schema_name AS schemaname,
-    case when datasetname is null then 'schema:' || us.schema_name else datasetname end as datasetname
-   FROM ( select schema_name from information_schema.schemata where schema_owner != 'postgres' and schema_name != 'public') us
-     JOIN companies cp ON cp.schemata = us.schema_name AND cp.isdeleted IS null and cp.company is not null and cp.portal='app';
-QUERY: select terms from public.users where id='e9e6880b-75c7-70b5-ce61-49cf6d62630f';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM lousdiner.reportperiod rp ORDER BY    startdate, enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:30',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM lousdiner.reportperiod rp ORDER BY    startdate, enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:31',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM lousdiner.reportperiod rp ORDER BY    startdate, enddate;
-_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:30',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:30',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:31',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:30',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM lousdiner.reportperiod rp ORDER BY    startdate, enddate;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:31',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM lousdiner.reportperiod rp ORDER BY    startdate, enddate;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-dhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:30',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM lousdiner.reportperiod rp ORDER BY    startdate, enddate;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM lousdiner.reportperiod rp ORDER BY    startdate, enddate;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:31',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM lousdiner.reportperiod rp ORDER BY    startdate, enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:30',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:30',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-03') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-03') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-03') between startdate and enddate) or (startdate <= date('2021-02-03') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '2021-02-02' as datebefore,
-          '21:30' as timebefore,
-          '2021-02-04' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-03') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-03') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-03') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-03') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-03') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:30',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select timetrackertype,sector,portal,module_vacancy,datasetname from public.companies where schemata='lousdiner';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,   to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM lousdiner.reportperiod rp ORDER BY    startdate, enddate;
-QUERYARRAY: SELECT wp.id,wp.workplan,wp.isdefault,wp.weekhours,wp.weekdays,
-   coalesce((((((wp.workplan || ' / ') ||substr(wp.weekhours::text, 1, 5)) || 'h / ') || wp.weekdays) || 'j / libre: ') || (( SELECT string_agg(ww.wday, ',') AS string_agg FROM ( SELECT public.day_name(json_array_elements_text(wp.freeweekdayslist)) AS wday) ww)),wp.workplan ) AS dspworkplandetail
-   FROM lousdiner.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:31',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select daydate as datebefore,to_char(case when timestart2 is null then timeend1 else timeend2 end,'HH24:MI') as timeendbefore from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate < date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate desc limit 1;
-QUERY: select daydate as dateafter ,to_char(case when timestart1 is null then timestart2 else timestart1 end,'HH24:MI') as timestartafter from lousdiner.staffreportperioddays where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate > date('2021-02-02') and (timestart1 is not null or timestart2 is not null) order by daydate asc limit 1;
-QUERY: select weekhours from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and ((date('2021-02-02') between startdate and enddate) or (startdate <= date('2021-02-02') and enddate is null)) order by startdate,enddate nulls first limit 1;
-QUERY: select to_char(wk.maxdayhours,'HH24:MI') as maxdayhours,
-          to_char(wk.maxweekhours,'HH24:MI') as maxweekhours,
-          to_char(wk.maxinterruptionhours,'HH24:MI') as maxinterruptionhours,
-          to_char(wk.mindailyrecuperation,'HH24:MI') as mindailyrecuperation,
-     to_char(wk.defaultweekhours,'HH24:MI') as defaultweekhours,
-          '' as datebefore,
-          '' as timebefore,
-          '2021-02-03' as dateafter,
-          '13:00' as timeafter
- from lousdiner.worktimes wk where (date('2021-02-02') between wk.startdate and wk.enddate) or (wk.startdate is null and wk.enddate is null)  and maxhourspercents is null
- order by wk.startdate,wk.enddate nulls last limit 1;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id,id_staff,daydate,to_char(stamp_in,'HH24:MI') as stamp_in,to_char(stamp_out,'HH24:MI') as stamp_out,
-case when stamp_in is null or stamp_out is null then '00:00' else to_char(stamp_out-stamp_in,'HH24:MI') end as total  
-from lousdiner.timetracker where daydate=date('2021-02-02') and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by stamp_in,stamp_out;
-QUERYARRAY: select public.getuuid() as id, 'd439cd6a-7758-2072-9c4b-eca7639bd94f' as id_staff,date('2021-02-02') as daydate,'00:00' as stamp_in,'00:00' as stamp_out, '00:00' as total
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE lousdiner.staffreportperioddays SET timestart1='13:00',timeend1='21:30',timestart2=null,timeend2=null,pausestart1='21:00',pauseend1='21: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='c1573abe-fcf1-7685-f4c1-56901afaf998';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: DELETE FROM lousdiner.timetracker WHERE id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate=date('2021-02-02') and id not in ('');
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',startdate)) as startdate,startdate as periodstart, enddate as periodend,date(date_trunc('week',enddate) + interval '6 days') as enddate from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'
-QUERY: select * from lousdiner.reportperiod where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7';
-QUERYBYKEY: select ws.weekstart,ws.weekend,ws.calweek,ws.calyear, ws.id_staff
-  ,to_char(ws.workhours::interval,'HH24:MI') as workhours
-  ,to_char(ws.vacancyhours,'HH24:MI') as vacancynormal
-  ,to_char(ws.vacillhours,'HH24:MI') as vacancyill
-  ,to_char(ws.vacextrahours,'HH24:MI') as vacancyextra
-  ,to_char(ws.otherpaidhours,'HH24:MI') as otherpaidhours
-  ,to_char(ws.partunemplhours,'HH24:MI') as partunemplhours
-  ,to_char(ws.recuperationhours,'HH24:MI') as recuperationhours
-  ,to_char(ws.totalhours,'HH24:MI') as totalhours
-  ,cd.contractworkdays
-  ,cd.cmpcontractdays
-  ,cd.cmpweekhours
-  ,to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval),'HH24:MI') as weektrackedhours
-  ,ws.periodworkhours
-       ,interval_to_char(sum(coalesce(ttr.weektrackedhours,'00:00:00'::interval)) over (order by ws.weekstart) - sum(ws.periodworkhours::interval) over (order by ws.weekstart)) as periodtrackdiff
-       ,sum(ws.workhours::interval) over (order by ws.weekstart) as runningworkhours
-       ,interval_to_char(coalesce(ttr.weektrackedhours,'00:00:00'::interval) - ws.periodworkhours::interval) as trackeddiff
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else to_char(cd.contracthours,'HH24:MI') end as contracthours
-  ,to_char(AVG(ws.totalhours) over (order by ws.weekstart),'HH24:MI') as avgtotalhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then '00:00' else interval_to_char(ws.totalhours-cd.contracthours) end as diffhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then 
-       to_char(case when cd.cmpweekhours < '40:00:00'::interval then cd.contracthours * 1.15 *  cd.contractworkdays else (cd.contractworkdays*'08:00:00'::interval) + (cd.contractworkdays* case when maxdata.maxweekhours > '48:00:00' then '01:16:50'::interval else '00:50:00'::interval end)  end,'HH24:MI') 
-       else
-  to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours * 1.15  else maxdata.maxweekhours end,'HH24:MI')
-  end  as maxweekhours
-  ,case when cd.contractworkdays < cd.cmpcontractdays then to_char(cd.contractworkdays*'08:00:00'::interval,'HH24:MI') else 
-       to_char(case when cd.contracthours < '40:00:00'::interval then cd.contracthours else maxdata.defaultweekhours end,'HH24:MI') 
-   end as defaultweekhours
-  from (
-  SELECT weekstart,weekend,calweek,calyear, id_staff,
-                    sum(CASE WHEN srpd.workhours IS NULL THEN '00:00:00'::interval ELSE srpd.workhours::interval END) AS workhours,
-                    sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval)  else '00:00:00'::interval end) as periodworkhours,
-                    --sum(case when srpd.daydate between date('2021-02-01') and date('2021-07-31') then coalesce(srpd.workhours::interval, '00:00:00'::interval) else '00:00:00'::interval end) as periodworkhoursnopause,
-                    sum(CASE WHEN srpd.vacancyhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacancyhours::interval END) AS vacancyhours,
-                    sum(CASE WHEN srpd.vacillhours IS NULL THEN '00:00:00'::interval ELSE srpd.vacillhours::interval END) AS vacillhours,
-                    sum(CASE WHEN srpd.vacextrahours IS NULL THEN '00:00:00'::interval ELSE srpd.vacextrahours::interval END) AS vacextrahours,
-                    sum(CASE WHEN srpd.recuperationhours IS NULL THEN '00:00:00'::interval ELSE srpd.recuperationhours::interval END) AS recuperationhours,
-                    sum(CASE WHEN srpd.otherpaidhours IS NULL THEN '00:00:00'::interval ELSE srpd.otherpaidhours::interval END) AS otherpaidhours,
-                    sum(CASE WHEN srpd.partunemplhours IS NULL THEN '00:00:00'::interval ELSE srpd.partunemplhours::interval END) AS partunemplhours,
-                    sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours,
-                    sum(CASE WHEN srpd.workhours > '00:00:00'::time without time zone OR srpd.recuperationhours > '00:00:00'::time without time zone OR srpd.vacancyhours > '00:00:00'::time without time zone OR srpd.vacillhours > '00:00:00'::time without time zone OR srpd.vacextrahours > '00:00:00'::time without time zone OR srpd.otherpaidhours > '00:00:00'::time without time zone or srpd.partunemplhours > '00:00:00'::time without time zone THEN 1 ELSE 0 END) AS workdays,
-                    sum( CASE WHEN srpd.contracthours IS NULL THEN '00:00:00'::interval ELSE srpd.contracthours::interval END) AS contracthours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01')
-                    ) srpd GROUP BY srpd.weekstart,srpd.weekend,srpd.calweek,srpd.calyear,srpd.id_staff
-                  ORDER BY weekstart) ws left join (
-                    select date(date_trunc('week',pd.daydate)) as weekstart,pd.id_staff,max(sc.weekdays) as cmpcontractdays,max(sc.weekhours) as cmpweekhours,
-  case when count(pd.daydate) < avg(sc.weekdays) then count(pd.daydate) else avg(sc.weekdays) end as contractworkdays, 
-  case when count(pd.daydate) < avg(sc.weekdays) then avg(sc.weekhours/ sc.weekdays) *  count(pd.daydate) else avg(sc.weekhours/ sc.weekdays) * avg(sc.weekdays) end as contracthours ,sum(case when coalesce(pd.workhours,'00:00:00'::time) > '00:00:00'::time then 1 else 0 end) as realworkdays
-  from ( select id_staff,weekdays ,weekhours,
-    case when startdate> date('2021-02-01') then startdate else date('2021-02-01') end  as staffperiodstart, 
-    case when enddate is null or enddate > date('2021-08-01') then date('2021-08-01')
-    else enddate end as staffperiodend from lousdiner.staffcontract where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' 
-    and startdate < date('2021-08-01')
-  ) sc 
-  join lousdiner.staffreportperioddays pd on (pd.id_staff=sc.id_staff and pd.daydate between sc.staffperiodstart and sc.staffperiodend)
-  group by date(date_trunc('week',pd.daydate)),pd.id_staff
-                  ) cd on ws.id_staff = cd.id_staff and ws.weekstart=cd.weekstart
-  left join (
-    select id_staff,weekstart,max(defaultweekhours) as defaultweekhours,avg(maxweekhours) as maxweekhours from (
-  select lpd.id_staff,date(date_trunc('week',lpd.daydate)) as weekstart,lpd.daydate,
-  case when wk.defaultweekhours is null then wkdef.defaultweekhours else wk.defaultweekhours end as defaultweekhours ,
-  case when wk.maxweekhours is null then wkdef.maxweekhours else wk.maxweekhours end as maxweekhours 
-  from lousdiner.staffreportperioddays lpd
-  left join lousdiner.worktimes wk on (lpd.daydate between wk.startdate and wk.enddate)
-  cross join (select * from lousdiner.worktimes where isdefault=true) wkdef
-  where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and lpd.daydate between date('2021-02-01') and date('2021-08-01')
-  order by lpd.daydate ) mh group by id_staff,weekstart
-  ) maxdata on ws.id_staff = maxdata.id_staff and ws.weekstart=maxdata.weekstart
-  left join (
-  select weekstart,id_staff,coalesce(sum(daytracked),'00:00:00'::interval) as weektrackedhours from (
-    select daydate,id_staff,weekstart,case when sum(trackedhours) > '06:00:00'::interval then sum(trackedhours)- '00:30:00'::interval else coalesce(sum(trackedhours),'00:00:00'::interval) end as daytracked from (
-select daydate,date(date_trunc('week',daydate)) as weekstart,id_staff,(stamp_out-stamp_in)::interval as trackedhours from lousdiner.timetracker 
-where daydate between date('2021-02-01') and date('2021-07-31') and id_staff ='d439cd6a-7758-2072-9c4b-eca7639bd94f') tto group by daydate,id_staff,weekstart,trackedhours) ttx group by weekstart,id_staff
-    ) ttr on ws.weekstart=ttr.weekstart and ws.id_staff=ttr.id_staff;
-QUERY: select coalesce(prevperiod,'') as prevperiod from (select lag(id_reportperiod,1) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from lousdiner.staffreportperiod srp
-    join lousdiner.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='bec92b1d-4b99-4aad-ddcb-a693b929acd7'; 
-EXEC: update lousdiner.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(preds.pdt1+preds.pdt2)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,nighthours,
-       case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1::interval - timestart1::interval else  timeend1::interval - timestart1::interval end else  '00:00:00'::interval end as dt1,
-       case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2::interval - timestart2::interval else  timeend2::interval - timestart2::interval end  else  '00:00:00'::interval end as dt2,
-       case when pausestart1 is not null and pauseend1 is not null then case when pauseend1 < pausestart1 then '24:00:00'::interval + pauseend1::interval - pausestart1::interval else  pauseend1::interval - pausestart1::interval end else '00:00:00'::interval end as pdt1,
-       case when pausestart2 is not null and pauseend2 is not null then case when pauseend2 < pausestart2 then '24:00:00'::interval + pauseend2::interval - pausestart2::interval else  pauseend2::interval - pausestart2::interval end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then  
-        timestart2::interval - timeend1::interval
-    else null end as interruption,
-    wdcontracthours
-               from lousdiner.staffreportperioddays where id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: update lousdiner.staffreportperioddays spds set 
-  nighthours=nh from (
-  select id,daydate,timestart1,timeend1, timestart2,timeend2,
-  coalesce((case when timeend1 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend1::interval end) -
-  (case when timestart1 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart1::interval end),'00:00:00'::interval)
-   + coalesce((case when timeend2 not between '01:00:01'::interval and '05:59:59'::interval then '06:00:00'::interval else timeend2::interval end) -
-  (case when timestart2 not between '01:00:01'::interval and '05:59:59'::interval then '01:00:00'::interval else timestart2::interval end),'00:00:00'::interval) as nh
-  from lousdiner.staffreportperioddays s where 
-  (timeend1 between '01:00:01' and '05:59:59' or timeend2 between '01:00:01' and '05:59:59'
-  or timestart1 between '01:00:01' and '05:59:59' or timestart2 between '01:00:01' and '05:59:59')
-   and id in (select id from lousdiner.staffreportperioddays where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days'))
-  ) ds
-  where spds.id=ds.id;
-QUERY: select max(rowx) as statussuncount, sum(modx) as suppvacancysunwork from (
-select daydate,rowx, case when mod(rowx,20) = 0 then 2 else null end as modx from (
-select daydate,+row_number() over (order by daydate) as rowx  from lousdiner.staffreportperioddays 
-where daydate between date('2021-02-01') and date('2021-07-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from lousdiner.staffreportperiod where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and id_reportperiod in (select id from lousdiner.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-02-01')));
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= '076166fe-8ad4-2888-5824-f4809df3b810' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select *,case when week44s >= 8 then (week44s/8)::int else null end as plusdays from (
-select date(date_trunc('week',max(maxdate)) + interval '7 days') as maxdate,max(sumx) as week44s,mod(max(sumx),8) as weeksrest from (
-select weekstart,sum(case when sum(cnt44) > 0 then 0 else 1 end) over (order by weekstart) as sumx, max(daydate) as maxdate from (
-  SELECT date(date_trunc('week',yy.daydate)) as weekstart,daydate,
-                   case when (date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval) >= '44:00:00'::interval then 1 else 0 end as cnt44
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and sr.daydate between  date('2021-02-01')  and date(date_trunc('week',date('2021-07-31')) - interval '1 day')
-                                  and sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy order by yy.daydate,weekstart
-                                 ) aa group by aa.weekstart order by weekstart
-                                 ) bb)cc;
-QUERYARRAY: SELECT pd.id,pd.id_staff,pd.id_reportperiod,pd.daydate,pd.payedpause,pd.daytype,pd.daycomment,
-            vacancycomment,vacillcomment,vacextracomment,recupcomment,otherpaidhourscomment,partunempcomment,
-            date(date_trunc('week',pd.daydate)) as weekstart,
-            to_char(pd.timestart1::interval, 'HH24:MI') AS timestart1,
-            to_char(pd.timeend1::interval, 'HH24:MI') AS timeend1,
-            to_char(pd.timestart2::interval, 'HH24:MI') AS timestart2,
-            to_char(pd.timeend2::interval, 'HH24:MI') AS timeend2,
-            to_char(pd.timepause::interval, 'HH24:MI') AS timepause,
-            --  coalesce('<div class="dspvacancynormal">' || to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN null ELSE pd.vacancyhours END::interval, 'HH24:MI') || '</div>','')  ||
-            -- coalesce('<div class="dspvacancyill">' || to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN null else pd.vacillhours END::interval, 'HH24:MI') || '</div>','') || 
-            -- coalesce('<div class="dspvacancyextra">' || to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN null ELSE pd.vacextrahours END::interval, 'HH24:MI') || '</div>','') AS dspvacancyhours,
-            to_char(CASE WHEN pd.vacancyhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacancyhours END::interval, 'HH24:MI') AS vacancyhours,
-            to_char(CASE WHEN pd.vacillhours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacillhours END::interval, 'HH24:MI') AS vacillhours,
-            to_char(CASE WHEN pd.vacextrahours::interval = '00:00:00'::interval THEN NULL ELSE pd.vacextrahours END::interval, 'HH24:MI') AS vacextrahours,
-            to_char(CASE WHEN pd.otherpaidhours::interval = '00:00:00'::interval THEN NULL ELSE pd.otherpaidhours END::interval, 'HH24:MI') AS otherpaidhours,
-            to_char(CASE WHEN pd.partunemplhours::interval = '00:00:00'::interval THEN NULL ELSE pd.partunemplhours END::interval, 'HH24:MI') AS partunemplhours,
-            to_char(pd.contracthours::interval, 'HH24:MI') AS contracthours,
-            to_char(CASE WHEN pd.workhours::interval = '00:00:00'::interval THEN NULL ELSE pd.workhours END::interval, 'HH24:MI') AS workhours,
-            to_char(CASE WHEN pd.dayhours::interval = '00:00:00'::interval THEN NULL ELSE pd.dayhours END::interval, 'HH24:MI') AS dayhours,
-            to_char(case WHEN pd.recuperationhours::interval = '00:00:00'::interval THEN NULL ELSE pd.recuperationhours END::interval, 'HH24:MI') AS recuperationhours,
-            to_char(CASE WHEN pd.interruptionhours::interval = '00:00:00'::interval THEN NULL ELSE pd.interruptionhours END::interval, 'HH24:MI') AS interruptionhours,
-            to_char(CASE WHEN pd.nighthours::interval = '00:00:00'::interval THEN NULL ELSE pd.nighthours END::interval, 'HH24:MI') AS nighthours,
-            to_char(pd.pausestart1::interval, 'HH24:MI') AS pausestart1,
-            to_char(pd.pauseend1::interval, 'HH24:MI') AS pauseend1,
-            to_char(pd.pausestart2::interval, 'HH24:MI') AS pausestart2,
-            to_char(pd.pauseend2::interval, 'HH24:MI') AS pauseend2,
-            COALESCE((to_char(pd.pausestart1::interval, 'HH24:MI') || '-') || to_char(pd.pauseend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.pausestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.pausestart2::interval, 'HH24:MI')) || '-') || to_char(pd.pauseend2::interval, 'HH24:MI'), '') AS dsppausedata,
-            COALESCE((to_char(pd.timestart1::interval, 'HH24:MI') || '-') || to_char(pd.timeend1::interval, 'HH24:MI'), '') || COALESCE(((CASE WHEN pd.timestart1 IS NOT NULL THEN '<br/>' ELSE '' END || to_char(pd.timestart2::interval, 'HH24:MI')) || '-') || to_char(pd.timeend2::interval, 'HH24:MI'), '') AS dspworkdata,
-            CASE WHEN max(freehours.freehours) < '00:00:00'::interval THEN NULL ELSE to_char(max(freehours.freehours), 'HH24:MI') END AS freehoursafter,
-            to_char(coalesce(max(wk.defaultdayhours),max(wkstd.defaultdayhours)),'HH24:MI') as defaultdayhours, 
-            to_char(coalesce(max(wk.maxdayhours),max(wkstd.maxdayhours)),'HH24:MI') as maxdayhours, 
-            to_char(coalesce(max(wk.mindailyrecuperation),max(wkstd.mindailyrecuperation)),'HH24:MI') as mindailyrecuperation,
-            to_char(coalesce(max(wk.maxinterruptionhours),max(wkstd.maxinterruptionhours)),'HH24:MI') as maxinterruptionhours,
-            max(vd.vacancyname) as vacancyname,
-            to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end,'HH24:MI') as trackedtime,
-            interval_to_char(case when (max(tt.trackedtime) >= '06:00:00'::interval) then max(tt.trackedtime) - case when pd.timepause::interval > '00:30:00'::interval then pd.timepause::interval else '00:30:00'::interval end else max(tt.trackedtime) end - coalesce(pd.workhours::interval,'00:00:00'::interval))  as trackeddiff,
-            max(tt.incompletetrack) as incompletetrack
-            FROM lousdiner.staffreportperioddays pd
-             JOIN lousdiner.staff st ON pd.id_staff = st.id and st.id='d439cd6a-7758-2072-9c4b-eca7639bd94f' and st.isdeleted is null
-             LEFT JOIN ( SELECT yy.id_staff, yy.ndaydate AS daydate,yy.ndaydate + yy.ntimeend AS tmfrom, yy.daydate + yy.timestart AS tmto,
-                    yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend) AS realinterval,
-                    date_part('epoch', yy.daydate + yy.timestart - (yy.ndaydate + yy.ntimeend)) * '00:00:01'::interval AS freehours
-                   FROM ( SELECT lag(xx_1.daydate, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ndaydate,
-                            lag(xx_1.timeend, 1) OVER (ORDER BY xx_1.id_staff, xx_1.daydate) AS ntimeend,
-                            xx_1.id_staff, xx_1.daydate, xx_1.timestart, xx_1.timeend
-                           FROM ( SELECT sr.id_staff, sr.daydate,
-            CASE WHEN sr.timestart1 IS NOT NULL THEN sr.timestart1 ELSE sr.timestart2 END AS timestart,
-            CASE WHEN sr.timestart2 IS NOT NULL THEN sr.timeend2 ELSE sr.timeend1 END AS timeend
-                                   FROM lousdiner.staffreportperioddays sr
-                                  WHERE sr.dayhours IS NOT NULL AND sr.dayhours <> '00:00:00'::time without time zone
-                                  ORDER BY sr.id_staff, sr.daydate) xx_1) yy) freehours ON pd.id_staff = freehours.id_staff AND freehours.daydate = pd.daydate
-          left join lousdiner.worktimes wk on pd.daydate between wk.startdate and wk.enddate
-          cross join (select defaultdayhours,maxdayhours,mindailyrecuperation,maxinterruptionhours from lousdiner.worktimes where isdefault =true) wkstd
-          left join lousdiner.vacancydays vd on pd.daydate=vd.daydate 
-          left join (
-               select daydate,sum(case when stamp_out is not null then cast(stamp_out-stamp_in as interval)::interval else '00:00:00'::interval end) as trackedtime, 
-               sum(case when stamp_out is null and daydate < current_date then 1 else 0 end) as incompletetrack
-from lousdiner.timetracker where id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-08-01') group by daydate
-             ) tt on pd.daydate=tt.daydate
-          WHERE pd.daydate between date('2021-02-01') and date('2021-08-01')
-          group by pd.id
-          ORDER BY pd.id_staff, pd.daydate;
-QUERY: select weekstart,id_staff,avgtotalhours from (  
-     select ws.weekstart, ws.id_staff,
-  AVG(ws.totalhours) over (order by ws.weekstart) as avgtotalhours
-  from (
-  SELECT weekstart, id_staff,
-sum(CASE WHEN srpd.dayhours IS NULL THEN '00:00:00'::interval ELSE srpd.dayhours::interval END) AS totalhours
-                   FROM (select *,date(date_trunc('week', daydate)) AS weekstart,
-                    date(date_trunc('week', daydate) + interval '6 days') AS weekend,
-                    date_part('week', daydate) AS calweek,
-                    date_part('isoyear', daydate) AS calyear from lousdiner.staffreportperioddays
-                    where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date(date_trunc('week',date('2021-02-01'))) and date(date_trunc('week',date('2021-07-31')) + interval '6 days')
-                    --where id_staff= 'd439cd6a-7758-2072-9c4b-eca7639bd94f' and daydate between date('2021-02-01') and date('2021-07-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update lousdiner.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=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('2021-07-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 lousdiner.staffreportperioddays pd 
-  join lousdiner.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = 'bec92b1d-4b99-4aad-ddcb-a693b929acd7')
-  where pd.id_staff='d439cd6a-7758-2072-9c4b-eca7639bd94f' and  pd.daydate between date('2021-02-01') and date('2021-07-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coalesce(st.prename,'') as name,
-    to_char(srp.contracthours, 'HH24:MI'::text) AS contracthours,
-    to_char(srp.workhours, 'HH24:MI'::text) AS workhours,
-    --to_char(srp.vacancyhours, 'HH24:MI'::text) AS vacancyhours,
-    to_char(srp.vacancyill, 'HH24:MI'::text) AS vacancyill,
-    to_char(srp.vacancynormal, 'HH24:MI'::text) AS vacancynormal,
-    to_char(srp.vacancyextra, 'HH24:MI'::text) AS vacancyextra,
-    to_char(srp.otherpaidhours, 'HH24:MI'::text) AS otherpaidhours,
-    to_char(srp.partunemplhours, 'HH24:MI'::text) AS partunemplhours,
-    to_char(srp.recuperationhours, 'HH24:MI'::text) AS recuperationhours,
-    to_char(srp.nighthours, 'HH24:MI'::text) AS nighthours,
-    case when position('-' in to_char(srp.hoursdiff, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.hoursdiff, 'HH24:MI'),'-','') else to_char(srp.hoursdiff, 'HH24:MI') end as hoursdiff,
-    to_char(srp.totalhours, 'HH24:MI'::text) AS totalhours,
-    srp.id as id_staffreportperiod,srp.id_reportperiod, srp.id_staff, srp.id, rp.startdate, rp.enddate,
-    COALESCE(st.surname || ' '::text, ''::text) || COALESCE(st.prename, ''::text) AS staffname,
-    st.id_staffgroup, sgr.groupname,
-    case when position('-' in to_char(srp.transferedhours, 'HH24:MI')) > 0 then '-' || replace(to_char(srp.transferedhours, 'HH24:MI'),'-','') else to_char(srp.transferedhours, 'HH24:MI') end as transferedhours,
-    case when suppvacancysunwork is not null and suppvacancysunwork > 0 then '+' || suppvacancysunwork  else  null end as suppvacancysunwork,
-    case when suppvacancy44hours is not null and suppvacancy44hours > 0 then '+' || suppvacancy44hours  else null end as suppvacancy44hours
-    ,itmcontracthours,maxdays,srp.isvalidated,
-    to_char(srp.payedhours40calc,'HH24:MI'::text) AS payedhours,
-    to_char(payedhours0, 'HH24:MI'::text) as payedhours0,
-    to_char(payedhours40, 'HH24:MI'::text) as payedhours40,
-    to_char(payedhours40calc, 'HH24:MI'::text)  as payedhours40calc,
-    to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
-    to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
-    to_char(nighthourstotransfer, 'HH24:MI'::text) as nighthourstotransfer,
-    to_char(nighthourstotransfercalc, 'HH24:MI'::text)  as nighthourstotransfercalc,
-    to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM lousdiner.staffreportperiod srp
-     LEFT JOIN lousdiner.staff st ON srp.id_staff = st.id
-     LEFT JOIN lousdiner.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN lousdiner.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'd439cd6a-7758-2072-9c4b-eca7639bd94f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
index a97e08a..63aabff 100644 (file)
@@ -46,7 +46,7 @@ let index = {
     let slst = document.getElementById("lst_schemata");
     slst.innerHTML='';
     postData("db.php",{"cl":"User","fn":"getUserSchemata","id_user":"{{session.id}}","id_usergroup":"{{session.usergroup}}"}).then(data => {
-      console.log("Datasets",data.result.data);
+      //console.log("Datasets",data.result.data);
       for (var d=0;d<data.result.data.length;d++){
         let row = '<button onclick="index.changedataset(\''+ data.result.data[d].schemaname+'\');return false;" class="bar-item button padding">'+ data.result.data[d].datasetname+'</button>';
         slst.insertAdjacentHTML('beforeend',row);
index fb17c03..6fa857a 100644 (file)
@@ -21,7 +21,7 @@ let periodday = {
   edit: function(cday,closeClb){
     periodday.closeCallback = closeClb;
     dataform.cleanform2("staffreportperioddays",periodday.choices);
-    console.log("cday",cday,closeClb,periodday.closeCallback);
+    //console.log("cday",cday,closeClb,periodday.closeCallback);
     periodday.cday=cday;
    //let cday = periodday.tbl.getSelectedData();
    //let selrp = periodday.parenttbl.getSelectedData();
@@ -104,10 +104,10 @@ let periodday = {
       
         if ((sin.length == 5) || (sout.length == 5)){
           let nrow = {"id":ttid,"stamp_in":null,"stamp_out":null};
-          if (sin.length == 5){nrow.stamp_in=sel[0].daydate + " " +sin + ":00";}
-          if (sout.length == 5){nrow.stamp_out=sel[0].daydate + " " +sout + ":00";}
+          if (sin.length == 5){nrow.stamp_in=periodday.cday.daydate + " " +sin + ":00";}
+          if (sout.length == 5){nrow.stamp_out=periodday.cday.daydate + " " +sout + ":00";}
           if ((sin > sout) && (sout != "") && (sin != "")){ 
-            let stpoutday = sel[0].daydate;
+            let stpoutday = periodday.cday.daydate;
             stpoutday = moment(stpoutday).add(1, 'd').format("YYYY-MM-DD"); 
             nrow.stamp_out = stpoutday + " " +sout + ":00";
           }
@@ -402,6 +402,7 @@ let periodday = {
     }
     let tpsval='';
     let calcwp=0;
+    calcwp = calc;
     if ((calc >= 360) && (pps == false)){
       tpsval = '00:30';
       calcwp = calc-30;
index 882eef2..c3632d7 100644 (file)
@@ -190,11 +190,11 @@ let staffperiodweeks = {
     }
     //console.log("PeriodID",xrepid);
     postData("db.php",{"get":"periodweeksums","schemata":schemata,"id_staff":selrp[0].id_staff,"id_period":xrepid,"date_start":weekmonstart,"date_end":weeksunend}).then(data => {
-      console.log("WeeksumData",data.result);
+      //console.log("WeeksumData",data.result);
       staffperiodweeks.weekdata = data.result.data;
       postData("db.php",{ "get":  "perioddays","schemata":schemata,"id_staff":selrp[0].id_staff,"date_start":weekmonstart,"date_end":weeksunend}).then(data2 => {
         if (data2 && data2.result.data) {
-          console.log("Data to Set",data2.result);
+          //console.log("Data to Set",data2.result);
           //staffperiodweeks.tbl.redraw();
           staffperiodweeks.tbl.setData(data2.result.data).then(dd => {
             if (staffperiodweeks.selectedid != null){
index 3c3a228..776987e 100644 (file)
@@ -163,7 +163,7 @@ let staff ={
   gettbldata: function(id){
     let selectedData = staff.tbl.getSelectedData();
     postData("db.php",{ "cl":"Staff","fn":"getStaffList","schema":schemata,"id_groups":'{{session.staffgroups}}'}).then(data => {
-      console.log("getStaffList",data.result);
+      //console.log("getStaffList",data.result);
       staff.tbl.setData(data.result.data).then(function(){
         if(selectedData[0]){staff.tbl.selectRow(selectedData[0]['id']);}
       });
@@ -173,7 +173,7 @@ let staff ={
     if (!fval){
       fval = document.getElementById("stafffilter").value;
     }
-    console.log(fval);
+    //console.log(fval);
     if (fval == "all"){
       staff.tbl.clearFilter();
     } else {
@@ -212,14 +212,14 @@ let staff ={
     }
     showdataloaddlg('','<div class="xxlarge">{{ lbl.waitmsg }}</div>');
     postData("db.php",flds).then(data => {
-      console.log("after Save OK !",data);
+      //console.log("after Save OK !",data);
       document.getElementById("dlg_addstaff").style.display = 'none';
       staff.current_view = 'basedata';
       staff.gettbldata();
       staff.setview(staff.current_view);
       closedataloaddlg();
     }).catch(e => {
-      console.log("after Save Catched !",e);
+      //console.log("after Save Catched !",e);
       document.getElementById("dlg_addstaff").style.display = 'none';
       closedataloaddlg();
     });
@@ -332,7 +332,7 @@ let staff ={
   setview: function(viewname){
    let sel = staff.tbl.getSelectedData();
    if (sel[0]){
-     console.log("Staff Current View", viewname);
+     //console.log("Staff Current View", viewname);
     staff.current_view = viewname;
     if ((viewname == 'periods' || viewname == 'months')){ staffperiods.gettbldata();staffmonths.gettbldata(); }
     if (viewname == 'basedata'){ }
@@ -363,7 +363,7 @@ let staff ={
   getnfcuid: function(){
     showdataloaddlg('','<div class="xxlarge">{{ lbl.waitmsg }}</div>');
     postData('db.php',{"cl":"TimeTracker","fn":"get_tag_timetracker","schema":schemata,"id_staff":staff.current_id}).then(data => {
-      console.log("Get tracker id",data.result.data);
+      //console.log("Get tracker id",data.result.data);
       //console.log("XY",data.result.data.data['output'][0]);
       if (data.result.data.data['output'][0]['id']){
         document.getElementById("nfcuid").value=data.result.data.data['output'][0]['id'];
index a3ff812..ba8e9ef 100644 (file)
@@ -88,7 +88,7 @@ let staffcontract = {
         // if (data.result.data.defaultfreedays){
         //   data.result.data.defaultfreedays = JSON.parse(data.result.data.defaultfreedays);
         // }
-        console.log("SC",data);
+        //("SC",data);
         dataform.fillformbydataclass2("staffcontract",staffcontract.choices,data.result.data);
         app.viewdialog("staffcontract");
       });
@@ -129,7 +129,7 @@ let staffcontract = {
     }
     flds["fn"] ="saveform";flds["table"]="staffcontract";
     flds["schemata"]=schemata;
-    console.log(flds);
+    //console.log(flds);
     postData("db.php",flds).then(data => {
       staffcontract.gettbldata();
       staffvacancy.gettblyeardata();
index 5097e24..b30ce2e 100644 (file)
@@ -47,9 +47,9 @@ let staffmonths = {
     staffmonths.tbl.on("rowContext",function(e, row){e.preventDefault();});
   },
   gettbldata: function(){
-    console.log("stafftable data");
+    //console.log("stafftable data");
     postData("db.php",{ "cl":"Period","fn":"getMonthsByStaff","schema":schemata,"id_staff":staff.current_id,"id_groups":'{{session.staffgroups}}'}).then(data => {
-      console.log("staffdata",data);
+      //console.log("staffdata",data);
       staffmonths.tbl.setData(data.result.data);
     });
   },
@@ -68,7 +68,7 @@ let staffmonths = {
     // for (var i in udata){
     //     rpids.push(udata[i].id_reportperiod);
     // }
-    console.log("PDF for staff:" + staff.current_id + " Period: " +udata[0].id_reportperiod);
+    //console.log("PDF for staff:" + staff.current_id + " Period: " +udata[0].id_reportperiod);
     if (staff.current_id && udata[0]) {
       report.generate('pot',{"schemata":schemata,"id_staff":staff.current_id,"id_period":udata[0].id_reportperiod});
     }
index 4e04c87..365f4a2 100644 (file)
@@ -58,7 +58,7 @@ let staffperiods = {
     staffperiods.tbl.on("rowContext",function(e, row){e.preventDefault();});
   },
   gettbldata: function(){
-    console.log("stafftable data");
+    //console.log("stafftable data");
     postData("db.php",{ "cl":"Period","fn":"getPeriodsByStaff","schema":schemata,"id_staff":staff.current_id,"id_groups":'{{session.staffgroups}}'}).then(data => {
       //console.log("staffdata",data);
       staffperiods.tbl.setData(data.result.data);
@@ -85,7 +85,7 @@ let staffperiods = {
     // for (var i in udata){
     //     rpids.push(udata[i].id_reportperiod);
     // }
-    console.log("PDF for staff:" + staff.current_id + " Period: " +udata[0].id_reportperiod);
+    //console.log("PDF for staff:" + staff.current_id + " Period: " +udata[0].id_reportperiod);
     if (staff.current_id && udata[0]) {
       report.generate('pot',{"schemata":schemata,"id_staff":staff.current_id,"id_period":udata[0].id_reportperiod});
     }
index 6ac9e25..15e7729 100644 (file)
@@ -105,7 +105,7 @@ let staffvacancy = {
     //console.log("MD",yeardate);
     // postData("db.php", { "get": "getStaffVacancy","schemata":schemata,"id":staff.current_id}).then(data => {
     postData("db.php",{"cl":"Staff","fn":"getStaffVacancyCol","schema":schemata,"date":'',"id_staff":staff.current_id}).then(data => {
-      console.log("Data REsult",data.result);
+      //console.log("Data REsult",data.result);
       staffvacancy.tbl.setData(data.result.data);
     });
     // postData("db.php", { "get": "getStaffVacancy","schemata":schemata,"id":staff.current_id}).then(data => {
index 46303e6..d324034 100644 (file)
@@ -138,12 +138,12 @@ let timeclock = {
   // });\r
 \r
   timeclock.tbl.on("cellDblClick",function(e, cell){\r
-    console.log("DBLCLICK",cell._cell.column.field,cell._cell.row.data);\r
+    //console.log("DBLCLICK",cell._cell.column.field,cell._cell.row.data);\r
     \r
     if (/[time|exit|entry]$/.test(cell._cell.column.field)){\r
       let wd = cell._cell.column.field.substr(0,3);\r
       let wdate = timeclock.weekdates[wd];\r
-      console.log("Datum",wd,timeclock.weekdates,cell._cell.column.field.substr(1,3),wdate);\r
+      //console.log("Datum",wd,timeclock.weekdates,cell._cell.column.field.substr(1,3),wdate);\r
       let stname = cell._cell.row.data.staffname;\r
       // let cday ={"id":cell._cell.row.data.id_staff + "_" + wdate,\r
       //             "id_staff":cell._cell.row.data.id_staff,\r
@@ -152,7 +152,7 @@ let timeclock = {
       //           };\r
       //           console.log(cday);\r
           postData("db.php",{ "cl":"Period","fn": "getPeriodDays","schema":schemata,"date_start":wdate,"date_end":wdate,"id_staff":cell._cell.row.data.id_staff}).then(daydata => {\r
-            console.log("Daydata",daydata);\r
+            //console.log("Daydata",daydata);\r
               daydata.result.data[0].staffname=stname;\r
               periodday.edit(daydata.result.data[0],timeclock.gettbldata);\r
                 });\r
@@ -216,7 +216,7 @@ let timeclock = {
     let date = document.getElementById("weekselect").value;\r
     let monday = moment(date).startOf('week').format('YYYY-MM-DD');\r
     let sunday = moment(date).endOf('week').format('YYYY-MM-DD');\r
-    console.log("M:" +monday + "- Date:"+ date + " - S:" + sunday);\r
+    //console.log("M:" +monday + "- Date:"+ date + " - S:" + sunday);\r
     timeclock.gettbldata();\r
   },\r
   preDay: function(){\r
@@ -234,7 +234,7 @@ let timeclock = {
   loadDay: function(){\r
     let date = document.getElementById("dayselect").value;\r
     let daydate = moment(date).format('YYYY-MM-DD');\r
-    console.log("DAY:" +daydate);\r
+    //console.log("DAY:" +daydate);\r
     timeclock.getDayTblData();\r
   }\r
 }\r
index cfa678a..bbd63da 100644 (file)
@@ -44,7 +44,7 @@ let app = {
       if (nlang != 'fr' && nlang != 'de'){ nlang='de';}
         var lbldata = document.getElementsByClassName("lbl");
         for (var l=0;l<lbldata.length;l++){
-          console.log(lbldata[l].dataset.lbl);
+          //console.log(lbldata[l].dataset.lbl);
           lbldata[l].innerHTML=lang[nlang][lbldata[l].dataset.lbl];
           
         }
index 230fa10..e4597c7 100644 (file)
@@ -6,12 +6,12 @@ let usersystem = {
   },
   readDir: function(dir){
     files = fs.readdirSync(os.datapath() + dir);
-    console.log("Dir parse:" + dir,JSON.stringify(files));
+    //console.log("Dir parse:" + dir,JSON.stringify(files));
     return files;
   },
   setPref: function(key,data){
       
-      console.log("Set Pref",key,data);
+      //console.log("Set Pref",key,data);
       if ((typeof data == 'object') || (typeof data == 'array')){
           data = JSON.stringify(data);
       }
@@ -19,7 +19,7 @@ let usersystem = {
       return result;
   },
   getPref: function(key){
-      console.log("get Pref key",key);
+      //console.log("get Pref key",key);
     //console.log("getPreference:" + this.profilepath()  + key + ".json");
       let data = null;
       if (fs.existsSync(this.dataPath()  + key + ".json")){
@@ -30,7 +30,7 @@ let usersystem = {
           }
           return data;
       }
-      console.log("get Pref data",data);
+      //("get Pref data",data);
       return data;
   },
 }
\ No newline at end of file
index aa356f7..d7f9958 100644 (file)
@@ -4,7 +4,7 @@ let shell = {
   scanwlans: function(){
     const scanwlan = spawn('bash', ['/home/pot/bin/scanwlan.sh','get']);
     scanwlan.stdout.on('data', (data) => {
-      console.log(`scanwlan stdout: ${data}`);
+      //console.log(`scanwlan stdout: ${data}`);
     });
 
     scanwlan.stderr.on('data', (data) => {
@@ -12,13 +12,13 @@ let shell = {
     });
 
     scanwlan.on('close', (code) => {
-      console.log(`scanwlan exit code ${code}`);
+      //console.log(`scanwlan exit code ${code}`);
     });
   },
   netstatus: function(){
     const netstatus = spawn('bash', ['ip --json addr show']);
     netstatus.stdout.on('data', (data) => {
-      console.log(`netstatus stout: ${data}`);
+      //console.log(`netstatus stout: ${data}`);
     });
 
     netstatus.stderr.on('data', (data) => {
@@ -26,13 +26,13 @@ let shell = {
     });
 
     netstatus.on('close', (code) => {
-      console.log(`netstatus: exit code ${code}`);
+      //console.log(`netstatus: exit code ${code}`);
     });
   },
   savewlan: function(ssid,psk){
     const netstatus = spawn('bash', ['/home/pot/bin/savewlan.sh','"'+ ssid+'"',psk]);
     netstatus.stdout.on('data', (data) => {
-      console.log(`netstatus stout: ${data}`);
+      //console.log(`netstatus stout: ${data}`);
     });
 
     netstatus.stderr.on('data', (data) => {
@@ -40,13 +40,13 @@ let shell = {
     });
 
     netstatus.on('close', (code) => {
-      console.log(`netstatus: exit code ${code}`);
+      //console.log(`netstatus: exit code ${code}`);
     });
   },
   shutdown: function(){
     const sh_shutdown = spawn('bash', ['/home/pot/bin/shutdown.sh']);
     sh_shutdown.stdout.on('data', (data) => {
-      console.log(`sh_shutdown stout: ${data}`);
+      //console.log(`sh_shutdown stout: ${data}`);
     });
 
     sh_shutdown.stderr.on('data', (data) => {
@@ -54,13 +54,13 @@ let shell = {
     });
 
     sh_shutdown.on('close', (code) => {
-      console.log(`sh_shutdown: exit code ${code}`);
+      //console.log(`sh_shutdown: exit code ${code}`);
     });
   },
   reboot: function(){
     const sh_reboot = spawn('bash', ['/home/pot/bin/reboot.sh']);
     sh_reboot.stdout.on('data', (data) => {
-      console.log(`sh_reboot stout: ${data}`);
+      //console.log(`sh_reboot stout: ${data}`);
     });
 
     sh_reboot.stderr.on('data', (data) => {
@@ -68,14 +68,14 @@ let shell = {
     });
 
     sh_reboot.on('close', (code) => {
-      console.log(`sh_reboot: exit code ${code}`);
+      //console.log(`sh_reboot: exit code ${code}`);
     });
   },
   turnscreen: function(){
     const sh_turnscreen = spawn('bash', ['/home/pot/bin/turnscreen.sh']);
     sh_turnscreen.stdout.on('data', (data) => {
       //alert(`"DATA" + ${data}`);
-      console.log(`sh_turnscreen stout: ${data}`);
+      //console.log(`sh_turnscreen stout: ${data}`);
     });
 
     sh_turnscreen.stderr.on('data', (data) => {
@@ -83,14 +83,14 @@ let shell = {
     });
 
     sh_turnscreen.on('close', (code) => {
-      console.log(`sh_turnscreen: exit code ${code}`);
+      //console.log(`sh_turnscreen: exit code ${code}`);
     });
   },
   nfcimportid: function(){
     const sh_nfcimport = spawn('bash', ['/home/pot/bin/nfcimportid.sh']);
-    console.log("NFC import started!")
+    //console.log("NFC import started!")
     sh_nfcimport.stdout.on('data', (data) => {
-      console.log(`sh_nfcimport stout: ${data}`);
+      //console.log(`sh_nfcimport stout: ${data}`);
       let nuid=data.toString().replace(/^UID:/,'').replace(/\n/g,'');
      if (nuid != ""){
       timeclock.setbadgetouser(nuid);
@@ -107,14 +107,14 @@ let shell = {
     });
 
     sh_nfcimport.on('close', (code) => {
-      console.log(`sh_nfcimport: exit code ${code}`);
+      //console.log(`sh_nfcimport: exit code ${code}`);
     });
   },
   nfcunload: function(){
     const sh_nfcunload = spawn('bash', ['/home/pot/bin/nfcunload.sh']);
     timeclock.current_staff_id='';
     sh_nfcunload.stdout.on('data', (data) => {
-      console.log(`sh_nfcunload stout: ${data}`);
+      //console.log(`sh_nfcunload stout: ${data}`);
     });
 
     sh_nfcunload.stderr.on('data', (data) => {
@@ -122,18 +122,18 @@ let shell = {
     });
 
     sh_nfcunload.on('close', (code) => {
-      console.log(`sh_nfcunload: exit code ${code}`);
+      //console.log(`sh_nfcunload: exit code ${code}`);
     });
   },
   nfcwaitbadge: function(){
     const sh_nfcwaitbadge = spawn('bash', ['/home/pot/bin/nfcreadbadge.sh']);
     timeclock.current_staff_id='';
     sh_nfcwaitbadge.stdout.on('data', (data) => {
-      console.log(`sh_nfcwaitbadge stout: ${data}`);
+      //console.log(`sh_nfcwaitbadge stout: ${data}`);
       timeclock.current_staff_id=data.toString().replace(/^STAFFID:/,'').replace(/\n/g,'');
-      console.log("C St:->" + timeclock.current_staff_id + "<-",timeclock.current_staff_id.length);
+      //console.log("C St:->" + timeclock.current_staff_id + "<-",timeclock.current_staff_id.length);
       //timeclock.userdata=usersystem.getPref('staff/' + timeclock.current_staff_id);
-      //console.log("Staffdata from file:",JSON.stringify(timeclock.userdata));
+      ////console.log("Staffdata from file:",JSON.stringify(timeclock.userdata));
       if (timeclock.current_staff_id.length > 35){
         timeclock.loadtimetrack();
       } else {
@@ -149,7 +149,7 @@ let shell = {
     });
 
     sh_nfcwaitbadge.on('close', (code) => {
-      console.log(`sh_nfcwaitbadge: exit code ${code}`);
+      //console.log(`sh_nfcwaitbadge: exit code ${code}`);
     });
   }
 }
index d4ab683..8d998c0 100644 (file)
@@ -11,7 +11,7 @@ let db = {
   },
   query: function(sql){
     if (preferences.debug==1){
-      console.log("query sql:",sql);
+      //console.log("query sql:",sql);
     }
     return new Promise((resolve, reject) => {
       db.dbh.get(`${sql}`, (err, row) => {
@@ -25,7 +25,7 @@ let db = {
   },
   queryarray: function(sql){
     if (preferences.debug==1){
-      console.log("queryarray sql:",sql);
+      //console.log("queryarray sql:",sql);
     }
     return new Promise((resolve, reject) => {
       let queries = [];
@@ -49,7 +49,7 @@ let db = {
   },
   querybykey: function(key,sql){
     if (preferences.debug==1){
-      console.log("querybykey sql:",sql);
+      //console.log("querybykey sql:",sql);
     }
     return new Promise((resolve, reject) => {
       let ret = {}
@@ -70,7 +70,7 @@ let db = {
   },
   exec: function(sql,callback){
     if (preferences.debug==1){
-      console.log("exec sql:",sql);
+      //console.log("exec sql:",sql);
     }
     return new Promise((resolve, reject) => {
       
index 53d4015..c43399d 100644 (file)
@@ -1,6 +1,6 @@
 let syncdata ={
   track: function(id){
-    console.log("Send track id " + id);
+    //console.log("Send track id " + id);
     var child = spawn('bash', ['/home/pot/bin/sendtrack.sh',id], {
       detached: true,
       stdio: [ 'ignore', 'ignore', 'ignore' ]
@@ -8,7 +8,7 @@ let syncdata ={
     child.unref();
   },
   sendnfcuid: function(staffid){
-    console.log("Send badge id_staff " + staffid);
+    //console.log("Send badge id_staff " + staffid);
     var child = spawn('bash', ['/home/pot/bin/sendnfcuid.sh',staffid], {
       detached: true,
       stdio: [ 'ignore', 'ignore', 'ignore' ]
index 82903bb..acabe9c 100644 (file)
@@ -14,7 +14,7 @@ let timeclock = {
   intervaltime: preferences.timeout,
   loadscreensaver: function(){
     timeclock.lang = "fr";
-    console.log("Load screensaver");
+    ////console.log("Load screensaver");
     timeclock.currentpanel = 'screensaver';
     timeclock.currentuser= null;
     shell.nfcunload();
@@ -31,7 +31,7 @@ let timeclock = {
     setTimeout('timeclock.loadscreensaver()',3000);
   },
   loadusers: function(){
-    console.log("Load users");
+    ////console.log("Load users");
     timeclock.currentpanel = 'users';
     timeclock.current_staff_id=null;
     if (preferences.pinview == "1"){
@@ -49,7 +49,7 @@ let timeclock = {
     shell.nfcunload();
     let ulist = "";
     db.queryarray("select * from (select st.id,coalesce(st.prename,'') as prename,coalesce(st.surname,'') as surname, count(fp.id) as badgecount,st.pin, fp.id as nfcuid from staff st left join badges fp on (st.id=fp.id_staff) group by st.id order by st.surname,st.prename) where badgecount > 0 order by surname,prename;").then(data => {
-      console.log("userdata",data);
+      ////console.log("userdata",data);
       timeclock.userdata = data;
       if (timeclock.userdata.length > 24){
         document.getElementById("mnubtn_usersprev").style.display = 'block';
@@ -69,10 +69,10 @@ let timeclock = {
   
   prevusers: function(){
     let ulx = document.getElementsByClassName("userlistdata");
-    console.log(ulx);
+    ////console.log(ulx);
     if (timeclock.currentuserlist == 1 ){ return false;}
     for (u=0;u<ulx.length;u++){
-      console.log(u);
+      //console.log(u);
       ulx[u].style.display = 'none';
     }
     timeclock.currentuserlist=timeclock.currentuserlist-1;
@@ -81,10 +81,10 @@ let timeclock = {
   },
   nextusers: function(){
     let ulx = document.getElementsByClassName("userlistdata");
-    console.log(ulx.length);
+    //console.log(ulx.length);
     if (timeclock.currentuserlist == ulx.length ){ return false;}
     for (u=0;u<ulx.length;u++){
-      console.log(u);
+      //console.log(u);
       ulx[u].style.display = 'none';
     }
     timeclock.currentuserlist=timeclock.currentuserlist+1;
@@ -107,9 +107,9 @@ let timeclock = {
       for (i=0; i < data.length;i++){
         var uadata = '<li class="display-container xlarge">'+
         '<span>'+ data[i].surname + ' ' + data[i].prename +'<br/>('+data[i].nfcuid+')</span>';
-        console.log("has pin:",data[i].pin,preferences.pinview);
+        //console.log("has pin:",data[i].pin,preferences.pinview);
         if ((preferences.pinview == "1") && (data[i].pin != null)){
-          console.log("set pin button!");
+          //console.log("set pin button!");
           uadata += '<span onclick="timeclock.cleanpincode(\''+ data[i].id + '\');" class="button display-left2 xxlarge border red" style="font-weight: bold; width:120px;">&times;Pin</span>';
         }
         uadata += '<span onclick="timeclock.removebadge(\''+ data[i].id + '\');" class="button display-left xxlarge border red" style="font-weight: bold; width:120px;">&times;</span>'+
@@ -167,8 +167,8 @@ let timeclock = {
       
       timeclock.current_index = uindex;
 
-      console.log("Current Index",timeclock.current_index);
-      console.log("Current Userdata",timeclock.userdata[timeclock.current_index]);
+      //console.log("Current Index",timeclock.current_index);
+      //console.log("Current Userdata",timeclock.userdata[timeclock.current_index]);
       timeclock.selectfield('pincode','pincode2');
       document.getElementById("pincode").value="";
       document.getElementById("pincode2").value="";
@@ -193,8 +193,8 @@ let timeclock = {
   checkuserpin: function(){
     timeclock.stopCheckIdle();
     let pcode = document.getElementById("pincode").value;
-    console.log(pcode +" = " + preferences.pincode );
-    console.log('CIndex',timeclock.current_index);
+    //console.log(pcode +" = " + preferences.pincode );
+    //console.log('CIndex',timeclock.current_index);
     if (document.getElementById("pincode2").style.display == 'inline'){
       if (document.getElementById("pincode2").value != document.getElementById("pincode").value){
         document.getElementById("pincode").value = "";
@@ -211,7 +211,7 @@ let timeclock = {
       }
     }
     else if ((timeclock.current_index == null) &&  (pcode == preferences.pincode)){
-      //console.log("goto badge registration");
+      ////console.log("goto badge registration");
       app.viewpanel("admin");
     } else if ((timeclock.current_index != null) && (timeclock.userdata[timeclock.current_index].pin = document.getElementById("pincode").value)){
       timeclock.current_staff_id = timeclock.userdata[timeclock.current_index].id;
@@ -235,7 +235,7 @@ let timeclock = {
     document.getElementById("btntrackout").disabled = true;
     var sql = "select tt.id,st.id as id_staff,st.lang,st.isenabled,date('now','localtime') as today,strftime('%w',date('now','localtime')) as weekday,date('now','-1 day','localtime') as yesterday,strftime('%H:%M',time('now','localtime')) as timenow,st.prename,st.surname,st.monstart,st.monend,st.tuestart,st.tueend,st.wedstart,st.wedend,st.thustart,st.thuend,st.fristart,st.friend,st.satstart,st.satend,st.sunstart,st.sunend,tt.daydate,tt.stamp_in,tt.stamp_out from staff st left join timetracks tt on (st.id=tt.id_staff) where st.id='" + timeclock.current_staff_id + "' or tt.stamp_in=(select max(stamp_in) as stamp_in from timetracks where id_staff='" + timeclock.current_staff_id + "') order by tt.stamp_in DESC LIMIT 1;";
     db.query(sql).then(trdata => {
-      console.log("userdata",trdata);
+      //console.log("userdata",trdata);
       
       let ulang = timeclock.lang;
       if (trdata.lang != null){
@@ -289,7 +289,7 @@ let timeclock = {
       app.viewpanel('timetrack');
       timeclock.startCheckIdle();
     }).catch(e => {
-      console.log("SQL error: " + e);
+      //console.log("SQL error: " + e);
       document.getElementById("btntrackin").disabled = false;
       timeclock.startCheckIdle();
       return false;
@@ -307,9 +307,9 @@ let timeclock = {
           sql = "UPDATE timetracks SET stamp_out=datetime('now','localtime') where id_staff='"+ timeclock.current_staff_id+"' and id='"+timeclock.lasttrack.id+"';";
         }
         
-        //console.log("SET TrackSQL",sql);
+        ////console.log("SET TrackSQL",sql);
         db.exec(sql).then(data => {
-          console.log("LANG:" + timeclock.lang);
+          //console.log("LANG:" + timeclock.lang);
           var msgreg = lang[timeclock.lang].msgtrackregistered;
           timeclock.loadstatus(msgreg);
           syncdata.track(syncid);
index 4cc51e2..3ccd1fe 100644 (file)
@@ -56,9 +56,9 @@ let vacmonthly = {
   },
   gettbldata: function(){
     let monthdate = DateTime.fromSQL(document.getElementById("monthselect").value).toISODate();
-    console.log("MD",monthdate);
+    //console.log("MD",monthdate);
     postData("db.php",{"cl":"Staff","fn":"getStaffVacancyByMonth","schema":schemata,"date":monthdate}).then(data => {
-      console.log("Data REsult",data.result);
+      //console.log("Data REsult",data.result);
      this.tbl.setData(data.result.data);
     });
   },