<div class="row">
    <div class="col-12">
        <div class="card glass-card">
            <div class="card-header"><h5 class="card-title">Sales Report</h5></div>
            <div class="card-body">
                <?php $this->include('Reports/partials/filter_date') ?>
                <div class="table-responsive mt-3">
                    <table class="table table-hover">
                        <thead>
                            <tr><th>Date</th><th>Invoice #</th><th>Customer</th><th class="text-end">Subtotal</th><th class="text-end">Tax</th><th class="text-end">Total</th><th>Status</th></tr>
                        </thead>
                        <tbody>
                            <?php if (empty($data)): ?>
                            <tr><td colspan="7" class="text-center py-4 text-muted">No data available.</td></tr>
                            <?php else: ?>
                                <?php foreach ($data as $row): ?>
                                <tr>
                                    <td><?= date('d M Y', strtotime($row->created_at)) ?></td>
                                    <td><a href="<?= url('pos/invoices/' . $row->id) ?>">#<?= $row->id ?></a></td>
                                    <td><?= e($row->customer_name ?? 'Walk-in') ?></td>
                                    <td class="text-end"><?= currency($row->subtotal) ?></td>
                                    <td class="text-end"><?= currency($row->tax) ?></td>
                                    <td class="text-end fw-bold"><?= currency($row->total) ?></td>
                                    <td><span class="badge bg-<?= $row->status === 'paid' ? 'success' : 'warning' ?>"><?= e($row->status) ?></span></td>
                                </tr>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </tbody>
                        <?php if (!empty($data)): ?>
                        <tfoot>
                            <tr class="fw-bold">
                                <td colspan="3" class="text-end">Totals:</td>
                                <td class="text-end"><?= currency(array_sum(array_column($data, 'subtotal'))) ?></td>
                                <td class="text-end"><?= currency(array_sum(array_column($data, 'tax'))) ?></td>
                                <td class="text-end"><?= currency(array_sum(array_column($data, 'total'))) ?></td>
                                <td></td>
                            </tr>
                        </tfoot>
                        <?php endif; ?>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
