{function name=print_breaks breaks=[]}
   {foreach item=break from=$breaks}
        {if $break->diff>=$timelog_break_min}
            <small title="{$i.basic_min_pause}"> {$i.reporting_pause}: {$break->last_time_to->us_stime()} - {$break->time_from->us_stime()} ({$break->diff})</small>
        {/if}
    {/foreach}
{/function}

{if !isset($loop_count)}
    {$loop_count = 0}
{/if}

<style>
    .tnot {
        opacity: 0.5; 
        font-size: 8px;
    }
</style>

{if $loop_count === 0}
<div class="ui-report-header ui-widget-header ui-corner-all noprint" style="pd4ml-display:none; margin-bottom:5mm;">
    <a class="dialog_make_text_btn ui-corner-all" style="pd4ml-display:none;"
       onclick="evaluation.open_file(this, 'pdf', '{site_url url="reportportlet/`$reports_xjxcookie`/staff_timelog/result_pdf/`$staff_timelog_file_id`"}', 'XNOX')">
        <span class="dialog_make_btn16 pdf"></span>
        PDF
    </a>
    <a class="dialog_make_text_btn ui-corner-all" style="pd4ml-display:none;"
       onclick="evaluation.open_file(this, 'csv', '{site_url url="reportportlet/`$reports_xjxcookie`/tmp_as_csv/process/`$staff_timelog_csvfile_id`"}', 'XNOX')">
        <span class="dialog_make_btn16 csv"></span>
        CSV
    </a>
    
    {portlet file='report_designs_list'}
</div>
{else}
    <h1 style="margin-bottom:5mm; visibility:hidden; pd4ml-visibility:visible">{$title}<span id="wait" title="Loading..."></span><span class="print_btn" onclick="window.print();" title="Print preview"></span></h1>
{/if}
<!-- ------------------------------------- Zeitraum ------------------------------------- -->

<table class="editablepop" style="margin-bottom:5mm; display:none; pd4ml-display:block; ">
    <tbody>
        <tr>
            <td style="vertical-align:top; width:350px; background: none;"><h3 style="line-height:20px;">{$i.reporting_time_period}: {$request_vars->dates__from->us_date()} - {$request_vars->dates__to->us_date()}</h3></td>
            <td style="vertical-align:bottom; width:500px; background: none;"><textarea style="display:none; pd4ml-display:block; width:500px; height:28px; font-size:20px; border:0 none; margin:0; padding:0;" rows="1" cols="50"></textarea></td>
        </tr>
    </tbody>
</table>

<!-- ------------------------------------- Mitarbeitername + Anmerkung ------------------------------------- -->

<h2 style="margin-top: 1mm;">{$staff_info->staff_name}</h2>
<div style="display:none; pd4ml-display:block; margin:2mm; padding:0; border-bottom:1px solid gray;">
    <div style="width:40px; line-height:20px; float:left; margin:0; padding:0;">{$i.reporting_comment_short}:</div>
    <div style="width:780px; float:right; margin:0; padding:0;">
        <textarea style="width:780px; height:28px; font-size:20px; border:0 none; margin:0; padding:0;" rows="1" cols="50"></textarea>
    </div>
</div>

<!-- ------------------------------------- Hauptliste ------------------------------------- -->

<table class="editablepop" style="margin-top: 2mm;">
    <colgroup>
        <col style="min-width:20mm;"></col>
        {foreach item=project from=$projects_list}
            <col style="min-width:20mm;"></col>
        {/foreach}
        <col style="min-width:20mm;"></col>
        <col style="min-width:20mm;"></col>
        {foreach item=overtime_rate from=$overtime_rates}
            {if $overtime_rate->print neq 0}<col style="min-width:20mm;"></col>{/if}
        {/foreach}
        <col style="min-width:30mm;"></col>
        {if $home_office_use}
            <col style="min-width:10mm; max-width:20mm; width:15mm;"></col>
        {/if}
    </colgroup>
    <thead>
        <tr>
            <th style="min-width:20mm;">&nbsp;&nbsp;&nbsp;&nbsp;{$i.reporting_rep_date}&nbsp;&nbsp;&nbsp;&nbsp;</th>
            {$this_projects=array()}
            {foreach item=project from=$projects_list}
                <th>{$project->project|table_header_names}</th>
                {$this_projects[]=$project->project}
            {/foreach}
            <th class="spacebefore">{$i.reporting_target_day}</th>
            <th style="min-width:20mm;">&nbsp;&nbsp;&nbsp;&nbsp;{$i.reporting_actual}&nbsp;&nbsp;&nbsp;&nbsp;</th>
            {foreach item=overtime_rate from=$overtime_rates}
                {if $overtime_rate->print neq 0}<th>{$overtime_rate->name|table_header_names}</th>{/if}
            {/foreach}
            <th>{$i.reporting_overtime_storage} &<br /> {$i.reporting_hours_from_to}</th>
            {if $home_office_use}
                <th>{$trans_home_office}</th>
            {/if}
        </tr>
    </thead>
    <tbody>
        {$sums=array()}{$all_overtime_ok=true}{$all_set_ok=true}{$all_set_limit=true}
        {foreach item=total from=$totals}
            {$style_left=''}{$style_overtime=''}
            {if empty($total->target_hours)}{$style_left='background-color:#E78D8D;'}{/if}
            {if $total->dayofweek==$view_weekend1 OR $total->dayofweek==$view_weekend2}{$style_left='background-color:#8F8F8F;'}{/if}
            {if !$total->overtime_ok}{$style_overtime='background-color:#FFFF66;'}{$all_overtime_ok=false}{/if}
            {if $total->has_holiday!==false}{$style_left='background-color:#f3c6c6;'}{/if}
            {if isset($total->set_info) && $total->set_info}
                {if ($total->number_all+0.01)<($total->set_timediff/3600)}
                    {$style_left='background-color:#FFCC66;'}{$all_set_ok=false}
                {elseif ($total->number_all-0.01)>($total->set_timediff/3600)}
                    {$style_left='background-color:#FF6666;'}{$all_set_limit=false}
                {/if}
            {/if}
            <tr>
                <td style="text-align:center; white-space:nowrap; {$style_left}" {if $total->has_holiday!==false}title="{$total->has_holiday}"{/if}>{*
                    *}{$total->date->us_date()}{*
                *}</td>
                {$this_sum_projects_list=0}
                {foreach item=project from=$projects_list}
                    {assign var="numbername" value="number`$project->id`"}
                    {if !isset($sums.$numbername)}{$sums.$numbername=0}{/if}
                    {$sums.$numbername=$sums.$numbername+$total->$numbername}
                    {$this_sum_projects_list=$this_sum_projects_list+$total->$numbername}
                    <td style="text-align:right; white-space:nowrap; {$style_left}">{*
                        *}{if !empty($total->$numbername)}{isfloat value=$total->$numbername}{/if}{*
                    *}</td>
                {/foreach}
                <td style="text-align:right; white-space:nowrap; {$style_overtime}" class="spacebefore">{*
                    *}{if empty($total->target_hours)}{isfloat value=0}{else}{isfloat value=$total->target_hours}{/if}{*
                    *}{if !isset($sums.target_hours)}{$sums.target_hours=0}{/if}{*
                    *}{$sums.target_hours=$sums.target_hours+$total->target_hours}{*
                *}</td>
                <td style="text-align:right; white-space:nowrap; {$style_overtime}">{*
                    *}{if empty($total->number_all)}{isfloat value=0}{else}{isfloat value=$total->number_all}{/if}{*
                    *}{if !isset($sums.number_all)}{$sums.number_all=0}{/if}{*
                    *}{$sums.number_all=$sums.number_all+$total->number_all}{*
                *}</td>
                {foreach item=overtime_rate from=$overtime_rates}
                    {if $overtime_rate->print neq 0}
                        {assign var="overtimename" value="overtime`$overtime_rate->id`"}
                        {if !isset($sums.$overtimename)}{$sums.$overtimename=0}{/if}
                        {$sums.$overtimename=$sums.$overtimename+$total->$overtimename}
                        <td style="text-align:right; white-space:nowrap; {$style_overtime}">{*
                            *}{if !empty($total->$overtimename)}{isfloat value=$total->$overtimename}{/if}{*
                        *}</td>
                    {/if}
                {/foreach}
                <td>{*
                    *}{$total->overtime_storage}{*
                    *}{if isset($total->set_info) && $total->set_info}{*
                        *}{* Start end Times *}{*
                        *}<span title="{$i.basic_set}">{*
                            *}{$total->set_info}{*
                            *}{if !empty($total->breaks)}{*
                                *}{print_breaks breaks=$total->breaks}{*
                                *}{assign var="breaks_printed" value=true}{*
                            *}{else}{*
                            *}<span style="white-space:pre;"> (-{float_to_usnumber($total->set_time_deduct, 2)})</span> = {isfloat value=$total->set_timediff/3600}{*
                            *}{/if}{*
                        *}</span>{*
                        *}{if !$total->time_from->is_null()} | {/if}{*
                    *}{/if}{*
                    *}{if !$total->time_from->is_null()}{*
                        *}{* Min and Max from times *}{*
                        *}<span title="{$i.reporting_hours_from_to}">{*
                            *}{$total->time_from->us_stime()} - {$total->time_to->us_stime()}{*
                        *}</span>{*
                        *}{* Breaks *}{*
                    *}{if !isset($breaks_printed)}{print_breaks breaks=$total->breaks}{/if}
                    {/if}
                </td>
                {if !isset($sums.overtime_all)}{$sums.overtime_all=0}{/if}
                {$sums.overtime_all=$sums.overtime_all+$total->overtime_all}
                {if $home_office_use}
                    <td style="text-align:center;" {if $total->home_office && empty($total->number_all)}title="{$i.reporting_yes_but_no_number}"{/if}>{*
                        *}{if $total->home_office}{*
                            *}{if !empty($total->number_all)}{*
                                *}{boolview value=true}{*
                                *}{if !isset($sums.home_office_all)}{$sums.home_office_all=0}{/if}{*
                                *}{$sums.home_office_all=$sums.home_office_all+1}{*
                            *}{else}{*
                                *}<div class="dialog_make_btn14 dot" title="{$i.reporting_yes_but_no_number}"> ✔</div>{*
                            *}{/if}{*
                        *}{/if}{*
                        *}{if !$total->home_office && !empty($total->number_all) && (round($total->number_all,2)!==round($this_sum_projects_list,2))}{*
                            *}{if !isset($sums.home_office_not_all)}{$sums.home_office_not_all=0}{/if}{*
                            *}{$sums.home_office_not_all=$sums.home_office_not_all+1}<small class="tnot">n</small>{*
                        *}{/if}
                    </td>
                {/if}
            </tr>
        {/foreach}
        <tr class="ui-widget-header">
            <td rowspan="2">{$i.reporting_rep_x_total}</td>
            {foreach item=project from=$projects_list}
                {assign var="numbername" value="number`$project->id`"}
                <td style="text-align:right; white-space:nowrap;" rowspan="2">{if !empty($sums.$numbername)}{isfloat value=$sums.$numbername}{/if}</td>
            {/foreach}
            <td style="text-align:right; white-space:nowrap;" class="spacebefore" title="{$i.reporting_target_day|table_header_names}" rowspan="2">
                {isfloat value=$sums.target_hours}
            </td>
            <td style="text-align:right; white-space:nowrap;" title="{$i.reporting_actual|table_header_names}" rowspan="2">
                {isfloat value=$sums.number_all}
            </td>
            {$overtime_cols=0}
            {foreach item=overtime_rate from=$overtime_rates}
                {if $overtime_rate->print neq 0}
                    {$overtime_cols=$overtime_cols+1}
                    {assign var="overtimename" value="overtime`$overtime_rate->id`"}
                    <td style="text-align:right; white-space:nowrap;" title="{$overtime_rate->name|table_header_names}">
                        {if empty($sums.$overtimename)}{isfloat value=0}{else}{isfloat value=$sums.$overtimename}{/if}
                    </td>
                {/if}
            {/foreach}
            <td style="white-space:nowrap;" rowspan="2" title="{$i.reporting_target_day|table_header_names} + {$i.reporting_overtime|table_header_names}">
                {$i.reporting_target_a_overtime} = {isfloat value=$sums.target_hours+$sums.overtime_all}
            </td>
            {if $home_office_use}
                <td style="text-align:right; white-space:nowrap;" title="{$trans_home_office} {$i.basic_days}">
                    {$trans_home_office_short}: {if empty($sums.home_office_all)}0{else}{isfloat value=$sums.home_office_all maxf=0}{/if}
                </td>
            {/if}
        </tr>
        <tr class="ui-widget-header">
            {if $overtime_cols neq 0}
                <td style="text-align:right; white-space:nowrap;" colspan="{$overtime_cols}" title="{$i.reporting_rep_x_total|table_header_names} - {$i.reporting_overtime|table_header_names}">
                    {if empty($sums.overtime_all)}{isfloat value=0}{else}{isfloat value=$sums.overtime_all}{/if}
                </td>
            {/if}
            {if $home_office_use}
                <td style="text-align:right; white-space:nowrap;" title="{$i.reporting_home_office_not} ({$i.reporting_undefined_fees} {implode(', ',$this_projects)})">
                    <span style="background: linear-gradient(171deg, transparent 47.75%, red 49.5%, darkred 50.5%, transparent 52.25%); text-decoration: line-through; text-decoration-color: transparent;">
                        {$i.reporting_home_office_not}: {if empty($sums.home_office_not_all)}0{else}{isfloat value=$sums.home_office_not_all maxf=0}{/if}
                    </span>
                </td>
            {/if}
        </tr>
    </tbody>
</table>
    
<p style="margin:1mm;">
    {if $all_overtime_ok}
        {$i.reporting_overtime_ok}
    {else}
        <span style="background-color:#FFFF66;" class="ui-corner-all">{$i.reporting_overtime_not_ok}</span>
    {/if}
    {if !$all_set_ok}
        <br /><span style="background-color:#FFCC66;" class="ui-corner-all">{$i.reporting_set_not_ok}</span>
    {/if}
    {if !$all_set_limit}
        <br /><span style="background-color:#FF6666;" class="ui-corner-all">{$i.reporting_set_not_limit}</span>
    {/if}
</p>

<!-- ------------------------------------- Überstunden ------------------------------------- -->

{if $timelog_add_overtime}
<table class="editablepop" style="margin-top: 3mm; clear:both;">
    <colgroup>
        <col style="width:80mm;"></col>
        {if $timelog_overtime_paid_before}<col style="width:40mm;"></col>{/if}
        {if $timelog_overtime_paid_between}<col style="width:40mm;"></col>{/if}
        {if $timelog_overtime_before}<col style="width:40mm;"></col>{/if}
        <col style="width:40mm;"></col>
    </colgroup>
    <thead>
        <tr>
            <th>{$i.reporting_overtime}</th>
            {if $timelog_overtime_paid_before}<th>{$i.reporting_overtime_paid_before}</th>{/if}
            {if $timelog_overtime_paid_between}<th>{$i.reporting_overtime_paid_between}</th>{/if}
            {if $timelog_overtime_before}<th>{$i.reporting_overtime_before}</th>{/if}
            <th>{$i.reporting_overtime_upto}</th>
        </tr>
    </thead>
    <tbody>
        {$sum_paid_before=0}{$sum_paid_between=0}{$sum_before=0}{$sum_number=0}
        {foreach item="overtime" from=$overtime_pool_upto}
            {$number_paid_between=0}
            {if isset($overtime->number_paid_between)}
                {$number_paid_between = $overtime->number_paid_between}
            {/if}
            {$number_paid_before=0}
            {if isset($overtime->number_paid_before)}
                {$number_paid_before = $overtime->number_paid_before}
            {/if}            
            
            {$number_before=0}
            {if isset($overtime->number_before)}
                {$number_before = $overtime->number_before}
            {/if}    

            {$sum_paid_before=$sum_paid_before+$number_paid_before}
            {$sum_paid_between=$sum_paid_between+$number_paid_between}
            {$sum_before=$sum_before+$number_before}
            {$sum_number=$sum_number+$overtime->number}
            <tr>
                <th style="text-align:left;">{$overtime->name}</th>
                {if $timelog_overtime_paid_before}<td class="floatval">{float_to_usnumber(-$number_paid_before,2)}</td>{/if}
                {if $timelog_overtime_paid_between}<td class="floatval">{float_to_usnumber(-$number_paid_between,2)}</td>{/if}
                {if $timelog_overtime_before}<td class="floatval">{float_to_usnumber($number_before,2)}</td>{/if}
                <td class="floatval">{float_to_usnumber($overtime->number,2)}</td>
            </tr>
        {/foreach}
        <tr class="ui-widget-header">
            <th style="text-align:left;">{$i.reporting_rep_x_total}</th>
            {if $timelog_overtime_paid_before}<td class="floatval">{float_to_usnumber(-$sum_paid_before,2)}</td>{/if}
            {if $timelog_overtime_paid_between}<td class="floatval">{float_to_usnumber(-$sum_paid_between,2)}</td>{/if}
            {if $timelog_overtime_before}<td class="floatval">{float_to_usnumber($sum_before,2)}</td>{/if}
            <td class="floatval">{float_to_usnumber($sum_number,2)}</td>
        </tr>
    </tbody>
</table>
{/if}

<!-- ------------------------------------- Urlaubssaldo ------------------------------------- -->
{if $has_right_holiday && $timelog_balance}
<table class="editablepop" style="margin-top:4mm; clear:both;">
    <tbody>
        <tr>
            <td style="width:80mm;">{$i.reporting_balance_print}: </td>
            <td style="width:40mm;">{isfloat value=$vacation_balance} {$i.basic_days}</td>
            <td style="width:60mm;">{$i.reporting_deadline}: </td>
            <td style="width:40mm;">{if isset($vacation_deadline)}{$vacation_deadline}{/if}</td>
        </tr>
    </tbody>
</table>
{/if}

<!-- ------------------------------------- Unterschriften ------------------------------------- -->

<div style="display:none; pd4ml-display:block; margin:2mm; margin-top:5mm; margin-bottom:0; clear:both;">
    <div style="width:80mm; float:left; margin-top:5mm;">
        <textarea style="width:80mm; height:28px; font-size:20px; border:0 none; margin:0; padding:0;" rows="1" cols="50"></textarea>
        <div style="border-top:1px solid gray; width:100%;">{$i.reporting_manager}</div>
    </div>
    
    <div style="width:80mm; float:right; margin-top:5mm;">
        <textarea style="width:80mm; height:28px; font-size:20px; border:0 none; margin:0; padding:0;" rows="1" cols="50"></textarea>
        <div style="border-top:1px solid gray; width:100%;">{$i.reporting_staff}</div>
    </div>
</div>
