}
$chsql = "select sum(maxdays) as maxdays,sum(contracthours - ('00:00:'|| extract(second from contracthours))::interval ) as itmcontracthours from (
select sum(maxdays) as maxdays,sum(maxdays) * (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)-count(sundays) end as maxdays, calweek,count(daydate) as cntdays,count(sundays) as sundays,weekdays,weekhours 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 ".$schema.".staffreportperioddays
// ) wdays ) rnddays;";
//OLD
// print STDERR "CONTRACT:".$chsql."\n========\n";
+ error_log("set contract:".$chsql);
$checkhours = $this->dbh->query($chsql);
$usql = "update ".$schema.".staffreportperiod set maxdays=".(($checkhours["maxdays"] != "")?$checkhours["maxdays"]:'null').",contracthours=".(($checkhours["itmcontracthours"] != "")?"'".$checkhours["itmcontracthours"]."'":'null')." where id_staff='".$id_staff."' and id_reportperiod='".$pp["id"]."';" ;
{title: '<span style="font-size: 9pt;">{{ lbl.suppsunwork }}</span>',width: 50, field:"suppvacancysunwork",hozAlign:"right",headerSort: false,headerVertical:true},
{title: '<span style="font-size: 8pt;">{{ lbl.avgweek_short }}</span>',width: 60, field:"avgtotalweekhours",hozAlign:"right",headerSort: false,formatter:periodAVGFormatter},
{title: '<span style="font-size: 9pt;">{{ lbl.validated }}</span>',width: 40, field:"isvalidated",hozAlign:"center",headerSort: false,formatter:"tickCross", formatterParams:{allowEmpty:true,allowTruthy: false},headerVertical:true},
- // {title: '<span style="font-size: 9pt;">{{ lbl.maxdays }}</span>',width: 60, field:"maxdays",hozAlign:"center",headerSort: false}
+ {title: '<span style="font-size: 9pt;">{{ lbl.maxdays }}</span>',width: 60, field:"maxdays",hozAlign:"center",headerSort: false}
]
});