<?php $this->start('body');
    $stat     = $this->v('status');
    $statuses = ['DRAFT','SCHEDULED','PAID','CANCELLED'];
?>

<div class="d-flex align-items-center justify-content-between mb-3">
    <h5 class="mb-0" style="font-weight:600;"><i class="fas fa-money-check-alt me-2 text-muted"></i>Payment Vouchers</h5>
    <a href="<?= PROOT; ?>Payables" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-left me-1"></i> Payables Queue</a>
</div>

<div class="mb-2 d-flex flex-wrap gap-1">
    <a href="<?= PROOT; ?>PaymentVouchers" class="badge <?= $stat===''?'bg-dark':'bg-light text-muted'; ?>" style="text-decoration:none;padding:.35em .6em;">All</a>
    <?php foreach ($statuses as $s):
        $active = ($stat === $s);
        $cls    = $active ? 'bg-dark' : 'bg-light text-muted';
    ?>
        <a href="<?= PROOT; ?>PaymentVouchers?status=<?= $s; ?>" class="badge <?= $cls; ?>" style="text-decoration:none;padding:.35em .6em;text-transform:capitalize;">
            <?= htmlspecialchars(strtolower($s)); ?>
        </a>
    <?php endforeach; ?>
</div>

<div class="card border-0 shadow-sm">
    <div class="table-responsive">
        <table class="table table-sm mb-0 align-middle">
            <thead class="table-light">
                <tr>
                    <th>PV #</th><th>LPO</th><th>Project</th><th>Payee</th>
                    <th class="text-end">Amount</th><th>Scheduled</th><th>Paid</th><th>Status</th><th></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($this->data['rows'] as $r):
                    $sc = [
                        'DRAFT'     => 'bg-light text-muted',
                        'SCHEDULED' => 'bg-info text-white',
                        'PAID'      => 'bg-success',
                        'CANCELLED' => 'bg-secondary',
                    ][$r['status']] ?? 'bg-light text-muted';
                ?>
                    <tr>
                        <td><a href="<?= PROOT; ?>PaymentVouchers/view/<?= (int)$r['c0d']; ?>" class="text-decoration-none"><strong><?= htmlspecialchars($r['pv_no']); ?></strong></a></td>
                        <td><a href="<?= PROOT; ?>Lpos/view/<?= (int)($r['c0d']); ?>" class="text-muted small text-decoration-none"><?= htmlspecialchars($r['lpo_no']); ?></a></td>
                        <td class="text-muted small"><?= htmlspecialchars($r['project_no'] ?: '(central)'); ?></td>
                        <td><?= htmlspecialchars($r['payee_name']); ?></td>
                        <td class="text-end"><?= htmlspecialchars($r['currency']); ?> <?= number_format((float)$r['amount']); ?></td>
                        <td class="text-muted small"><?= htmlspecialchars($r['scheduled_on'] ?: '—'); ?></td>
                        <td class="text-muted small"><?= htmlspecialchars($r['paid_on'] ?: '—'); ?></td>
                        <td><span class="badge <?= $sc; ?>" style="text-transform:capitalize;"><?= htmlspecialchars(strtolower($r['status'])); ?></span></td>
                        <td class="text-end"><a href="<?= PROOT; ?>PaymentVouchers/view/<?= (int)$r['c0d']; ?>" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-right"></i></a></td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($this->data['rows'])): ?>
                    <tr><td colspan="9" class="text-center text-muted py-4">No payment vouchers <?= $stat ? 'with status ' . htmlspecialchars(strtolower($stat)) : ''; ?>.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<?php $this->end(); ?>
