<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h4 class="mb-0">Laporan Iuran Tahun <?php echo $tahun; ?></h4>
        <form method="get" class="d-flex gap-2">
            <select name="tahun" class="form-select">
                <?php for($y=date('Y'); $y>=2020; $y--): ?>
                    <option value="<?php echo $y; ?>" <?php echo ($y == $tahun) ? 'selected' : ''; ?>><?php echo $y; ?></option>
                <?php endfor; ?>
            </select>
            <button type="submit" class="btn btn-primary">Tampilkan</button>
        </form>
    </div>

    <div class="table-container">
        <table class="table table-bordered table-hover">
            <thead class="table-light">
                <tr>
                    <th>Bulan</th>
                    <th>Iuran Kebersihan</th>
                    <th>Iuran Keamanan</th>
                    <th>Iuran Sampah</th>
                    <th>Total</th>
                </tr>
            </thead>
            <tbody>
                <?php 
                $total_kebersihan = 0;
                $total_keamanan = 0;
                $total_sampah = 0;
                $grand_total = 0;
                
                $nama_bulan = array('Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
                
                foreach($laporan as $l): 
                    $total_kebersihan += $l->iuran_kebersihan;
                    $total_keamanan += $l->iuran_keamanan;
                    $total_sampah += $l->iuran_sampah;
                    $grand_total += $l->total;
                ?>
                <tr>
                    <td><?php echo $nama_bulan[$l->bulan-1]; ?></td>
                    <td>Rp <?php echo number_format($l->iuran_kebersihan, 0, ',', '.'); ?></td>
                    <td>Rp <?php echo number_format($l->iuran_keamanan, 0, ',', '.'); ?></td>
                    <td>Rp <?php echo number_format($l->iuran_sampah, 0, ',', '.'); ?></td>
                    <td class="fw-bold">Rp <?php echo number_format($l->total, 0, ',', '.'); ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
            <tfoot class="table-light fw-bold">
                <tr>
                    <td>TOTAL</td>
                    <td>Rp <?php echo number_format($total_kebersihan, 0, ',', '.'); ?></td>
                    <td>Rp <?php echo number_format($total_keamanan, 0, ',', '.'); ?></td>
                    <td>Rp <?php echo number_format($total_sampah, 0, ',', '.'); ?></td>
                    <td>Rp <?php echo number_format($grand_total, 0, ',', '.'); ?></td>
                </tr>
            </tfoot>
        </table>
    </div>
</div>