<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-boxes"></span> Daftar Jenis Pembayaran</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="small check_all"></th>
                                            <th>Edit</th>
                                            <th>Kode</th>
                                            <th>Nama Pembayaran</th>
                                            <th>Bulanan</th>
                                            <th>Status Blok</th>
                                            <th>Untuk Kelas</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php
                                        $nama_bayar = new namaBayar();
                                        $showUser = $nama_bayar->nama('tb_nama_bayar', 'tp', $tahun, 'kode');
                                        while ($data = $showUser->fetch(PDO::FETCH_OBJ)) {
                                            $link = new linkpage;

                                            if ($data->blok == "no") {
                                                $blok = "Tidak";
                                            } else {
                                                $blok = "Ya";
                                            };
                                            echo "
                                                    <tr>
                                                        <td width='5px'>
                                                            <input type='checkbox' class='d-inline small chk_boxes1' name='id_bayar[]' value='$data->no'> 
                                                        </td>
                                                        <td width='75px' align='center'>
                                                        <a " . $link->pageID($data->id, 'seting/jenisPembayaran/jenisPembayaran_edit') . " class='badge badge-primary  px-1 py-1 d-inline''> <i class='bi bi-pencil-square'></i> EDIT</a>
                                                        </td>
                                                        <td>$data->kode</td>
                                                        <td>$data->nama</td>
                                                        <td>$data->bulanan</td>
                                                        <td>$blok</td>
                                                        <td>$data->kelas</td>
                                                        </tr>";
                                        };
                                        ?>
                                    </tbody>
                                </table>
                                <div class="div d-inline">
                                    <a <?php echo $link->page('seting/jenisPembayaran/jenisPembayaran_create'); ?> class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-person-plus"></i> TAMBAH</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>
                                    <a <?php echo $link->page('seting/jenisPembayaran/jenisPembayaran_copytl'); ?> class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-files"></i> COPY TAHUN LALU</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </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']) && isset($_POST['id_bayar'])) {
    foreach ($_POST['id_bayar'] as $id) {
        $user_admin = new crudData();
        $delete = $user_admin->deleteData('tb_nama_bayar', 'no', $id);
    };

    $direct = new toast();
    echo  $direct->redirect('toast', 'delete', 'seting/jenisPembayaran/jenisPembayaran_read');
};
