<style>
    .fontInput {
        font-size: 11px;
        font-family: arial;
    }
</style>
<!-- Content Wrapper. Contains page content -->
<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-map"></span> Daftar Transaksi</b>
                        </div>
                        <div class="row col-md-12">

                            <div class="col-md-12">
                                <div class="card-body mt-4 px-1 mx-2">

                                    <div class="row">
                                        <div class="col-12 col-sm-12 col-md-12">
                                            <div class="info-box mb-3">


                                                <div class="info-box-content">
                                                    <div class="relative mb-0 pb-4">
                                                        <input name="judul" value="DAFTAR TRANSAKSI" style="background-color: gainsboro;" class="form-control-sm col-sm-2 fontInput small bg-default mt-3 text-center" disabled>
                                                    </div>

                                                    <div class="col-sm-12 invoice-col pt-0">

                                                        <div class="row mt-1">
                                                            <div class="col-12">
                                                                <form action="" method="post">
                                                                    <table id="example51" class="table table-condensed table-striped table-sm mb-4">
                                                                        <thead>
                                                                            <tr>
                                                                                <th><input type="checkbox" class="small check_all"></th>
                                                                                <th>No</th>
                                                                                <th>Tanggal</th>
                                                                                <th>Nama</th>
                                                                                <th>NIS</th>
                                                                                <th>Jenis</th>
                                                                                <th>Debet</th>
                                                                                <th>Kredit</th>
                                                                                <th>Petugas</th>
                                                                                <th>Catatan</th>
                                                                            </tr>
                                                                        </thead>
                                                                        <tbody>
                                                                            <?php
                                                                            $clsCrud = new crudData();
                                                                            $clsTabungan = new tabungan();
                                                                            $format = new format;

                                                                            $db = database::getInstance();
                                                                            $show = $db->runQuery("SELECT * FROM  $tabungan_transaksi where jurnal!='1' order by tanggal desc");
                                                                            $row = $show->rowCount();
                                                                            $no = 0;

                                                                            if ($row != 0) {
                                                                                while ($data = $show->fetch(PDO::FETCH_OBJ)) {
                                                                                    $tanggal = $format->dateTimeToIndo($data->tanggal);

                                                                                    $debet = $clsTabungan->debetKredit($data->jenis, 'D', $data->jumlah);
                                                                                    $kredit = $clsTabungan->debetKredit($data->jenis, 'K', $data->jumlah);

                                                                                    $uraian = $clsTabungan->uraianJenis($data->jenis);

                                                                                    $petugas = $clsCrud->getValue('user', "where id='$data->created_by'", 'nama');
                                                                                    $nama = $clsCrud->getValue($tabungan_siswa, "where nis='$data->nis'", 'nama');

                                                                                    $no++;
                                                                                    if ($nama == NULL) {
                                                                                        $bgRow = "bg-danger";
                                                                                    } else {
                                                                                        $bgRow = "";
                                                                                    };
                                                                                    echo "
                                                                                <tr height='15' class='$bgRow'>
                                                                                    <td width='5px'>
                                                                                        <input type='checkbox' class='d-inline small chk_boxes1' name='transaksi_delete[]' value='$data->id'> 
                                                                                    </td>
                                                                                    <td align=left width='5px'>$no</td>
                                                                                    <td align=left>$tanggal</td>
                                                                                    <td align=left>$nama </td>
                                                                                    <td align=left>$data->nis </td>
                                                                                    <td align=left>$uraian </td>
                                                                                    <td align=left>" . $format->ribuan($debet) . "</td>
                                                                                    <td align=left>" . $format->ribuan($kredit) . "</td>
                                                                                    <td align=left>$petugas</td>
                                                                                    <td align=left>" . $data->catatan . "</td>
                                                                                </tr>";
                                                                                }
                                                                            } else {
                                                                                echo  "  <tr height='15'>
                                                                                <td align=center colspan='9'>-- N I H I L --</td>
                                                                               
                                                                            </tr>";
                                                                            };
                                                                            // $showList = $class->list_deleted($tabungan_siswa, $tabungan_transaksi, $tahun);
                                                                            ?>
                                                                        </tbody>
                                                                    </table>
                                                                    <div class="div d-inline">
                                                                        <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 TRANSAKSI</button>
                                                                        <?php echo $link->exportXlsx('transaksi/transaksi_export', $tahun); ?>
                                                                    </div>

                                                                </form>
                                                            </div>
                                                        </div>

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

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<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['submit']) && isset($_POST['transaksi_delete'])) {
    foreach ($_POST['transaksi_delete'] as $id) {
        //Insert ke DB Transaksi

        $tanggal = $clsCrud->getValue($tabungan_transaksi, "where id='$id'", 'tanggal');
        $nis = $clsCrud->getValue($tabungan_transaksi, "where id='$id'", 'nis');
        $nama = $clsCrud->getValue($tabungan_transaksi, "where id='$id'", 'nama');
        $jenis = $clsCrud->getValue($tabungan_transaksi, "where id='$id'", 'jenis');
        $jumlah = $clsCrud->getValue($tabungan_transaksi, "where id='$id'", 'jumlah');
        $jurnal = $clsCrud->getValue($tabungan_transaksi, "where id='$id'", 'jurnal');
        $catatan = $clsCrud->getValue($tabungan_transaksi, "where id='$id'", 'catatan');
        $created_by = $clsCrud->getValue($tabungan_transaksi, "where id='$id'", 'created_by');
        $created_at = $clsCrud->getValue($tabungan_transaksi, "where id='$id'", 'created_at');
        $dataarray = [
            'tanggal' => $tanggal,
            'nis' => $nis,
            'nama' => $nama,
            'jenis' => $jenis,
            'jumlah' => $jumlah,
            'jurnal' => $jurnal,
            'catatan' => $catatan,
            'created_by' => $created_by,
            'created_at' => $created_at,
            'id' => $id,
            'deleted_at' => $waktu,
            'deleted_by' => $user,
            'browser' => $browser,
            'ip' => $ip
        ];
        $clsCrud->insertData('deleted_tabungan', $dataarray);
        $delete = $clsCrud->deleteData($tabungan_transaksi,  'id',  $id);
    }
    echo  $direct->redirect('toast', 'delete', 'transaksi/transaksi_list');
} else {
    echo "";
};
