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

    <style>
        @page {
            margin: 130px 15px 70px 15px;
        }

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

        /* ========================= HEADER ========================== */
        .header {
            position: fixed;
            top: -110px;
            left: 0;
            right: 0;
            height: 90px;
        }
        .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; }
        .clearfix::after { content: ""; display: table; clear: both; }

        /* ========================= FOOTER ========================== */
        .footer {
            position: fixed;
            bottom: -50px;
            left: 0;
            right: 0;
            height: 40px;
            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;
            font-size: 7px;
        }
        th, td {
            border: 1px solid #000;
            padding: 3px 2px;
            text-align: left;
        }
        th {
            background: #f2f2f2;
            font-weight: bold;
            font-size: 7px;
        }
        td.number { text-align: right; }

        .page-block {
            page-break-after: always;
        }
        .page-block:last-child {
            page-break-after: auto;
        }
    </style>
</head>
<body>

<!-- HEADER (repeats on every page) -->
<div class="header clearfix">
    <div class="header-left">
        <div class="report-name">Payroll Details Crosstab Report</div>
        <div class="company-name"><?php echo e($company->legal_name ?? $company->display_name ?? ''); ?></div>
        <div class="small-text">
            <?php echo e(trim(implode(', ', array_filter([$company->address_line1 ?? null, $company->address_line2 ?? null])))); ?>

        </div>
        <div class="small-text">
            <?php if(!empty($filters['from_date']) && !empty($filters['to_date'])): ?>
                Period: <?php echo e(\Carbon\Carbon::parse($filters['from_date'])->format('d M Y')); ?>

                to <?php echo e(\Carbon\Carbon::parse($filters['to_date'])->format('d M Y')); ?>

            <?php endif; ?>
        </div>
    </div>
    <div class="header-right">
        <?php if(!empty($company->logo)): ?>
            <img src="<?php echo e(public_path($company->logo)); ?>" height="70">
        <?php endif; ?>
    </div>
</div>

<!-- FOOTER (repeats on every page) -->
<div class="footer">
    <div class="footer-left">LaraOffice</div>
    <div class="footer-center"><span class="page-number"></span></div>
    <div class="footer-right">Printed: <?php echo e(now()->format('Y-m-d H:i')); ?></div>
</div>

<!-- CONTENT -->
<?php
    $currency    = optional($company->baseCurrency)->symbol ?? 'Rs.';
    $rowsPerPage = 25;
    $colsPerPage = 8;

    // Build ordered dynamic column list
    $dynamicCols = [];
    $dynamicCols[] = ['type' => 'basic',  'label' => "Basic ($currency)"];
    foreach ($all_additions as $a) {
        $dynamicCols[] = ['type' => 'addition',  'id' => $a->id, 'label' => $a->payslip_label ?: $a->name];
    }
    $dynamicCols[] = ['type' => 'gross',  'label' => "Gross ($currency)"];
    foreach ($all_deductions as $d) {
        $dynamicCols[] = ['type' => 'deduction', 'id' => $d->id, 'label' => $d->payslip_label ?: $d->name];
    }
    foreach ($all_loans as $l) {
        $dynamicCols[] = ['type' => 'loan', 'id' => $l->id, 'label' => $l->name . ' Rec.'];
    }
    $dynamicCols[] = ['type' => 'net',   'label' => "Net ($currency)"];
    $dynamicCols[] = ['type' => 'epf12', 'label' => 'EPF 12%'];
    $dynamicCols[] = ['type' => 'etf3',  'label' => 'ETF 3%'];

    $colChunks = array_chunk($dynamicCols, $colsPerPage);
    $rowChunks = array_chunk($rows, $rowsPerPage);

    $totalPages     = count($rowChunks) * count($colChunks);
    $pageBlockIndex = 0;
?>

<?php $__currentLoopData = $rowChunks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rowChunk): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <?php $__currentLoopData = $colChunks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $colChunk): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <?php
        $pageBlockIndex++;
        $isLast     = ($pageBlockIndex === $totalPages);
        $dynCount   = count($colChunk);
        // Identity cols take 38%, dynamic cols share 62%
        $dynColPct  = round(62 / $dynCount, 2);
    ?>
    <div class="<?php echo e($isLast ? '' : 'page-block'); ?>">
        <table>
            <thead>
                <tr>
                    <th style="width:5%">EMP No</th>
                    <th style="width:5%">EPF No</th>
                    <th style="width:13%">Name</th>
                    <th style="width:8%">Department</th>
                    <th style="width:7%">Designation</th>
                    <?php $__currentLoopData = $colChunk; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $col): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <th style="width:<?php echo e($dynColPct); ?>%"><?php echo e($col['label']); ?></th>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $rowChunk; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($row['employee']->employee_code); ?></td>
                    <td><?php echo e($row['employee']->epf_no ?? '-'); ?></td>
                    <td><?php echo e(trim($row['employee']->first_name . ' ' . $row['employee']->middle_name . ' ' . $row['employee']->last_name)); ?></td>
                    <td><?php echo e(optional($row['department'])->name ?? '-'); ?></td>
                    <td><?php echo e(optional($row['designation'])->name ?? '-'); ?></td>
                    <?php $__currentLoopData = $colChunk; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $col): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $val = match($col['type']) {
                            'basic'     => $row['basic_salary'],
                            'gross'     => $row['gross_salary'],
                            'net'       => $row['net_salary'],
                            'epf12'     => $row['epf_12'],
                            'etf3'      => $row['etf_3'],
                            'addition'  => $row['additions'][$col['id']]  ?? 0,
                            'deduction' => $row['deductions'][$col['id']] ?? 0,
                            'loan'      => $row['loans'][$col['id']]      ?? 0,
                            default     => 0,
                        };
                    ?>
                    <td class="number"><?php echo e(number_format($val, 2)); ?></td>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

</body>
</html>
<?php /**PATH /home/codeproh/va.laraoffice.com/app/Modules/HR/Reports/Providers/../Views/pdf/payroll-details-crosstab.blade.php ENDPATH**/ ?>