<!-- tagihan -->
<div class="x_title" style="text-transform: capitalize;">
    <h2>Data Tagihan</h2>
    <div class="clearfix"></div>
</div>

<div class="accordion" id="accordionExample">
    <div class="card">
        <div class="card-header" id="headingThree">
            <h5 class="mb-0">
                <button type="button" class="collapsible" data-toggle="collapse" data-target="#collapseThree">TAGIHAN SPP</button>
            </h5>
        </div>
        <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionExample">
            <div class="card-body">
                <table class="Projects table table-responsive table-striped table-bordered dataTable " id="datatable">
                    <thead>
                        <tr>
                            <th width="10px">No</th>
                            <th width="110px">Jenis</th>
                            <th>Bulan</th>
                            <th>Tahun</th>
                            <!--<th>No Rekening</th>-->
                            <th>dibayar</th>
                            <th>Total</th>
                            <th>Pembayaran</th>
                            <th>Kekurangan</th>
                            <th>Status</th>

                        </tr>
                    </thead>
                    <tbody style="background-color:lightgoldenrodyellow;">

                        <?php
                        //sort tagihan

                        $t1 = 2021;
                        $b1 = 1;
                        $t2 = date('Y');
                        $n = 0;
                        $b2 = date('m');


                        //sort tagihan

                        $thsantri = 2021;
                        $blnsantri = 3;
                        $thini = date('Y');

                        $t1 = $thsantri;
                        $t2 = date('Y');
                        $n = 0;


                        for ($t2; $t2 >= $t1; $t2--) {
                            if ($thsantri == date('Y')) {
                                $b2 = date('n');
                                $b1 = $blnsantri;
                            } else {
                                if ($t2 > $t1 && $t2 != $thini) {
                                    $b2 = 12;
                                    $b1 = 1;
                                } elseif ($t2 == $thini) {
                                    $b2 = date('n');
                                    $b1 = 1;
                                } elseif ($t2 == $t1) {
                                    $b2 = 12;
                                    $b1 = $blnsantri;
                                }
                            }




                            for ($b2; $b2 >= $b1; $b2--) {
                                $n++;
                        ?>
                                <!-- spp -->
                                <tr>
                                    <td><?php echo $n; ?></td>
                                    <td>SPP</td>
                                    <td><?php echo namabulan($b2); ?></td>
                                    <td><?php echo $t2; ?></td>
                                    <td><?php
                                        $tot = 0;
                                        $keri = mysqli_query($conn, "SELECT * FROM transaksi WHERE id_donatur='$id' AND id_jenis='10' AND spp_bulan=$b2 AND spp_tahun=$t2 order by tanggal DESC ");
                                        while ($ri = mysqli_fetch_array($keri)) {
                                            $tgl = date('d/m/y', strtotime($ri['tanggal']));
                                            echo "[" . $tgl . "~" . rupiah($ri['debit']) . "]<br>";
                                            $tot = $tot + $ri['debit'];
                                        }
                                        $sisa = $r['biaya_spp'] - $tot;
                                        ?></td>
                                    <td><?php echo rupiah($tot); ?></td>
                                    <td><?php echo rupiah($r['biaya_spp']); ?></td>
                                    <td><?php echo rupiah($sisa); ?></td>
                                    <td>
                                        <?php $cekstatus = mysqli_query($conn, "SELECT * FROM status_lunas WHERE id_donatur='$id' AND id_jenis='10' AND spp_bulan=$b2 AND spp_tahun=$t2");
                                        $status = mysqli_fetch_array($cekstatus);

                                        if ($status > 0) {
                                            echo "<font color=#0082da><b>lunas</b></font>";
                                        } else {
                                            echo "<font color=#f01519><b>Belum Lunas</b></font>";
                                        }


                                        ?>
                                    </td>
                                </tr>

                        <?php

                            }
                            // $b2 = 12;
                        }

                        ?>

                    </tbody>

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