v20220120
authorKilian Saffran <ksaffran@dks.lu>
Thu, 20 Jan 2022 14:28:04 +0000 (15:28 +0100)
committerKilian Saffran <ksaffran@dks.lu>
Thu, 20 Jan 2022 14:28:04 +0000 (15:28 +0100)
13 files changed:
app/db.php
app/lib/POT/Company.php
app/lib/POT/Staff.php
app/lib/lang/de.php
app/lib/lang/fr.php
app/lib/version.php
app/log/sql.log
app/pwa/manifest.webmanifest
app/tmpl/module/admin/staffgroups.js
app/tmpl/module/admin/users.js
app/tmpl/module/staff.html
app/tmpl/module/staff/staff.js
app/tmpl/module/staff/staffperiods.js

index 7ebf970..143f740 100644 (file)
       elseif ($p["get"] == "lastperioddates"){
         $hres = $period->getLastPeriodDates($schema);
       }
-    } elseif (preg_match('/company$|companiesdata$|staffgroups$|staffgroup$|sectors$|allschemalist$|companysize$|vacancydays$|gvacancytypes$|sectordata$/',$p["get"])){
+    } elseif (preg_match('/company$|companiesdata$|staffgroup$|sectors$|allschemalist$|companysize$|vacancydays$|gvacancytypes$|sectordata$/',$p["get"])){
       $cp = new Company($db,$cfg);
       if ($p["get"] == 'companiesdata'){
         $hres = $cp->getCompaniesData();
       } elseif ($p["get"] == 'company'){
         $hres = $cp->getCompany($schema);
-      } elseif ($p["get"] == 'staffgroups'){
-        $hres = $cp->getStaffGroups($schema);
       } elseif ($p["get"] == 'staffgroup'){
         $hres = $cp->getStaffGroup($schema,$db->securetext($p["id"]));
       } elseif ($p["get"] == 'sectors'){
index e00aad1..1fd8a25 100644 (file)
@@ -96,10 +96,13 @@ function  getCompany($schema){
   return $cp;
 }
 
-function  getStaffGroups($schema){
-   
-   $sql ="select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM ".$schema.".staffgroups sg LEFT JOIN ".$schema.".staff st ON (st.id_staffgroup = sg.id and st.isdeleted IS NULL)
-    GROUP BY sg.id ORDER BY sg.groupname;";
+function  getStaffGroups($schema,$id_groups=null){
+  $wgroups ="";
+  if (($id_groups != null) && (strlen($id_groups) >= 3)){
+    $tmpgrp = json_decode($id_groups);
+    $wgroups .= " and sg.id in ('".implode("','",$tmpgrp)."') ";
+  }
+   $sql ="select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM ".$schema.".staffgroups sg LEFT JOIN ".$schema.".staff st ON (st.id_staffgroup = sg.id) WHERE st.isdeleted IS NULL ".$wgroups." GROUP BY sg.id ORDER BY sg.groupname;";
   return $this->dbh->queryarray($sql);
 }
 
index 1c0ef6f..7dac35e 100644 (file)
@@ -147,10 +147,12 @@ $wgroups = "";
     $tmpgrp = json_decode($id_groups);
     $wgroups .= " and stg.id in ('".implode("','",$tmpgrp)."') ";
   }
-  $sql = "select ttr.*, st.* ,stg.groupname,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') AS staffname from ".$schema.".staff st 
+  $sql = "select ttr.*, st.* ,stg.groupname,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') AS staffname,sc.staffstatus from ".$schema.".staff st 
 LEFT JOIN ".$schema.".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 ".$schema.".staffcontract 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='".$schema."') ttr
-where st.isdeleted is null ".$wgroups." order by groupname,surname,prename;";
+where st.isdeleted is null ".$wgroups." order by groupname,st.staffnumber,surname,prename;";
   
   //print STDERR "XX:".$sql."\n";
   return $this->dbh->queryarray($sql);
index ea6cc5d..e6e77a6 100644 (file)
   "maxdays" => "Arbeits-<br/>tage",\r
   "difference" => "Differenz",\r
   "vacmonthly" => "monatlicher Urlaubsbericht",\r
-  "excelexport" => "XSLX Export"\r
+  "excelexport" => "XSLX Export",\r
+  "staffcurrent" => "aktuelle Mitarbeiter",\r
+  "staffall" => "alle Mitarbeiter",\r
+  "staffpast" => "ehemalige Mitarbeiter",\r
+  "stafffutur" => "zukünftige Mitarbeiter"\r
  ); ?>
\ No newline at end of file
index 8240fed..5f7cd45 100644 (file)
   "maxdays" => "jours<br/>de travail",
   "difference" => "différence",
   "vacmonthly" => "Rapport Congés mensuelles",
-  "excelexport" => "Export XLSX"
+  "excelexport" => "Export XLSX",
+  "staffcurrent" => "salariés courrants",
+  "staffall" => "tous les salariés",
+  "staffpast" => "anciens salariés",
+  "stafffutur" => "futur salariés"
  ); ?>
\ No newline at end of file
index 125a0ff..fc8f1a4 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-$cfg["appversion"] = '1.11.5';
+$cfg["appversion"] = '1.12.0';
   if ($cfg["debug"] == 1){
     $cfg["appversion"] = date('YmdHi');//$cfg["version"];
   } 
index 74fd04b..45e72f1 100644 (file)
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e'  
-  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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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 alicehartmann.staffgroups sg LEFT JOIN alicehartmann.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 alicehartmann.timetrackerconfig order by trackername
+QUERYARRAY: select ttr.*, st.* ,stg.groupname,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') AS staffname,sc.staffstatus from alicehartmann.staff st 
+LEFT JOIN alicehartmann.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 alicehartmann.staffcontract 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='alicehartmann') ttr
+where st.isdeleted is null  order by groupname,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 kajiwara.workplans wp
+   FROM alicehartmann.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 kajiwara.reportperiod rp ORDER BY startdate, enddate;
 QUERYARRAY: SELECT id,vacancyname,color
-   FROM kajiwara.vacancytypes where isworktime is null or isworktime=false order by vacancyname;
+   FROM alicehartmann.vacancytypes where isworktime is null or isworktime=false order by vacancyname;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select id from kajiwara.staff where isdeleted is null;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','11796d0b-6de0-c137-4a20-4ef48c92e6e5') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '11796d0b-6de0-c137-4a20-4ef48c92e6e5'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '11796d0b-6de0-c137-4a20-4ef48c92e6e5'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','a21bf35f-797d-f9f1-1796-34e3591934bc') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'a21bf35f-797d-f9f1-1796-34e3591934bc'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'a21bf35f-797d-f9f1-1796-34e3591934bc'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='34f850b6-7a29-6900-637e-8c145886000c'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='34f850b6-7a29-6900-637e-8c145886000c')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='34f850b6-7a29-6900-637e-8c145886000c' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','34f850b6-7a29-6900-637e-8c145886000c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='34f850b6-7a29-6900-637e-8c145886000c'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='34f850b6-7a29-6900-637e-8c145886000c'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '34f850b6-7a29-6900-637e-8c145886000c'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='34f850b6-7a29-6900-637e-8c145886000c' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '34f850b6-7a29-6900-637e-8c145886000c'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','0be74e54-4c4e-3801-caa8-0031df35742a') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0be74e54-4c4e-3801-caa8-0031df35742a'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0be74e54-4c4e-3801-caa8-0031df35742a'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','4971b1a7-555b-8552-92a2-e8fc85fa6861') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4971b1a7-555b-8552-92a2-e8fc85fa6861'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4971b1a7-555b-8552-92a2-e8fc85fa6861'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='520:00:00' where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','96623b4b-5bb4-0822-ce31-1e2a0ac19e9d') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '30:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff, null as payedpause, 
- '06:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '06:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','4dbf2328-c00b-0174-5604-67088bf87e6e') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='780:00:00' where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4dbf2328-c00b-0174-5604-67088bf87e6e'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '30:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff, null as payedpause, 
- '06:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '06:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4dbf2328-c00b-0174-5604-67088bf87e6e'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='520:00:00' where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','0920d9fa-f53c-6244-1859-43c37159cca3') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='520:00:00' where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0920d9fa-f53c-6244-1859-43c37159cca3'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0920d9fa-f53c-6244-1859-43c37159cca3'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','97ac0b46-1e0a-8389-22cb-39c1dfd89596') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '97ac0b46-1e0a-8389-22cb-39c1dfd89596'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-04-30')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-05-01'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and (daydate > date('2022-05-01') or daydate < date('2021-11-01')) 
-     OR (id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' AND  daydate not between date('2021-11-01') and date('2022-05-01'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '97ac0b46-1e0a-8389-22cb-39c1dfd89596'  
-  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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e'  
-  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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select max(startdate) as startdate,max(enddate) as enddate,case when date(max(startdate) - interval '1 year') < current_date then null else date(max(startdate) - interval '1 year') end as alloweddate from kajiwara.reportperiod;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select reportperiodunit,reportperiodlength,reportperiodstart,periodtypes,subinterval from public.companies where schemata='kajiwara';
-QUERY: select case when max(enddate) is null then date('2021-11-01') else date(max(enddate) + interval '1 day') end as rpstart from kajiwara.reportperiod;
-QUERY: select date(date('2022-05-01') + interval  '6 months' -  interval '1 day' ) as rpend;
-QUERY: select id from kajiwara.reportperiod order by startdate DESC,enddate LIMIT 1;
-QUERY: INSERT INTO kajiwara.reportperiod (startdate, enddate, id_parentreportperiod,periodtype,subinterval) VALUES('2022-05-01','2022-10-31','3295dc17-be6c-3f8a-d5e0-b44a5de1277e','<15','1 month') returning id;
-QUERYARRAY: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-  select '883c34d8-cfea-aa41-57c0-85fa8ca0b222' as id_reportperiod,id_staff from kajiwara.staffcontract sc 
-left join kajiwara.staff st on (st.id=sc.id_staff)
-where st.isdeleted is null and sc.enddate is null or ( sc.startdate between date('2022-05-01') and date('2022-10-31')) or (sc.enddate between date('2022-05-01') and date('2022-10-31')) on conflict on constraint uniq_staffreportperiod_cal do nothing returning id_staff;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-) over (order by startdate,enddate) as prevperiod,id from ( 
-    select srp.id_reportperiod ,startdate,enddate,rp.id from kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 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.schemaaccess),cp.company,
-    us.schemaaccess AS schemaname,
-    cp.datasetname
-   FROM ( SELECT json_array_elements_text(users.schemaaccess) AS schemaaccess
-     FROM users WHERE users.isdeleted IS null) us
-     LEFT JOIN companies cp ON cp.schemata = us.schemaaccess AND cp.isdeleted IS NULL;
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-01')));
-QUERYARRAY: SELECT id,startdate,enddate,id_parentreportperiod,periodtype,subinterval,viewpartunempl,to_char(startdate,'MM/YY') || ' - ' || to_char(enddate,'MM/YY') as dspperiod FROM kajiwara.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 kajiwara.workplans wp
-  ORDER BY wp.isdefault, wp.workplan;
-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.staff where isdeleted is null;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5')) between startdate and enddate order by startdate,enddate;
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by startdate,enddate;
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','11796d0b-6de0-c137-4a20-4ef48c92e6e5') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-01')));
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by startdate,enddate;
-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.id;
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','11796d0b-6de0-c137-4a20-4ef48c92e6e5') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by daydate
-) xsunday) sunresult;
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-01')));
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 *,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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '11796d0b-6de0-c137-4a20-4ef48c92e6e5'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='' order by startdate,enddate;
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='1048:00:00' where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select date(date_trunc('week',date(''))) as firstday , date(date_trunc('week',date('')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-QUERY: select round(cast(((extract(epoch from (current_date + ''::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/ as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'' as id_staff, null as payedpause, 
- '' as  wdcontracthours  
-FROM generate_series( ''::timestamp,''::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='' and (daydate > date('') or daydate < date('')) 
-     OR (id_staff='' AND  daydate not between date('') and date('') AND  daydate not between date('') and date(''));
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5';
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by daydate
-) xsunday) sunresult;
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-01')));
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='' order by daydate
-) xsunday) sunresult;
-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 kajiwara.staffreportperioddays
-                    where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-01')));
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and  pd.daydate between date('2022-05-01') and date('2022-10-31')
-  group by dp.id,dp.payedhours,dp.transferedhourscalc
-  ) rp) csp where csp.id=rpd.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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '11796d0b-6de0-c137-4a20-4ef48c92e6e5'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-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 kajiwara.staffreportperioddays
-                    where id_staff= '' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours=null,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = ''  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '11796d0b-6de0-c137-4a20-4ef48c92e6e5'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'11796d0b-6de0-c137-4a20-4ef48c92e6e5' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '11796d0b-6de0-c137-4a20-4ef48c92e6e5' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='11796d0b-6de0-c137-4a20-4ef48c92e6e5' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '11796d0b-6de0-c137-4a20-4ef48c92e6e5'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','a21bf35f-797d-f9f1-1796-34e3591934bc') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','a21bf35f-797d-f9f1-1796-34e3591934bc') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'a21bf35f-797d-f9f1-1796-34e3591934bc'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='1048:00:00' where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'a21bf35f-797d-f9f1-1796-34e3591934bc'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'a21bf35f-797d-f9f1-1796-34e3591934bc'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'a21bf35f-797d-f9f1-1796-34e3591934bc' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= 'a21bf35f-797d-f9f1-1796-34e3591934bc' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='a21bf35f-797d-f9f1-1796-34e3591934bc' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'a21bf35f-797d-f9f1-1796-34e3591934bc'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='34f850b6-7a29-6900-637e-8c145886000c'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='34f850b6-7a29-6900-637e-8c145886000c')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='34f850b6-7a29-6900-637e-8c145886000c' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','34f850b6-7a29-6900-637e-8c145886000c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='34f850b6-7a29-6900-637e-8c145886000c' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','34f850b6-7a29-6900-637e-8c145886000c') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='34f850b6-7a29-6900-637e-8c145886000c'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='34f850b6-7a29-6900-637e-8c145886000c'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '34f850b6-7a29-6900-637e-8c145886000c'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='34f850b6-7a29-6900-637e-8c145886000c'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='34f850b6-7a29-6900-637e-8c145886000c'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='1048:00:00' where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='34f850b6-7a29-6900-637e-8c145886000c';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '34f850b6-7a29-6900-637e-8c145886000c'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='34f850b6-7a29-6900-637e-8c145886000c' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '34f850b6-7a29-6900-637e-8c145886000c'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'34f850b6-7a29-6900-637e-8c145886000c' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='34f850b6-7a29-6900-637e-8c145886000c' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='34f850b6-7a29-6900-637e-8c145886000c';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='34f850b6-7a29-6900-637e-8c145886000c' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='34f850b6-7a29-6900-637e-8c145886000c' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '34f850b6-7a29-6900-637e-8c145886000c' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='34f850b6-7a29-6900-637e-8c145886000c' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '34f850b6-7a29-6900-637e-8c145886000c'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','0be74e54-4c4e-3801-caa8-0031df35742a') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','0be74e54-4c4e-3801-caa8-0031df35742a') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0be74e54-4c4e-3801-caa8-0031df35742a'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='1048:00:00' where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='0be74e54-4c4e-3801-caa8-0031df35742a';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0be74e54-4c4e-3801-caa8-0031df35742a'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0be74e54-4c4e-3801-caa8-0031df35742a'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0be74e54-4c4e-3801-caa8-0031df35742a' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='0be74e54-4c4e-3801-caa8-0031df35742a';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '0be74e54-4c4e-3801-caa8-0031df35742a' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='0be74e54-4c4e-3801-caa8-0031df35742a' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0be74e54-4c4e-3801-caa8-0031df35742a'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','4971b1a7-555b-8552-92a2-e8fc85fa6861') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','4971b1a7-555b-8552-92a2-e8fc85fa6861') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4971b1a7-555b-8552-92a2-e8fc85fa6861'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='1048:00:00' where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4971b1a7-555b-8552-92a2-e8fc85fa6861'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4971b1a7-555b-8552-92a2-e8fc85fa6861'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4971b1a7-555b-8552-92a2-e8fc85fa6861' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '4971b1a7-555b-8552-92a2-e8fc85fa6861' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='4971b1a7-555b-8552-92a2-e8fc85fa6861' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4971b1a7-555b-8552-92a2-e8fc85fa6861'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='520:00:00' where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='524:00:00' where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '44cbd54f-c0a8-6bc7-dbe7-cdab23bc059f'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','96623b4b-5bb4-0822-ce31-1e2a0ac19e9d') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','96623b4b-5bb4-0822-ce31-1e2a0ac19e9d') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='1048:00:00' where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='96623b4b-5bb4-0822-ce31-1e2a0ac19e9d' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '96623b4b-5bb4-0822-ce31-1e2a0ac19e9d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '30:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff, null as payedpause, 
- '06:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '06:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','4dbf2328-c00b-0174-5604-67088bf87e6e') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '30:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff, null as payedpause, 
- '06:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '06:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','4dbf2328-c00b-0174-5604-67088bf87e6e') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='780:00:00' where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4dbf2328-c00b-0174-5604-67088bf87e6e'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='786:00:00' where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4dbf2328-c00b-0174-5604-67088bf87e6e'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '30:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff, null as payedpause, 
- '06:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '06:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4dbf2328-c00b-0174-5604-67088bf87e6e'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '30:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'4dbf2328-c00b-0174-5604-67088bf87e6e' as id_staff, null as payedpause, 
- '06:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '06:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '4dbf2328-c00b-0174-5604-67088bf87e6e' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='4dbf2328-c00b-0174-5604-67088bf87e6e' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '4dbf2328-c00b-0174-5604-67088bf87e6e'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='520:00:00' where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='524:00:00' where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '6e47c7e0-a43f-9c25-977c-f6fc4bf1d55d'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','0920d9fa-f53c-6244-1859-43c37159cca3') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','0920d9fa-f53c-6244-1859-43c37159cca3') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='520:00:00' where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0920d9fa-f53c-6244-1859-43c37159cca3'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='524:00:00' where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='0920d9fa-f53c-6244-1859-43c37159cca3';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0920d9fa-f53c-6244-1859-43c37159cca3'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0920d9fa-f53c-6244-1859-43c37159cca3'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '20:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'0920d9fa-f53c-6244-1859-43c37159cca3' as id_staff, null as payedpause, 
- '04:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '04:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='0920d9fa-f53c-6244-1859-43c37159cca3';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '0920d9fa-f53c-6244-1859-43c37159cca3' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='0920d9fa-f53c-6244-1859-43c37159cca3' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '0920d9fa-f53c-6244-1859-43c37159cca3'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id from kajiwara.reportperiod order by startdate,enddate;
-QUERYARRAY: select id,startdate,enddate from kajiwara.reportperiod where 
-startdate >= date((select min(startdate) from kajiwara.staffcontract where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596'))
-or date((select min(startdate) from kajiwara.staffcontract where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596')) between startdate and enddate order by startdate,enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('3295dc17-be6c-3f8a-d5e0-b44a5de1277e','97ac0b46-1e0a-8389-22cb-39c1dfd89596') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' group by rp.id);
-EXEC: INSERT INTO kajiwara.staffreportperiod (id_reportperiod, id_staff) 
-    VALUES ('883c34d8-cfea-aa41-57c0-85fa8ca0b222','97ac0b46-1e0a-8389-22cb-39c1dfd89596') on conflict on constraint uniq_staffreportperiod_cal do nothing;
-QUERY: select reportperiodunit,reportperiodlength from public.companies where schemata='kajiwara'
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596'
-    ) scx where startdate < enddate and id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2021-11-01'),date('2022-04-30'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 130 as maxdays,130 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date('2021-11-01') and date('2022-04-30')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-04-30') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-04-30')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=130,contracthours='1040:00:00' where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '97ac0b46-1e0a-8389-22cb-39c1dfd89596'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERYARRAY: select id,weekhours,weekdays,startdate,enddate,defaultfreedays from (
-    select rp.id,case when sc.startdate < rp.startdate then rp.startdate else sc.startdate end as startdate ,
-    case when sc.enddate is null or sc.enddate > rp.enddate then rp.enddate else sc.enddate end as enddate,
-    sc.weekhours,sc.weekdays,sc.defaultfreedays from kajiwara.staffcontract sc
-    cross join kajiwara.reportperiod rp 
-    where sc.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596'
-    ) scx where startdate < enddate and id='883c34d8-cfea-aa41-57c0-85fa8ca0b222' order by startdate,enddate;
-QUERY: select sum(dow) as maxdays from ( select case when date_part('isodow',generate_series) in (6,7) then 0 else 1 end as dow from pg_catalog.generate_series(date('2022-05-01'),date('2022-10-31'),'1 day')) mxdays
-QUERY: select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
-      select 131 as maxdays,131 * (round(cast(((extract(epoch from (current_date + weekhours::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0) /weekdays as numeric) ,2)+0.00) * '01:00:00'::interval as contracthours from (
-      select case when count(daydate) >= weekdays then weekdays else weekdays-count(daydate)-1 end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours from (
-       
-           select id_staff,date(date_trunc('week',daydate)) as calweek,daydate,case when date_part('isodow',daydate)::int4=7 then 1 else null end as sundays
-           from kajiwara.staffreportperioddays 
-           where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date('2022-05-01') and date('2022-10-31')
-      ) wgr
-      left join (
-           select date(date_trunc('week',startdate)) as weekstartdate,startdate,case when enddate is null then date('2022-10-31') else enddate end as enddate,case when enddate is null then date(date_trunc('week',date('2022-10-31')) + interval '6 days') else enddate end as weekenddate,weekdays,weekhours from kajiwara.staffcontract where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596'
-      ) sc  on (wgr.calweek between sc.weekstartdate and sc.weekenddate )   where wgr.daydate between sc.startdate and sc.enddate group by sc.weekhours,sc.weekdays,calweek
-      ) rnddays group by weekhours,weekdays) xx
-EXEC: update kajiwara.staffreportperiod set maxdays=131,contracthours='1048:00:00' where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '97ac0b46-1e0a-8389-22cb-39c1dfd89596'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-EXEC: insert into kajiwara.staffvacancyyear (id_staff,vacyear)
-  select id_staff,to_char(daydate,'YYYY')::int4 as vyear from kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' group by id_staff,vyear order by id_staff,vyear
-  on conflict on constraint staffvacancyyear_id_staff_vacyear_key do nothing;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by rp.startdate,rp.enddate)
-    sper ) prp where id='3295dc17-be6c-3f8a-d5e0-b44a5de1277e'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days'))
-  ) preds) 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 kajiwara.staffreportperioddays 
-where daydate between date('2021-11-01') and date('2022-04-30') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2021-11-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and sr.daydate between  date('2021-11-01')  and date(date_trunc('week',date('2022-04-30')) - 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 kajiwara.staffreportperioddays
-                    where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2021-11-01'))) and date(date_trunc('week',date('2022-04-30')) + interval '6 days')
-                    --where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date('2021-11-01') and date('2022-04-30')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '3295dc17-be6c-3f8a-d5e0-b44a5de1277e')
-  where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and  pd.daydate between date('2021-11-01') and date('2022-04-30')
-  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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '97ac0b46-1e0a-8389-22cb-39c1dfd89596'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
-QUERY: select date(date_trunc('week',min(startdate))) as startdatealt,min(startdate) as startdate,max(enddate) as enddate from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-QUERY: select payedpauses,reportperiodunit from public.companies where schemata ='kajiwara'
-QUERYARRAY: select case when sc.startdate > rp.minstartdate then sc.startdate else rp.minstartdatealt end as startdate ,
-case when sc.enddate is null or sc.enddate > rp.maxenddate then rp.maxenddate else sc.enddate end as enddate,
-sc.startdate as scstart,sc.enddate as scend,rp.minstartdate as minperiodstart,rp.maxenddate as maxperiodend,
-sc.weekhours,sc.weekdays from kajiwara.staffcontract sc
-left join (select date(date_trunc('week',min(startdate))) as minstartdatealt,min(startdate) as minstartdate,max(enddate) as maxenddate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff from kajiwara.reportperiod) rp on rp.id_staff=sc.id_staff 
-where sc.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by startdate,enddate;
-QUERY: select date(date_trunc('week',date('2021-11-01'))) as firstday , date(date_trunc('week',date('2022-10-31')) + interval '6 days') as lastday
-QUERY: select round(cast(((extract(epoch from (current_date + '40:00:00'::interval)::timestamp) - extract(epoch from current_date::timestamp))/3600.0)/5 as numeric) ,2) * '01:00:00'::interval as wdcontracthours
-EXEC: insert into kajiwara.staffreportperioddays (daydate,id_staff,payedpause,wdcontracthours)
-SELECT date_trunc('day', dd)::date as daydate,'97ac0b46-1e0a-8389-22cb-39c1dfd89596' as id_staff, null as payedpause, 
- '08:00:00' as  wdcontracthours  
-FROM generate_series( '2021-11-01'::timestamp,'2022-11-06'::timestamp,'1 day'::interval) dd on conflict on constraint uniq_staffworplan_staffday 
-do update set wdcontracthours = '08:00:00';
-EXEC: DELETE FROM kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and (daydate > date('2022-11-06') or daydate < date('2021-11-01')) 
-     OR (id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' AND  daydate not between date('2021-11-01') and date('2022-11-06'));
-EXEC: delete from kajiwara.staffreportperiod sp where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod not in (
-select rp.id from kajiwara.reportperiod rp left join kajiwara.staffreportperioddays pd on (pd.daydate between rp.startdate and rp.enddate)
-where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' group by rp.id);
-QUERY: select * from kajiwara.reportperiod where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222';
-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 kajiwara.staffreportperiod srp
-    join kajiwara.reportperiod rp on (rp.id=srp.id_reportperiod)
-    where srp.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by rp.startdate,rp.enddate)
-    sper ) prp where id='883c34d8-cfea-aa41-57c0-85fa8ca0b222'; 
-EXEC: update kajiwara.staffreportperioddays spds set
-  workhours=ds.worktime, timepause=case when ds.timepause::interval > '00:00:00' then ds.timepause else null end, 
-  dayhours=(ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval + ds.partunemplhours )::interval, interruptionhours = ds.interruption , 
-  contracthours=case when ds.worktime::interval + ds.vachours::interval  + ds.vacillhours::interval  + ds.vacextrahours::interval  + ds.otherpaidhours::interval  + ds.recup::interval > '00:00:00'::interval then ds.wdcontracthours else null end 
-  from (
-    select preds.id,case when preds.recuperationhours is null then '00:00:00'::interval else preds.recuperationhours::interval end as recup,
-    case when preds.vacancyhours is null then '00:00:00'::time else preds.vacancyhours end as vachours,
-    case when preds.vacillhours is null then '00:00:00'::time else preds.vacillhours end as vacillhours,
-    case when preds.vacextrahours is null then '00:00:00'::time else preds.vacextrahours end as vacextrahours,
-    case when preds.otherpaidhours is null then '00:00:00'::time else preds.otherpaidhours end as otherpaidhours,
-    case when preds.partunemplhours is null then '00:00:00'::time else preds.partunemplhours end as partunemplhours,
-    preds.interruption,
-    (preds.dt1+preds.dt2)-(case when preds.payedpause is null then preds.pdt1+preds.pdt2 else '00:00:00'::interval end)  as worktime,
-  (preds.pdt1+preds.pdt2) as timepause,
-  wdcontracthours
-       from ( select id, recuperationhours,vacancyhours,vacillhours,vacextrahours,otherpaidhours,payedpause,partunemplhours,
-               case when timestart1 is not null and timeend1 is not null then case when timeend1 < timestart1 then  '24:00:00'::interval + timeend1 - timestart1 else  timeend1 - timestart1 end else  '00:00:00'::interval end as dt1,
-               case when timestart2 is not null and timeend2 is not null then case when timeend2 < timestart2 then  '24:00:00'::interval + timeend2 - timestart2 else  timeend2 - timestart2 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 - pausestart1 else  pauseend1 - pausestart1 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 - pausestart2 else  pauseend2 - pausestart2 end else '00:00:00'::interval end as pdt2,
-    case when timestart2 is not null and timeend1 is not null and timestart1 is not null and timeend2 is not null then timestart2 - timeend1 else null end as interruption,
-    wdcontracthours
-               from kajiwara.staffreportperioddays where id in (select id from kajiwara.staffreportperioddays where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days'))
-  ) preds) ds where spds.id=ds.id;
-QUERY: select * from kajiwara.staffreportperiod where id_reportperiod='3295dc17-be6c-3f8a-d5e0-b44a5de1277e' and id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596';
-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 kajiwara.staffreportperioddays 
-where daydate between date('2022-05-01') and date('2022-10-31') 
-and date_part('isodow',daydate)::int4 = 7 and workhours > '00:00:00'::time
-and id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' order by daydate
-) xsunday) sunresult;
-QUERY: select sum(suppvacancy44hours) as curvac44h from kajiwara.staffreportperiod where id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and id_reportperiod in (select id from kajiwara.reportperiod where date_part('year',startdate)::int4=date_part('year',date('2022-05-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 kajiwara.staffreportperioddays sr
-                                  WHERE sr.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and sr.daydate between  date('2022-05-01')  and date(date_trunc('week',date('2022-10-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 kajiwara.staffreportperioddays
-                    where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date(date_trunc('week',date('2022-05-01'))) and date(date_trunc('week',date('2022-10-31')) + interval '6 days')
-                    --where id_staff= '97ac0b46-1e0a-8389-22cb-39c1dfd89596' and daydate between date('2022-05-01') and date('2022-10-31')
-                    ) srpd GROUP BY srpd.weekstart,srpd.id_staff
-                  ORDER BY weekstart) ws) wsavg order by weekstart DESC LIMIT 1;
-EXEC: update kajiwara.staffreportperiod rpd set
-  --contracthours=csp.contracthours,
-  workhours=csp.workhours,
-  vacancyill=csp.vacillhours,
-  vacancynormal=csp.vacancynormal,
-  vacancyextra=csp.vacextrahours,
-  otherpaidhours=csp.otherpaidhours,
-  partunemplhours=csp.partunemplhours,
-  totalhours=csp.totalhours,
-  recuperationhours=csp.recuperationhours,statussuncount=null,suppvacancysunwork=null,suppvacancy44hours=null,status44hcount=null,last44date=null,avgtotalweekhours='00:00:00'::interval,hoursdiff=csp.diffhours
-  FROM (
-  select contracthours,workhours,totalhours,recuperationhours, totalhours-contracthours-transferedhours as diffhours,id,vacillhours,vacancynormal,vacextrahours,otherpaidhours,partunemplhours from (
-  select dp.id,
-  sum(pd.workhours) as workhours,
-  sum(pd.dayhours) as totalhours,
-  sum(coalesce(pd.vacancyhours,'00:00:00'::time)) as vacancynormal,
-  sum(coalesce(pd.vacillhours,'00:00:00'::time)) as vacillhours,
-  sum(coalesce(pd.vacextrahours,'00:00:00'::time)) as vacextrahours,
-  sum(coalesce(pd.otherpaidhours,'00:00:00'::time)) as otherpaidhours,
-  sum(coalesce(pd.partunemplhours,'00:00:00'::time)) as partunemplhours,
-  sum(coalesce(pd.recuperationhours,'00:00:00'::time)) as recuperationhours, 
-  coalesce(dp.contracthours,'00:00:00'::interval) as contracthours,
-  coalesce(dp.payedhours0,'00:00:00'::interval) as payedhours0,
-  coalesce(dp.payedhours40,'00:00:00'::interval) as payedhours40,
-  coalesce(dp.transferedhours,'00:00:00'::interval) as transferedhours
-  from kajiwara.staffreportperioddays pd 
-  join kajiwara.staffreportperiod dp on (pd.id_staff=dp.id_staff and dp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222')
-  where pd.id_staff='97ac0b46-1e0a-8389-22cb-39c1dfd89596' and  pd.daydate between date('2022-05-01') and date('2022-10-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,
-    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(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_staff = '97ac0b46-1e0a-8389-22cb-39c1dfd89596'  
-  ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERYARRAY: select id,trackername from alicehartmann.timetrackerconfig order by trackername
+QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM alicehartmann.staffgroups sg LEFT JOIN alicehartmann.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,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') AS staffname,sc.staffstatus from alicehartmann.staff st 
+LEFT JOIN alicehartmann.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 alicehartmann.staffcontract 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='alicehartmann') 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 alicehartmann.workplans wp
+  ORDER BY wp.isdefault, wp.workplan;
+QUERYARRAY: SELECT id,vacancyname,color
+   FROM alicehartmann.vacancytypes where isworktime is null or isworktime=false order by vacancyname;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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 alicehartmann.staffgroups sg LEFT JOIN alicehartmann.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 alicehartmann.timetrackerconfig order by trackername
+QUERYARRAY: select ttr.*, st.* ,stg.groupname,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') AS staffname,sc.staffstatus from alicehartmann.staff st 
+LEFT JOIN alicehartmann.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 alicehartmann.staffcontract 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='alicehartmann') ttr
+where st.isdeleted is null  order by groupname,st.staffnumber::INT,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 alicehartmann.workplans wp
+  ORDER BY wp.isdefault, wp.workplan;
+QUERYARRAY: SELECT id,vacancyname,color
+   FROM alicehartmann.vacancytypes where isworktime is null or isworktime=false order by vacancyname;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='alicehartmann';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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.schemaaccess),cp.company,
+    us.schemaaccess AS schemaname,
+    cp.datasetname
+   FROM ( SELECT json_array_elements_text(users.schemaaccess) AS schemaaccess
+     FROM users WHERE users.isdeleted IS null) us
+     LEFT JOIN companies cp ON cp.schemata = us.schemaaccess AND cp.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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select sessiondata from public.sessions where id='f2de1423-f891-08ee-f516-ec4b2ce4c0db'
+EXEC: update public.sessions set sessiondata='{"schemata":"kraeltgen"}' where id='f2de1423-f891-08ee-f516-ec4b2ce4c0db'
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERYARRAY: select id,trackername from kraeltgen.timetrackerconfig order by trackername
+QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM kraeltgen.staffgroups sg LEFT JOIN kraeltgen.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,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') AS staffname,sc.staffstatus from kraeltgen.staff st 
+LEFT JOIN kraeltgen.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 alicehartmann.staffcontract 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='kraeltgen') ttr
+where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
+QUERYARRAY: SELECT id,vacancyname,color
+   FROM kraeltgen.vacancytypes where isworktime is null or isworktime=false order by vacancyname;
+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 kraeltgen.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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERYARRAY: select id,trackername from kraeltgen.timetrackerconfig order by trackername
+QUERYARRAY: select sg.id,sg.groupname,sg.groupcolor,sg.isdefault,COALESCE(count(st.id), 0) AS staffmembers FROM kraeltgen.staffgroups sg LEFT JOIN kraeltgen.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,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') AS staffname,sc.staffstatus from kraeltgen.staff st 
+LEFT JOIN kraeltgen.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 alicehartmann.staffcontract 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='kraeltgen') 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 kraeltgen.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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERYARRAY: select id,trackername from kraeltgen.timetrackerconfig order by trackername
+0) AS staffmembers FROM kraeltgen.staffgroups sg LEFT JOIN kraeltgen.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,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') AS staffname,sc.staffstatus from kraeltgen.staff st 
+LEFT JOIN kraeltgen.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 kraeltgen.staffcontract 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='kraeltgen') ttr
+where st.isdeleted is null  order by groupname,st.staffnumber,surname,prename;
+QUERYARRAY: SELECT id,vacancyname,color
+   FROM kraeltgen.vacancytypes where isworktime is null or isworktime=false order by vacancyname;
+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 kraeltgen.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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select * from kraeltgen.staff where id='f18a67e3-1b2f-dbed-85e9-1b35912f943e' 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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,
@@ -13071,68 +722,71 @@ QUERYARRAY: SELECT st.prename, st.surname, coalesce(st.surname || ' ','') || coa
     to_char(hourstotransfer, 'HH24:MI'::text) as hourstotransfer,
     to_char(hourstotransfercalc, 'HH24:MI'::text)  as hourstotransfercalc,
     to_char(srp.avgtotalweekhours, 'HH24:MI'::text) AS avgtotalweekhours
-   FROM kajiwara.staffreportperiod srp
-     LEFT JOIN kajiwara.staff st ON srp.id_staff = st.id
-     LEFT JOIN kajiwara.reportperiod rp ON srp.id_reportperiod = rp.id
-     LEFT JOIN kajiwara.staffgroups sgr ON st.id_staffgroup = sgr.id
-  WHERE st.isdeleted IS NULL  AND srp.id_reportperiod = '883c34d8-cfea-aa41-57c0-85fa8ca0b222'  
+   FROM kraeltgen.staffreportperiod srp
+     LEFT JOIN kraeltgen.staff st ON srp.id_staff = st.id
+     LEFT JOIN kraeltgen.reportperiod rp ON srp.id_reportperiod = rp.id
+     LEFT JOIN kraeltgen.staffgroups sgr ON st.id_staffgroup = sgr.id
+  WHERE st.isdeleted IS NULL  AND srp.id_staff = 'f18a67e3-1b2f-dbed-85e9-1b35912f943e'  
   ORDER BY st.surname, st.prename, srp.id_staff, rp.startdate, rp.enddate;
+QUERYARRAY: select id,id_staff,vacyear,to_char(vachours,'HH24:MI') as vachours from kraeltgen.staffvacancyyear where id_staff='f18a67e3-1b2f-dbed-85e9-1b35912f943e' order by vacyear;
+QUERYARRAY: SELECT id,id as id_staffcontract,id_staff,startdate,enddate,weekdays,to_char(weekhours, 'HH24:MI'::text) AS weekhours,defaultfreedays from kraeltgen.staffcontract where id_staff='f18a67e3-1b2f-dbed-85e9-1b35912f943e' order by startdate,enddate;
+QUERYARRAY: select to_char(daydate,'YYYY') as vacyear,daydate,
+  to_char(vacancyhours::interval,'HH24:MI') as vacancyhours,
+  to_char(vacillhours::interval,'HH24:MI') as vacillhours,
+  to_char(vacextrahours::interval,'HH24:MI') as vacextrahours, 
+  coalesce ('<div>' || vacancycomment || '</div>','') || coalesce('<div>' ||  vacillcomment|| '</div>','') || coalesce('<div>' || vacextracomment|| '</div>','') as description 
+  from kraeltgen.staffreportperioddays where (vacancyhours is not null or vacillhours is not null or vacextrahours is not null) and id_staff='f18a67e3-1b2f-dbed-85e9-1b35912f943e' order by 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
-      us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
-      join users us on (us.id=se.id_user)
-      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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.schemaaccess),cp.company,
@@ -13144,172 +798,256 @@ QUERYARRAY: SELECT distinct(us.schemaaccess),cp.company,
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+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 kraeltgen.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 kraeltgen.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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: SELECT * FROM public.companies WHERE schemata='kajiwara' 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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 kajiwara.staffgroups sg LEFT JOIN kajiwara.staff st ON (st.id_staffgroup = sg.id and st.isdeleted IS NULL)
-    GROUP BY sg.id ORDER BY sg.groupname;
-QUERYARRAY: select * from (
-SELECT us.username,us.isblocked,us.surname,us.prename,us.id_company,us.id_usergroup,us.id,cp.company,cp.datasetname,grp.groupname,us.lang,
-case when us.id_usergroup = 'teamleader' then string_agg(stgrp.groupname,',') else null end  as staffgroups,
-            json_array_elements_text(us.schemaaccess) AS xschema
-           FROM public.users us join public.companies cp on (us.id_company=cp.id)
-           left join public.usergroups grp on (us.id_usergroup=grp.id)
-           left join (select stu.id as id_user,stu.id_staffgroup,stg.groupname from kajiwara.staffgroups stg
-join (select id,json_array_elements_text(id_staffgroups) as id_staffgroup from public.users) stu on (stu.id_staffgroup=stg.id)) stgrp on (us.id=stgrp.id_user)
-          WHERE us.isdeleted IS null  and id_usergroup in ('teamleader','manager')  group by us.id,cp.id,grp.id
-          ) xus where xschema='kajiwara' group by xus.id,xus.username,xus.groupname,xus.isblocked,xus.surname,xus.prename,xus.id_company,xus.id_usergroup,xus.company,xus.datasetname,xus.xschema,xus.staffgroups,xus.lang;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERYARRAY: select * from (
-SELECT us.username,us.isblocked,us.surname,us.prename,us.id_company,us.id_usergroup,us.id,cp.company,cp.datasetname,grp.groupname,us.lang,
-case when us.id_usergroup = 'teamleader' then string_agg(stgrp.groupname,',') else null end  as staffgroups,
-            json_array_elements_text(us.schemaaccess) AS xschema
-           FROM public.users us join public.companies cp on (us.id_company=cp.id)
-           left join public.usergroups grp on (us.id_usergroup=grp.id)
-           left join (select stu.id as id_user,stu.id_staffgroup,stg.groupname from kajiwara.staffgroups stg
-join (select id,json_array_elements_text(id_staffgroups) as id_staffgroup from public.users) stu on (stu.id_staffgroup=stg.id)) stgrp on (us.id=stgrp.id_user)
-          WHERE us.isdeleted IS null  and id_usergroup in ('teamleader','manager')  group by us.id,cp.id,grp.id
-          ) xus where xschema='kajiwara' group by xus.id,xus.username,xus.groupname,xus.isblocked,xus.surname,xus.prename,xus.id_company,xus.id_usergroup,xus.company,xus.datasetname,xus.xschema,xus.staffgroups,xus.lang;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='kraeltgen';
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERYARRAY: SELECT distinct(us.schemaaccess),cp.company,
+    us.schemaaccess AS schemaname,
+    cp.datasetname
+   FROM ( SELECT json_array_elements_text(users.schemaaccess) AS schemaaccess
+     FROM users WHERE users.isdeleted IS null) us
+     LEFT JOIN companies cp ON cp.schemata = us.schemaaccess AND cp.isdeleted IS NULL;
+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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select sessiondata from public.sessions where id='f2de1423-f891-08ee-f516-ec4b2ce4c0db'
+EXEC: update public.sessions set sessiondata='{"schemata":"davincenzo"}' where id='f2de1423-f891-08ee-f516-ec4b2ce4c0db'
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERYARRAY: SELECT distinct(us.schemaaccess),cp.company,
+    us.schemaaccess AS schemaname,
+    cp.datasetname
+   FROM ( SELECT json_array_elements_text(users.schemaaccess) AS schemaaccess
+     FROM users WHERE users.isdeleted IS null) us
+     LEFT JOIN companies cp ON cp.schemata = us.schemaaccess AND cp.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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-EXEC: UPDATE public.users SET userpassword = 'c79a9c394eb8ff36f262e71c2e0cecfcf0f56f791b9bcbd1aa1e544fe916b785' WHERE id='940bc991-a807-ac19-49a1-6aaedcf836f7';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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;
+QUERYARRAY: SELECT id,vacancyname,color
+   FROM davincenzo.vacancytypes where isworktime is null or isworktime=false order by vacancyname;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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.schemaaccess),cp.company,
@@ -13321,111 +1059,131 @@ QUERYARRAY: SELECT distinct(us.schemaaccess),cp.company,
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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 id,trackername from davincenzo.timetrackerconfig order by trackername
+QUERYARRAY: select ttr.*, st.* ,stg.groupname,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') 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 davincenzo.staffcontract 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;
+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,vacancyname,color
+   FROM davincenzo.vacancytypes where isworktime is null or isworktime=false order by vacancyname;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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.schemaaccess),cp.company,
     us.schemaaccess AS schemaname,
     cp.datasetname
@@ -13435,94 +1193,145 @@ QUERYARRAY: SELECT distinct(us.schemaaccess),cp.company,
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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 id,trackername from davincenzo.timetrackerconfig order by trackername
+QUERYARRAY: select ttr.*, st.* ,stg.groupname,COALESCE(st.surname || ' ', '') || COALESCE(st.prename, '') 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 davincenzo.staffcontract 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;
+QUERYARRAY: SELECT id,vacancyname,color
+   FROM davincenzo.vacancytypes where isworktime is null or isworktime=false order by vacancyname;
+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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERYARRAY: SELECT distinct(us.schemaaccess),cp.company,
     us.schemaaccess AS schemaname,
@@ -13534,59 +1343,200 @@ QUERY: select terms from public.users where id='e9e6880b-75c7-70b5-ce61-49cf6d62
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
-QUERY: select timetrackertype,sector from public.companies where schemata='kajiwara';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
       us.isblocked is null group by se.id,us.id,ugrp.id;
 QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
       join users us on (us.id=se.id_user)
       left join usergroups ugrp on (ugrp.id=us.id_usergroup)
-      where se.id= 'a046868f-3c94-adc9-caac-1e6088267672' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' and 
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: SELECT * FROM public.companies WHERE schemata='davincenzo' and isdeleted IS NULL;
+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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 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.schemaaccess),cp.company,
     us.schemaaccess AS schemaname,
     cp.datasetname
    FROM ( SELECT json_array_elements_text(users.schemaaccess) AS schemaaccess
      FROM users WHERE users.isdeleted IS null) us
      LEFT JOIN companies cp ON cp.schemata = us.schemaaccess AND cp.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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector from public.companies where schemata='davincenzo';
+QUERY: select timetrackertype,sector 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: SELECT * FROM public.companies WHERE schemata='davincenzo' 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= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERY: select se.id as idsession,us.lang,us.id,us.username,ugrp.id as usergroup,us.id_staffgroups as staffgroups,se.sessiondata from sessions se 
+      join users us on (us.id=se.id_user)
+      left join usergroups ugrp on (ugrp.id=us.id_usergroup)
+      where se.id= 'f2de1423-f891-08ee-f516-ec4b2ce4c0db' and se.remote_addr= '::1' and se.user_agent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' and 
+      us.isblocked is null group by se.id,us.id,ugrp.id;
+QUERYARRAY: select * from (
+SELECT us.username,us.isblocked,us.surname,us.prename,us.id_company,us.id_usergroup,us.id,cp.company,cp.datasetname,grp.groupname,us.lang,
+case when us.id_usergroup = 'teamleader' then string_agg(stgrp.groupname,',') else null end  as staffgroups,
+            json_array_elements_text(us.schemaaccess) AS xschema
+           FROM public.users us join public.companies cp on (us.id_company=cp.id)
+           left join public.usergroups grp on (us.id_usergroup=grp.id)
+           left join (select stu.id as id_user,stu.id_staffgroup,stg.groupname from davincenzo.staffgroups stg
+join (select id,json_array_elements_text(id_staffgroups) as id_staffgroup from public.users) stu on (stu.id_staffgroup=stg.id)) stgrp on (us.id=stgrp.id_user)
+          WHERE us.isdeleted IS null  and id_usergroup in ('teamleader','manager')  group by us.id,cp.id,grp.id
+          ) xus where xschema='davincenzo' group by xus.id,xus.username,xus.groupname,xus.isblocked,xus.surname,xus.prename,xus.id_company,xus.id_usergroup,xus.company,xus.datasetname,xus.xschema,xus.staffgroups,xus.lang;
index 01a3a9d..91d7997 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "POT",
-  "start_url": "ttp://dks-laptop/potapp/potapp/",
+  "start_url": "http://dks-laptop/potapp/",
   "display": "standalone",
   "dir": "ltr",
   "lang": "fr-FR",
index b898ed0..860257c 100644 (file)
@@ -15,7 +15,7 @@ let staffgroups = {
   gettbldata: function(){
     sel = companies.tbl.getSelectedData();
     if (sel[0]){
-      postData("db.php", { "get":  "staffgroups","schemata":sel[0].schemata}).then(data => { staffgroups.tbl.setData(data.result.data);});
+      postData("db.php", { "cl":"Company","fn":"getStaffGroups","schema":sel[0].schemata,"id_groups":'{{session.staffgroups}}'}).then(data => { staffgroups.tbl.setData(data.result.data);});
     }
   },
   add: function(){
index e0a3ee3..c8b5979 100644 (file)
@@ -181,7 +181,7 @@ let users ={
     let sel = companies.tbl.getSelectedData();
     //console.log("cschema",companies.current_schemata);
     if (sel[0]){
-      postData("db.php",{"get":"staffgroups","schemata":sel[0].schemata}).then(data => {
+      postData("db.php",{"cl":"Company","fn":"getStaffGroups","schema":sel[0].schemata,"id_groups":'{{session.staffgroups}}'}).then(data => {
         //console.log("staffgroups",data.result);
         dataform.fillselectlist(users.choices["user_id_staffgroups"],data.result.data,'id','groupname');
       });
index 6e1b823..4e716e8 100644 (file)
   <div class="display-container">
     <div class="row">
       <div class="col s3" style="width: 300px;">
+        <div class="row">
+          <div>
+            <select class="select border data_stafffilter" data-column="filter" data-id="" data-selected="" data-table="label" id="stafffilter">
+              <option value="current">{{ lbl.staffcurrent }}</option>
+              <option value="all">{{ lbl.staffall }}</option>
+              <option value="past">{{ lbl.staffpast }}</option>
+              <option value="futur">{{ lbl.stafffutur }}</option>
+            </select>
+          </div>
+        </div>
         <div id="tbl_staff" ></div>
       </div>
     
index 8c5a34d..6105940 100644 (file)
@@ -15,7 +15,7 @@ let staff ={
   current_id: null,
   current_view: 'basedata',
   staff_defaultgroup:null,
-  choices:{"id_staffgroup":null,"addstaff_id_staffgroup":null,"istimetrackenabled":null,"timetrackers":null,"timetrackerlang":null,"note":null,"timetrackerrestriction":null},
+  choices:{"id_staffgroup":null,"addstaff_id_staffgroup":null,"istimetrackenabled":null,"timetrackers":null,"timetrackerlang":null,"note":null,"timetrackerrestriction":null,"stafffilter":null},
   initform: function(){
     flatpickr("#birthdate",{altInput: true,
       altFormat: "d.m.Y",
@@ -66,6 +66,13 @@ let staff ={
       showSearch: false,
       
     });
+    staff.choices["staffilter"] = new SlimSelect({
+      select: "#stafffilter",
+      showSearch: false,
+      afterClose: function(){
+        staff.setTableFilter();
+      }
+    });
     // staff.choices["timetrackerrestriction"] = new SlimSelect({
     //   select: "#timetrackerrestriction",
     //   showSearch: false,
@@ -118,7 +125,7 @@ let staff ={
     staff.initform();
     staff.tbl = new Tabulator("#tbl_staff", {
       resizableColumns: false,
-      height: "calc(100vh - 56px)",
+      height: "calc(100vh - 94px)",
       layout: "fitDataStretch",
       selectable: 1,
       groupBy:["groupname"],
@@ -140,7 +147,7 @@ let staff ={
   //   staff.edit();
   // });
   staff.gettbldata();
-      
+  staff.setTableFilter("current");
   },
   gettbldata: function(id){
     let selectedData = staff.tbl.getSelectedData();
@@ -150,7 +157,18 @@ let staff ={
       });
     }).catch(e => { console.log(e)});
   },
-
+  setTableFilter: function(fval=null){
+    if (!fval){
+      fval = document.getElementById("stafffilter").value;
+    }
+    console.log(fval);
+    if (fval == "all"){
+      staff.tbl.clearFilter();
+    } else {
+      staff.tbl.setFilter("staffstatus","in",[fval]);
+    }
+    
+  },
   add: function(){
     document.getElementById("dlg_addstaff_infomsg").innerHTML ='';
     dataform.cleanform2("addstaff",staff.choices);
@@ -270,7 +288,7 @@ let staff ={
     return false;
   },
   getstaffgroups: function(){
-    postData("db.php",{"get":"staffgroups","schemata":schemata}).then(data => {
+    postData("db.php",{"cl":"Company","fn":"getStaffGroups","schema":schemata,"id_groups":'{{session.staffgroups}}'}).then(data => {
       staff.staff_defaultgroup=data.result.data[0].id;
       dataform.fillselectlist(staff.choices["addstaff_id_staffgroup"],data.result.data,'id','groupname');
       dataform.fillselectlist(staff.choices["id_staffgroup"],data.result.data,'id','groupname');
@@ -282,9 +300,9 @@ let staff ={
       dataform.fillselectlist(staff.choices["timetrackers"],data.result.data,'id','trackername');
     });
   },
-  fillstaffgroups: function(data){
-    dataform.fillselectlist(staff.choices["id_staffgroup"],data.data,'id','groupname');
-  },
+  // fillstaffgroups: function(data){
+  //   dataform.fillselectlist(staff.choices["id_staffgroup"],data.data,'id','groupname');
+  // },
   setview: function(viewname){
    let sel = staff.tbl.getSelectedData();
    if (sel[0]){
@@ -330,6 +348,6 @@ let staff ={
       closedataloaddlg();
       //console.log("SetStaff err returns",data);
     });
-    //alert("Noch nicht aktiviert!\nPas activé pour l'instant!")
+    //ale,rt("Noch nicht aktiviert!\nPas activé pour l'instant!")
   }
 }
index 1f15f9e..6e63716 100644 (file)
@@ -11,7 +11,7 @@ let staffperiods = {
         headerFilterPlaceholder:"{{ lbl.filter }}",
       // },
       
-      height: "calc(100vh - 112px)",
+      height: "calc(100vh - 116px)",
       layout: "fitDataFill",
       selectable: true,
       selectableRangeMode:"click",