<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-badge"></span> Data 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>Tanggal</th>
                                            <th>Nama</th>
                                            <th>NIS</th>
                                            <th>Kelas</th>
                                            <th>Record</th>
                                            <th>Jumlah</th>
                                            <th>Bukti</th>
                                            <th>ID</th>


                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php
                                        //Filter by Level Operator

                                        $crud = new crudData();
                                        $showList = $crud->showTable($payment_list . " where status='PAID' order by status asc, created_at desc");
                                        $no = 0;
                                        while ($data = $showList->fetch(PDO::FETCH_OBJ)) {
                                            $format = new format();
                                            $modal = new modal();

                                            $id_billing = $data->payment_id;
                                            $nis = $data->nis;
                                            $siswa_id = $crud->getValue($tb_siswa, "where nis='$nis'", 'id');

                                            $link = new linkpage;

                                            //cek data siswa
                                            $count_siswa = $crud->countData($tb_siswa, " where nis='$nis'");
                                            if ($count_siswa > 0) {
                                                $bg_tr = "";
                                            } else {
                                                $bg_tr = "bg-danger text-light text-bold";
                                            };

                                            $servroot = $_SERVER['DOCUMENT_ROOT'];
                                            if (file_exists($servroot . "/asset/dokumen/bt/BT_" . $id_billing . ".pdf") || file_exists("../../asset/dokumen/bt/BT_" . $id_billing . ".pdf")) {
                                                $bukti = $modal->modalkonfirmTransfer('./view/transfer/bukti', 'verifikasi' . $data->payment_id, $data->payment_id, $tahun, 'lg', 'grey', 'BUKTI TRANSFER', "<strong class='text-secondary'>BUKTI TRANSFER</strong>", 'receipt-cutoff text-light', '<b class=text-light>BUKTI TRANSFER</b>', 'secondary', 'BUKTI TRANSFER');
                                                $cekbukti = 1;
                                            } elseif (file_exists($servroot . "/asset/dokumen/bt/BT_" . $id_billing . ".png") || file_exists("../../asset/dokumen/bt/BT_" . $id_billing . ".png")) {
                                                $bukti = $modal->modalkonfirmTransfer('./view/transfer/bukti', 'verifikasi' . $data->payment_id, $data->payment_id, $tahun, 'lg', 'grey', 'BUKTI TRANSFER', "<strong class='text-secondary'>BUKTI TRANSFER</strong>", 'receipt-cutoff text-light', '<b class=text-light>BUKTI TRANSFER</b>', 'secondary', 'BUKTI TRANSFER');
                                                $cekbukti = 1;
                                            } elseif (file_exists($servroot . "/dokumen/bt/BT_" . $id_billing . ".jpg") || file_exists("../../asset/dokumen/bt/BT_" . $id_billing . ".jpg")) {
                                                $bukti = $modal->modalkonfirmTransfer('./view/transfer/bukti', 'verifikasi' . $data->payment_id, $data->payment_id, $tahun, 'lg', 'grey', 'BUKTI TRANSFER', "<strong class='text-secondary'>BUKTI TRANSFER</strong>", 'receipt-cutoff text-light', '<b class=text-light>BUKTI TRANSFER</b>', 'secondary', 'BUKTI TRANSFER');
                                                $cekbukti = 1;
                                            } else {
                                                $bukti = "";
                                                $cekbukti = 0;
                                            }

                                            $bukti = $modal->modalkonfirmTransfer('./view/transfer/bukti', 'verifikasi' . $data->payment_id, $data->payment_id, $tahun, 'lg', 'grey', 'BUKTI TRANSFER', "<strong class='text-secondary'>BUKTI TRANSFER</strong>", 'receipt-cutoff text-light', '<b class=text-light>BUKTI TRANSFER</b>', 'secondary', 'BUKTI TRANSFER');

                                            $count1 = $crud->countData($tb_transaksi, " where id_tr='$data->payment_id'");
                                            $count2 = $crud->countData('payment_list_detail', " where id_tr='$data->payment_id'");
                                            $count = $count1 + $count2;
                                            $no++;


                                            if ($cekbukti == 1) {
                                                echo "
                                                    <tr class='$bg_tr'>
                                                        <td width='5px'> <input type='checkbox' class='d-inline small chk_boxes1' name='file_delete[]' value='" . $data->payment_id . "'></td>                                                      
                                                        <td align=center>" . $format->dateToIndo($data->tanggal) . "</td>
                                                        <td align=left>$data->nama </td>
                                                        <td align=center>$nis</td>
                                                        <td align=center>$data->jenjang - $data->paralel</td>
                                                        <td align=left>$count</td>
                                                        <td align=right>" . $format->ribuan($data->jumlah) . "</td>
                                                        <td align=left><i style='font-size:8px'></i>$bukti</td>  
                                                        <td align=left>$data->payment_id</td>
                                                    </tr>";
                                            } else {
                                                echo "";
                                            }
                                        }
                                        ?>

                                    </tbody>
                                </table>

                                <div class="div d-inline">
                                    <div class="col-lg-3 float-right">
                                        <?php //echo $link->exportXlsx('transaksi/transaksi_export', $tahun); 
                                        ?>
                                    </div>
                                </div>
                                <button type="submit" name="submitDel" class="btn btn-danger btn-xs float-left mt-1"> <i class="bi bi-trash"></i> HAPUS FILE BUKTI</button>

                        </div>
                    </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

$direct = new toast();
$clsTime = new time;
$clsIP = new ip;
$clsCrud = new crudData;

$waktu = $clsTime->getTime();
$ip = $clsIP->getIP();
$browser = $clsIP->getBrowser();
$user = $clsCrud->getValue('user', " where username='$username'", 'id');

if (isset($_POST['submitDel']) && isset($_POST['file_delete'])) {
    foreach ($_POST['file_delete'] as $id) {

        if (file_exists($servroot . "/asset/dokumen/bt/BT_" . $id . ".pdf") || file_exists("../../asset/dokumen/bt/BT_" . $id . ".pdf")) {
            $del = unlink("../../asset/dokumen/bt/BT_" . $id . ".pdf");
        } elseif (file_exists($servroot . "/asset/dokumen/bt/BT_" . $id . ".png") || file_exists("../../asset/dokumen/bt/BT_" . $id . ".png")) {
            $del = unlink("../../asset/dokumen/bt/BT_" . $id . ".png");
        } elseif (file_exists($servroot . "/dokumen/bt/BT_" . $id . ".jpg") || file_exists("../../asset/dokumen/bt/BT_" . $id . ".jpg")) {
            $del = unlink("../../asset/dokumen/bt/BT_" . $id . ".jpg");
        } else {
            $del = "";
        }
    }
    echo  $direct->redirect('toast', 'delete', 'transfer/file');
} else {
    echo "";
};
