<?= $this->extend('layouts/owner') ?>

<?= $this->section('content') ?>
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h4 class="mb-0">Dashboard Keuangan</h4>
    </div>

    <!-- Ringkasan Statistik -->
    <div class="row">
        <div class="col-md-4">
            <div class="card bg-primary text-white p-3 shadow-sm">
                <h6>Total Pendapatan</h6>
                <h3>Rp <?= number_format($total_pendapatan ?? 0) ?></h3>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card bg-success text-white p-3 shadow-sm">
                <h6>Total Profit</h6>
                <h3>Rp <?= number_format($total_profit ?? 0) ?></h3>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card bg-warning text-dark p-3 shadow-sm">
                <h6>Target Profit</h6>
                <h3>Rp <?= number_format($target_profit ?? 0) ?></h3>
            </div>
        </div>
    </div>

    <!-- Tabel Transaksi -->
    <div class="card mt-4 shadow-sm">
        <div class="card-header bg-white">
            <h5 class="mb-0">Laporan Transaksi Terakhir</h5>
        </div>
        <div class="card-body">
            <table class="table table-bordered table-hover">
                <thead class="table-light">
                    <tr>
                        <th>Tanggal</th>
                        <th>Nomor Order</th>
                        <th>Produk</th>
                        <th>Subtotal</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(empty($reports)): ?>
                        <tr><td colspan="4" class="text-center text-muted">Belum ada data transaksi.</td></tr>
                    <?php else: ?>
                        <?php foreach($reports as $r): ?>
                        <tr>
                            <td><?= esc($r['tanggal_order']) ?></td>
                            <td><?= esc($r['nomor_order']) ?></td>
                            <td><?= esc($r['nama_product']) ?></td>
                            <td>Rp <?= number_format($r['subtotal']) ?></td>
                        </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?= $this->endSection() ?>