<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<h4>Data Penjualan</h4>

<?php if (session()->getFlashdata('success')): ?>
    <div class="alert alert-success"><?= session()->getFlashdata('success') ?></div>
<?php endif; ?>

<a href="<?= base_url('admin/sales/create') ?>" class="btn btn-primary mb-3">+ Tambah Penjualan</a>

<table class="table table-bordered table-striped">
    <thead>
        <tr>
            <th>#</th>
            <th>Kode</th>
            <th>Tanggal</th>
            <th>Pelanggan</th>
            <th>Total</th>
            <th>Metode</th>
            <th>User</th>
            <th>Aksi</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($sales as $key => $sale): ?>
            <tr>
                <td><?= $key + 1 ?></td>
                <td><?= esc($sale['kode']) ?></td>
                <td><?= esc($sale['tanggal']) ?></td>
                <td><?= esc($sale['customer_name'] ?? '-') ?></td>
                <td>Rp<?= number_format($sale['total'], 0, ',', '.') ?></td>
                <td><?= ucfirst($sale['payment_method']) ?></td>
                <td><?= esc($sale['user_name'] ?? '-') ?></td>
                <td>
                    <a href="<?= base_url('admin/sales/detail/' . $sale['id']) ?>" class="btn btn-info btn-sm">Detail</a>
                    <!-- bisa tambahkan cetak/faktur di sini -->
                </td>
            </tr>
        <?php endforeach ?>
    </tbody>
</table>

<?= $this->endSection() ?>
