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

<div class="card card-emerald card-outline card-tabs shadow">
    <div class="card-header p-0 pt-1 border-bottom-0">
        <ul class="nav nav-tabs" id="custom-tabs-three-tab" role="tablist">
            <li class="nav-item">
                <a class="nav-link active text-emerald font-weight-bold" id="tabs-harian-tab" data-toggle="pill" href="#tabs-harian" role="tab"><i class="fas fa-calendar-day mr-1"></i> Rekap Harian</a>
            </li>
            <li class="nav-item">
                <a class="nav-link text-emerald font-weight-bold" id="tabs-bulanan-tab" data-toggle="pill" href="#tabs-bulanan" role="tab"><i class="fas fa-calendar-alt mr-1"></i> Rekap Bulanan</a>
            </li>
        </ul>
    </div>
    <div class="card-body p-0">
        <div class="tab-content" id="custom-tabs-three-tabContent">
            
            <div class="tab-pane fade show active" id="tabs-harian" role="tabpanel">
                <table class="table table-hover table-striped mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th>Tanggal Penyaluran</th>
                            <th>Nama Pupuk</th>
                            <th>Total Keluar Harian</th>
                            <th>Total Perputaran Uang</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if(empty($harian)): ?>
                            <tr><td colspan="4" class="text-center text-muted py-4">Belum ada transaksi penebusan harian.</td></tr>
                        <?php else: ?>
                            <?php foreach($harian as $h): ?>
                            <tr>
                                <td><b><?= date('d/m/Y', strtotime($h['tanggal'])) ?></b></td>
                                <td><?= $h['nama_pupuk'] ?></td>
                                <td><span class="badge badge-danger"><?= $h['total_kg'] ?> Kg</span></td>
                                <td class="text-success font-weight-bold">Rp <?= number_format($h['total_dana'], 0, ',', '.') ?></td>
                            </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>

            <div class="tab-pane fade" id="tabs-bulanan" role="tabpanel">
                <table class="table table-hover table-striped mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th>Bulan / Tahun</th>
                            <th>Nama Pupuk</th>
                            <th>Total Keluar Sebulan</th>
                            <th>Total Pendapatan HET</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if(empty($bulanan)): ?>
                            <tr><td colspan="4" class="text-center text-muted py-4">Belum ada data penebusan bulanan.</td></tr>
                        <?php else: ?>
                            <?php foreach($bulanan as $b): ?>
                            <tr>
                                <td><b>
                                    <?php 
                                        $nama_bulan = ["", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"];
                                        echo $nama_bulan[$b['bulan']] . ' ' . $b['tahun'];
                                    ?>
                                </b></td>
                                <td><?= $b['nama_pupuk'] ?></td>
                                <td><span class="badge badge-warning text-dark font-weight-bold"><?= $b['total_kg'] ?> Kg</span></td>
                                <td class="text-success font-weight-bold">Rp <?= number_format($b['total_dana'], 0, ',', '.') ?></td>
                            </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>

        </div>
    </div>
</div>

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