<div class="content-wrapper">

    <?php require('./layout/headerpage.php'); ?>

    <div class="container col-12 mb-4 pb-5">
        <div class="row">
            <div class="col-12">
                <div class="col-12">
                    <div class="card  mx-3">
                        <div class="timeline-header bg-primary py-2 pl-2">
                            <b class="text-light judul"><span class="bi bi-person-bounding-box"></span> Data Nasabah</b>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body my-4 mx-4">
                            <form action="" method="post">
                                <table id="example3" class="table table-bordered table-striped table-hover table-sm  mb-4">
                                    <thead>
                                        <tr>
                                            <th><input type="checkbox" class=" check_all"></th>
                                            <th>Aksi</th>
                                            <th>NIS</th>
                                            <th>Nama Nasabah</th>
                                            <th>No. Rekening</th>
                                            <th>Kelas</th>
                                            <th>Saldo Awal</th>
                                            <th>Debet</th>
                                            <th>Kredit</th>
                                            <th>Saldo Akhir</th>
                                            <th>Status</th>
                                            <th width="120">Rekam Transaksi</th>
                                            <th width="120">Buku Tabungan</th>

                                        </tr>

                                    </thead>
                                    <tbody>


                                        <?php
                                        $clsCrud = new crudData();
                                        $show = $clsCrud->showTable($tabungan_siswa . " order by status asc, nama asc");
                                        while ($data = $show->fetch(PDO::FETCH_OBJ)) {

                                            $nis = $data->nis;
                                            $clsCrud = new crudData;

                                            //count tabel siswa
                                            $count = $clsCrud->countData($tb_siswa, " where nis='$nis'");
                                            if ($count > 0) {
                                                $kelas = $clsCrud->getValue($tb_siswa, " where nis='$nis'", 'jenjang') . "-" . $clsCrud->getValue($tb_siswa, " where nis='$nis'", 'paralel');
                                            } else {
                                                $kelas = "--";
                                            };

                                            $clsTabungan = new tabungan;
                                            $jmlDebet = $clsTabungan->SUMdebetKredit($tabungan_transaksi, 'D', " and nis='$data->nis'");
                                            $jmlKredit = $clsTabungan->SUMdebetKredit($tabungan_transaksi, 'K', " and nis='$data->nis'");

                                            $saldoAkhir = @($data->saldo) + $jmlDebet - $jmlKredit;

                                            $link = new linkpage;
                                            $linkpost = new linkpost;
                                            $format = new format;

                                            echo "
                                                    <tr>
                                                        <td width='5px'>
                                                            <input type='checkbox' class='d-inline small chk_boxes1' name='id_nasabah[]' value='$data->id'> 
                                                        </td>
                                                        <td width='75px' align='center'>
                                                            <a " . $link->pageID($data->id, 'nasabah/nasabah_edit') . " class='badge badge-primary  px-1 py-1 d-inline''> <i class='bi bi-pencil-square'></i> EDIT</a>
                                                        </td>
                                                        <td>$data->nis</td>
                                                        <td>$data->nama</td>
                                                        <td>$data->rekening</td>
                                                        <td>$kelas</td>
                                                        <td>" . $format->ribuan($data->saldo) . "</td>
                                                        <td>" . $format->ribuan($jmlDebet) . "</td>
                                                        <td>" . $format->ribuan($jmlKredit) . "</td>
                                                        <td>" . $format->ribuan($saldoAkhir) . "</td>
                                                        <td>$data->status</td>
                                                        <td width='75px' align='center'>
                                                        <a " . $link->pageID($data->id, 'transaksi/transaksi_read') . " class='badge badge-primary  px-1 py-1 d-inline''> <i class='bi bi-book'></i> TRANSAKSI</a>
                                                        </td>
                                                         <td width='75px' align='center'>
                                                        <a " . $link->pageIDReportSiswa($data->id, 'nasabah/buku_preview', $data->nis, $tahun) . " class='badge badge-primary  px-1 py-1 d-inline''> <i class='bi bi-printer'></i> BUKU TABUNGAN</a>
                                                        </td>
                                                        </tr>";
                                        };

                                        ?>

                                    </tbody>
                                </table>
                                <div class="div d-inline">
                                    <a <?php echo $link->page('nasabah/nasabah_create'); ?> class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-person-plus"></i> TAMBAH</a>
                                    <a <?php echo $link->page('nasabah/nasabah_import'); ?> class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-upload"></i> UPLOAD NASABAH</a>
                                    <button type="submit" name="submit" class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-trash"></i> HAPUS</button>
                                    <?php echo $link->exportXlsx('nasabah/nasabah_export', $tahun); ?>

                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--/. container-fluid -->
        </section>
        <!-- /.content -->
    </div>
</div>
<!-- /.content-wrapper -->
<script type="text/javascript">
    $(function() {
        $('.check_all').click(function() {
            $('.chk_boxes1').prop('checked', this.checked);
        });
    });
</script>

<?php
if (isset($_POST['submit'])) {
    foreach ($_POST['id_nasabah'] as $id) {
        $clsCrud = new crudData();
        $delete = $clsCrud->deleteData($tabungan_siswa, 'id', $id);
    };

    $direct = new toast();
    echo  $direct->redirect('toast', 'delete', 'nasabah/nasabah_read');
} else {
    echo '';
}



?>