<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Over Time 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">
            Over Time 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' }}
        </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>


    @if($single_employee)

        <table border="1" width="100%" cellpadding="6" cellspacing="0">

            <tr style="background:#f5f5f5; font-weight:bold;">
                <th>Date</th>
                <th>Shift</th>
                <th>OT Hrs</th>
                <th>DOT Hrs</th>
                <th>Total OT</th>
            </tr>

            @foreach($records as $row)

            @php
            $totalOt = $row->ot_hrs + $row->dot_hrs;
            @endphp

            <tr>
                <td>{{ $row->attendance->attendance_date->format('Y-m-d') }}</td>
                <td>{{ optional($row->shift)->name }}</td>
                <td>{{ $row->ot_hrs }}</td>
                <td>{{ $row->dot_hrs }}</td>
                <td>{{ number_format($totalOt,2) }}</td>
            </tr>

            @endforeach

        </table>

    @endif


    @if(!$single_employee)

        <table border="1" width="100%" cellpadding="6" cellspacing="0">

            @foreach($grouped as $department => $rows)

                <tr style="background:#eaeaea; font-weight:bold;">
                    <td colspan="7">Department: {{ $department }}</td>
                </tr>

                <tr style="background:#f5f5f5; font-weight:bold;">
                    <th>Emp Code</th>
                    <th>Name</th>
                    <th>Date</th>
                    <th>Shift</th>
                    <th>OT Hrs</th>
                    <th>DOT Hrs</th>
                    <th>Total OT</th>
                </tr>

                @foreach($rows as $row)

                    @php
                    $totalOt = $row->ot_hrs + $row->dot_hrs;
                    @endphp

                    <tr>
                        <td>{{ $row->employee->employee_code }}</td>
                        <td>{{ $row->employee->first_name }} {{ $row->employee->last_name }}</td>
                        <td>{{ $row->attendance->attendance_date->format('Y-m-d') }}</td>
                        <td>{{ optional($row->shift)->name }}</td>
                        <td>{{ $row->ot_hrs }}</td>
                        <td>{{ $row->dot_hrs }}</td>
                        <td>{{ number_format($totalOt,2) }}</td>
                    </tr>

                    @endforeach

            @endforeach

        </table>

    @endif

</body>
</html>
