<?php /* stock/expiry.php */ ?>
<div class="d-flex justify-content-between align-items-center mb-3">
  <h5 class="fw-semibold mb-0">Near Expiry Alert <span class="badge bg-warning text-dark ms-1"><?= count($products) ?></span></h5>
  <a href="<?= APP_URL ?>/stock" class="btn btn-sm btn-outline-secondary">Back</a>
</div>
<div class="card"><div class="card-body p-0"><div class="table-responsive">
  <table class="table table-hover mb-0">
    <thead><tr><th>Product</th><th>Batch No</th><th>Expiry Date</th><th>Days Left</th><th class="text-end">Qty</th></tr></thead>
    <tbody>
      <?php foreach($products as $p): ?>
      <tr class="<?= $p['days_to_expiry']<=7?'table-danger':($p['days_to_expiry']<=14?'table-warning':'') ?>">
        <td><div class="fw-semibold small"><?= e($p['product_name']) ?></div><small class="text-muted"><?= e($p['product_code']) ?></small></td>
        <td><?= e($p['batch_no']) ?></td>
        <td><?= fDate($p['expiry_date']) ?></td>
        <td><span class="badge <?= $p['days_to_expiry']<=7?'bg-danger':($p['days_to_expiry']<=14?'bg-warning text-dark':'bg-info') ?>"><?= $p['days_to_expiry'] ?> days</span></td>
        <td class="text-end fw-semibold"><?= number_format($p['quantity'],2) ?></td>
      </tr>
      <?php endforeach; ?>
      <?php if(empty($products)): ?><tr><td colspan="5" class="text-center text-success py-4"><i class="bi bi-check-circle me-2"></i>No products expiring soon</td></tr><?php endif; ?>
    </tbody>
  </table>
</div></div></div>
