<?php
// view: pages/sales/view
?>
<?php $inv = $inv ?? null; $lines = $lines ?? []; ?>

<div class="d-flex justify-content-between align-items-center mb-3">
  <div>
    <h4 class="mb-0">فاتورة: <?= e($inv['invoice_no']) ?></h4>
    <div class="text-muted">التاريخ: <?= e($inv['invoice_date']) ?></div>
  </div>
  <div class="d-flex gap-2">
    <a class="btn btn-outline-dark" href="<?= e(url('/sales/invoices')) ?>">رجوع</a>
    <a class="btn btn-dark" href="<?= e(url('/prints/sales-invoice')) ?>?id=<?= (int)$inv['id'] ?>" target="_blank">طباعة</a>
  </div>
</div>

<div class="card p-3">
  <div class="table-responsive">
    <div class="table-responsive"><table class="table table-bordered table-hover table-striped align-middle table-sm align-middle mb-0">
      <thead class="table-light">
        <tr>
          <th>الصنف</th>
          <th class="text-end">الكمية</th>
          <th class="text-end">السعر</th>
          <th class="text-end">الإجمالي</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($lines as $ln): ?>
          <tr>
            <td><?= e($ln['name']) ?></td>
            <td class="text-end"><?= format_qty($ln['qty']) ?></td>
            <td class="text-end"><?= format_money($ln['price']) ?></td>
            <td class="text-end"><?= format_money($ln['line_total']) ?></td>
          </tr>
        <?php endforeach; ?>
      </tbody>
      <tfoot class="table-light">
        <tr>
          <th colspan="3" class="text-end">الإجمالي</th>
          <th class="text-end"><?= format_money($inv['total']) ?></th>
        </tr>
      </tfoot>
    </table></div>
  </div>
</div>
