<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Timesheet Details Report</title>

    <style>
        @page {
            margin: 140px 40px 80px 40px;
        }

        body {
            font-family: DejaVu Sans, sans-serif;
            font-size: 12px;
            margin: 0;
        }

        /* =========================
           HEADER
        ========================== */
        .header {
            position: fixed;
            top: -120px;
            left: 0;
            right: 0;
            height: 100px;
        }

        .header-left {
            float: left;
            width: 70%;
        }

        .header-right {
            float: right;
            width: 30%;
            text-align: right;
        }

        .report-name {
            font-size: 15px;
            font-weight: bold;
        }

        .company-name {
            font-size: 13px;
            font-weight: bold;
        }


        .small-text {
            font-size: 11px;
        }

       .footer {
            position: fixed;
            bottom: -60px;
            left: 0;
            right: 0;
            height: 50px;
            font-size: 10px;
        }

        .footer-left {
            float: left;
            width: 33%;
            text-align: left;
        }

        .footer-center {
            float: left;
            width: 34%;
            text-align: center;
        }

        .footer-right {
            float: right;
            width: 33%;
            text-align: right;
        }

        .page-number:before {
            content: "Page " counter(page) " / " counter(pages);
        }

        /* =========================
           TABLE
        ========================== */
        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            border: 1px solid #000;
            padding: 5px;
            font-size: 8px;
        }

        th {
            background: #f2f2f2;
        }
    </style>
</head>
<body>

<!-- ================= HEADER ================= -->
<div class="header">
    <div class="header-left">
        <div class="report-name">
           Timesheet Details Report
        </div>
        <div class="company-name">
            {{ $company->legal_name ?? $company->display_name ?? '' }}
        </div>
        <div class="small-text">
            {{ trim(implode(', ', array_filter([$company->address_line1 ?? null, $company->address_line2 ?? null]))) }}
        </div>
        <div class="small-text">
            Branch: {{ $branch->name ?? 'All Branches' }} <br>
            From: {{ $from->format('Y-m-d') }} 
            To: {{ $to->format('Y-m-d') }}
        </div>
        
    </div>

    <div class="header-right">
        @if(!empty($company->logo))
            <img src="{{ public_path($company->logo) }}" height="70">
        @endif
    </div>
</div>

<!-- ================= FOOTER ================= -->
<div class="footer">
    <div class="footer-left">
        LaraOffice
    </div>

    <div class="footer-center">
        <span class="page-number"></span>
    </div>

    <div class="footer-right">
        Printed: {{ now()->format('Y-m-d H:i') }}
    </div>
</div>


<!-- ================= CONTENT ================= -->

@php
$currentDept = null;
$currentEmp = null;
@endphp

@foreach($records as $row)

    {{-- Department Group --}}
    @if($currentDept != optional($row->employee->department)->name)
        @php
            $currentDept = optional($row->employee->department)->name;
        @endphp

        <h5 style="margin-top:20px;">
            Department: {{ $currentDept }}
        </h5>
    @endif

    {{-- Employee Group --}}
    @if($currentEmp != $row->employee_id)
        @php
            $currentEmp = $row->employee_id;
        @endphp

        <h6>
            {{ $row->employee->employee_code }} -
            {{ $row->employee->first_name }} {{ $row->employee->last_name }}
            ({{ optional($row->employee->designation)->name }})
        </h6>

        <table border="1" width="100%" cellpadding="5" cellspacing="0">
            <thead>
            <tr style="background:#eaeaea; font-weight:bold;">
                <th>Date</th>
                <th>In Time</th>
                <th>Out Time</th>
                <th>Status</th>
                <th>Single OT</th>
                <th>Double OT</th>
                <th>Triple OT</th>
                <th>Late Mins</th>
            </tr>
            </thead>
            <tbody>
    @endif

    <tr>
        <td>{{ optional($row->attendance)->attendance_date }}</td>
        <td>{{ optional($row->in_time)->format('h:i A') }}</td>
        <td>{{ optional($row->out_time)->format('h:i A') }}</td>
        <td>{{ $row->attendance_status }}</td>
        <td>{{ gmdate('H:i', $row->ot_minutes * 60) }}</td>
        <td>{{ gmdate('H:i', $row->dot_minutes * 60) }}</td>
        <td>0:00</td>
        <td>{{ $row->late_minutes }}</td>
    </tr>

@endforeach
</body>
</html>
