<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-credit-card-2-back-fill"></span> Monitoring Payment Gateway</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>Waktu</th>
                                            <th>Nama</th>
                                            <th>NIS</th>
                                            <th>Kelas</th>
                                            <th>ID Billing</th>
                                            <th>Record</th>
                                            <th>Jumlah</th>
                                            <th>Status</th>
                                            <th>Cetak</th>

                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php
                                        $crud = new crudData();
                                        $showList = $crud->showTable($payment_list . " order by status asc,tanggal desc");
                                        while ($data = $showList->fetch(PDO::FETCH_OBJ)) {
                                            $format = new format();

                                            $nis = $data->nis;

                                            $link = new linkpage;

                                            if ($data->status == "DRAF") {
                                                $status = "<b class='text-danger'>DRAF</b>";
                                                $inputcek = "  <input type='checkbox' class='d-inline small chk_boxes1' name='id_trans[]' value='" . $data->payment_id . "'> ";
                                                $record = $crud->countData('payment_list_detail', "where payment_id='$data->payment_id'");
                                            } elseif ($data->status == "PAID") {
                                                $status = "<b class='text-success'>PAID</b>";
                                                $inputcek = "";
                                                $record = $crud->countData($tb_transaksi, "where id_tr='$data->payment_id'");
                                            } else {
                                                $status = "<b class='text-warning'>PENDING</b>";
                                                $inputcek = "";
                                                $record = $crud->countData('payment_list_detail', "where payment_id='$data->payment_id'");
                                            };


                                            echo "
                                                    <tr>
                                                        <td width='5px'>
                                                            $inputcek
                                                        </td>
                                                        <td align=center>" . $format->dateTimeToIndo($data->created_at) . "</td>
                                                        <td align=left>$data->nama</td>
                                                        <td align=center>$nis</td>
                                                        <td align=center>$data->jenjang - $data->paralel</td>
                                                        <td align=left>$data->payment_id</td>
                                                        <td align=right>$record</td>
                                                        <td align=right>" . $format->ribuan($data->jumlah) . "</td>
                                                        <td align=left>$status</td>
                                                        <td width='50px' align='center'>
                                                        <a " . $link->pageID($data->payment_id, 'payment/payment_printpreview') . " class='badge badge-secondary  px-1 py-1 d-inline'> <i class='bi bi-printer'></i> CETAK</a>
                                                        </td>  
                                                       
                                                    </tr>";
                                        }

                                        ?>

                                    </tbody>
                                </table>
                                <div class="div d-inline">
                                    <?php
                                    echo $link->exportXlsx('payment/payment_export', $tahun);
                                    ?>
                                    <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>

                                </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_trans'] as $id_billing) {
        $class = new crudData();
        //$delete = $class->deleteData($tb_transaksi, 'no', $id);
        $delete = $crud->deleteData($payment_list, 'payment_id', $id_billing);
        $delete = $crud->deleteData('payment_list_detail', 'payment_id', $id_billing);
    };

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



?>