<?php
/** Recent supplier bills feed for procurement / finance dashboards. */
$rows = $this->data['feed_bills'] ?? [];
$badge = ['draft'=>'secondary','posted'=>'warning text-dark','paid'=>'success','void'=>'dark'];
?>
<div class="card border-0 shadow-sm h-100">
  <div class="card-body p-0">
    <div class="p-3 pb-2 d-flex justify-content-between align-items-center">
      <h6 class="text-uppercase text-muted small mb-0">Recent supplier bills</h6>
      <a href="<?= PROOT; ?>SupplierBills" class="small text-decoration-none">All &rarr;</a>
    </div>
    <?php if (empty($rows)): ?>
      <div class="text-center text-muted small py-4">No bills yet.</div>
    <?php else: ?>
      <table class="table table-sm mb-0">
        <tbody>
          <?php foreach ($rows as $b): $bg = $badge[$b['status']] ?? 'light'; $bal = (float)$b['total_amount'] - (float)$b['amount_paid']; ?>
            <tr>
              <td>
                <a href="<?= PROOT; ?>SupplierBills/view/<?= (int)$b['c0d']; ?>" class="text-decoration-none">
                  <div class="font-monospace small"><?= htmlspecialchars($b['bill_no']); ?></div>
                  <div class="small text-muted"><?= htmlspecialchars($b['vendor_name'] ?: '—'); ?> &middot; <?= humanDate($b['bill_date']); ?></div>
                </a>
              </td>
              <td class="text-end">
                <div class="fw-bold font-monospace small">TZS <?= number_format($bal, 0); ?></div>
                <div class="badge bg-<?= $bg; ?> small"><?= htmlspecialchars($b['status']); ?></div>
              </td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>
    <?php endif; ?>
  </div>
</div>
