<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Addition &amp; Deduction Details Report</title>
    @include('hr_reports::pdf.partials._styles')
</head>
<body>
@include('hr_reports::pdf.partials._header', ['reportTitle' => 'Addition & Deduction Details Report', 'filters' => $filters ?? []])
@include('hr_reports::pdf.partials._footer')

@foreach($employeeChunks as $empChunk)
    @foreach($columnChunks as $colChunk)
    <table>
        <thead>
            <tr>
                <th style="width:7%">Emp Code</th>
                <th style="width:6%">EPF</th>
                <th style="width:18%">Name</th>
                <th style="width:10%">Department</th>
                <th style="width:9%">Designation</th>
                @foreach($colChunk as $col)
                    <th class="tr">{{ $col['name'] }}</th>
                @endforeach
            </tr>
        </thead>
        <tbody>
            @foreach($empChunk as $emp)
            <tr>
                <td>{{ $emp->employee_code }}</td>
                <td>{{ $emp->epf_no }}</td>
                <td>{{ trim($emp->first_name . ' ' . ($emp->middle_name ?? '') . ' ' . $emp->last_name) }}</td>
                <td>{{ optional($emp->department)->name }}</td>
                <td>{{ optional($emp->designation)->name }}</td>
                @foreach($colChunk as $col)
                    @php
                        $value = $col['type'] === 'addition'
                            ? $emp->additions->where('addition_id', $col['id'])->first()
                            : $emp->deductions->where('deduction_id', $col['id'])->first();
                    @endphp
                    <td class="tr">{{ $value ? number_format($value->amount, 2) : '0.00' }}</td>
                @endforeach
            </tr>
            @endforeach
        </tbody>
    </table>
    @if(!($loop->parent->last && $loop->last))
        <div style="page-break-after: always;"></div>
    @endif
    @endforeach
@endforeach
</body>
</html>
