<?php


if (isset($_POST['jenjang'])) {
    $jenjang_lap = $_POST['jenjang'];
    $jenjang_post = $_POST['jenjang'];
    $aktifjenis = "";
} else {
    $jenjang_lap = "--Pilih--";
    $jenjang_post = "Semua";
    $aktifjenis = "disabled";
};

if (isset($_POST['jenis'])) {
    $jenis_lap = $_POST['jenis'];
} else {
    $jenis_lap = "Semua";
};

if (isset($_POST['status'])) {
    $status_lap = $_POST['status'];
} else {
    $status_lap = "Semua";
};

if ($jenjang_post == "Semua") {
    $kondisiJenjang = " where jenjang!='Semua'";
} else {
    $kondisiJenjang = " where jenjang='$jenjang_post'";
};
if ($jenis_lap == "Semua") {
    $kondisiJenis = " and jenis!='Semua'";
} else {
    $kondisiJenis = " and jenis='$jenis_lap'";
};
if ($status_lap == "Semua") {
    $kondisiStatus = " and setor!='Semua'";
} elseif ($status_lap == 0) {
    $kondisiStatus = " and id_setor=''";
} else {
    $kondisiStatus = " and setor='$status_lap'";
};

$dt_jenis = new namaBayar();
$showJenis = $dt_jenis->shownamaBayar($tahun, $jenis_lap, $jenjang_lap);
$count_nb = $showJenis->rowCount();
$datajenis = $showJenis->fetch(PDO::FETCH_OBJ);
if ($count_nb > 0) {
    $namaBayar = $datajenis->nama;
} else {
    $namaBayar = "Semua";
};

//Jumlah Rekap
$clsSetor = new setor;
$clsFormat = new format();
$jmlRekap = $clsFormat->ribuan($clsSetor->jumlah($tb_transaksi, 'jumlah',  $kondisiJenjang . " " . $kondisiJenis . " " . $kondisiStatus));

//juMLAH rECORD
$clsCrud = new crudData;
$jmlRecord = $clsCrud->showTable($tb_transaksi . " " . $kondisiJenjang . " " . $kondisiJenis . " " . $kondisiStatus)->rowCount();

//$showList = $clsCrud->showTable($tb_transaksi . " " . $kondisiJenjang . " " . $kondisiJenis . " " . $kondisiStatus);

?>
<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-4 mt-3">
                        <div class="timeline-header bg-primary py-2 pl-2">
                            <b class="text-light judul"><span class="bi bi-search"></span> Monitoring Transaksi Setor</b>

                        </div>
                        <div class="card-body mx-2 ">
                            <?php require('./view/setor/headerpage.php'); ?>
                        </div>

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

                                            <div class="col-md-12">
                                                <div class="card-body  px-1 mx-2">
                                                    <form action="" method="post">

                                                        <div class="row">
                                                            <label class="col-sm-4 col-form-label">Jenjang </label>
                                                            <div class="col-md-8">
                                                                <select name="jenjang" class="form-control form-control-sm fontInput small" onchange="this.form.submit()">
                                                                    <option value="<?php echo $jenjang_lap; ?>"><?php echo $jenjang_lap; ?></option>
                                                                    <option value="Semua">Semua</option>
                                                                    <?php
                                                                    $data_sekolah = new crudData;
                                                                    $sekolah = $data_sekolah->editData('sekolah', 'no', 1);
                                                                    $dataSekolah = $sekolah->fetch(PDO::FETCH_OBJ);
                                                                    $jenjang = strtolower($dataSekolah->jenjang);

                                                                    $opt = new form();
                                                                    $opval = $opt->optSelect('tb_tingkat', "where {$jenjang}<>'' order by no asc");
                                                                    while ($dataopt = $opval->fetch(PDO::FETCH_OBJ)) {
                                                                        $optJenjang = $dataopt->{$jenjang};
                                                                        echo "<option>" . $optJenjang . " </option>";
                                                                    };
                                                                    ?>
                                                                </select>
                                                            </div>

                                                        </div>
                                                        <div class=" row">
                                                            <label class="col-sm-4 col-form-label">Jenis Pembayaran</label>
                                                            <div class="col-md-8">
                                                                <select name="jenis" class="form-control form-control-sm fontInput small" required <?php echo $aktifjenis; ?> onchange="this.form.submit()">
                                                                    <option value="<?php echo $jenis_lap; ?>"><?php echo $jenis_lap . " : " . $namaBayar; ?></option>
                                                                    <option value="Semua">Semua</option>
                                                                    <?php

                                                                    $showJenis = $dt_jenis->NamaTransaksi('tb_nama_bayar', 'tp', $tahun, $jenjang_lap, 'kode');
                                                                    $count = $showJenis->rowCount();
                                                                    while ($datajenis = $showJenis->fetch(PDO::FETCH_OBJ)) {
                                                                        echo "<option value='$datajenis->kode'>$datajenis->kode : $datajenis->nama</option>";
                                                                    };
                                                                    ?>
                                                                </select>
                                                            </div>
                                                        </div>
                                                        <div class="row">
                                                            <label class="col-sm-4 col-form-label">Status Setor</label>
                                                            <div class="col-md-8">
                                                                <select name="status" class="form-control form-control-sm fontInput small" required onchange="this.form.submit()">
                                                                    <option value="<?php echo $status_lap; ?>"><?php if ($status_lap == 0) {
                                                                                                                    echo "Belum Setor";
                                                                                                                } elseif ($status_lap == 1) {
                                                                                                                    echo "Draf Setor";
                                                                                                                } elseif ($status_lap == 2) {
                                                                                                                    echo "Proses Setor";
                                                                                                                } elseif ($status_lap == 3) {
                                                                                                                    echo "Setor Diterima";
                                                                                                                } else {
                                                                                                                    echo "Semua";
                                                                                                                }  ?></option>
                                                                    <option value="Semua">Semua</option>
                                                                    <option value="0">Belum Setor</option>
                                                                    <option value="1">Draf Setor</option>
                                                                    <option value="2">Proses Setor</option>
                                                                    <option value="3">Setor DIterima</option>
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="row mt-3">
                                                            <label class="col-sm-3 col-form-label"></label>
                                                            <div class="col-md-9">
                                                                <button type="submit" class="btn btn-primary btn-xs float-right px-2 mx-1" name="save"><i class="bi-funnel"></i> <b>FILTER</b></button>
                                                    </form>


                                                    <form name="cetak" action="<?php echo $link->pageAction('laporan/transaksi/print_preview'); ?>" method="post">
                                                        <input name="status" value="<?php echo $status_lap; ?>" hidden>
                                                        <input name="jenis" value="<?php echo $jenis_lap; ?>" hidden>
                                                        <input name="tahun" value="<?php echo $tahun; ?>" hidden>
                                                        <input name="jenjang_lap" value="<?php echo $jenjang_lap; ?>" hidden>
                                                        <button type="submit" class="btn btn-primary btn-xs float-right px-2 mx-1 d-inline"><i class="bi bi-printer"></i><b> CETAK</b></button>
                                                    </form>
                                                </div>
                                            </div>

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

                                <div class="col-md-6">
                                    <div class="card-body mt-4 pt-4 px-1 mx-2">
                                        <div class="row">
                                            <div class="col-12 col-sm-6 col-md-12">
                                                <div class="info-box mb-3">
                                                    <span class="info-box-icon bg-primary elevation-1"><i class="bi bi-calculator"></i></span>
                                                    <div class="info-box-content">
                                                        <div class="col-sm-12 invoice-col">
                                                            <dl class="row">
                                                                <dt class="col-sm-3">JUMLAH</dt>
                                                                <dd class="col-sm-9"><b>: <?php echo $jmlRekap; ?></b></dd>
                                                                <dt class="col-sm-3">RECORD</dt>
                                                                <dd class="col-sm-9"><b>: <?php echo $jmlRecord; ?> Data</b></dd>

                                                                </dd>
                                                            </dl>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="card-body mx-4">
                        <label>
                            <h6><b class="text-primary">DAFTAR TRANSAKSI</b></h6>
                        </label>
                        <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>Kode : Jenis Pembayaran</th>
                                    <th>Periode</th>
                                    <th>Jumlah</th>
                                    <th>Metode</th>
                                    <th>Penerima</th>
                                    <th>Catatan</th>
                                    <th>Status Setor</th>

                                </tr>
                            </thead>
                            <tbody>

                                <?php


                                $clsCrud = new crudData;
                                $showList = $clsCrud->showTable($tb_transaksi . " " . $kondisiJenjang . " " . $kondisiJenis . " " . $kondisiStatus);
                                while ($data = $showList->fetch(PDO::FETCH_OBJ)) {

                                    if ($data->jumlah == "" || $data->jumlah == 0) {
                                        $jumlah = number_format(0, 0, ",", ".");
                                    } else {
                                        $jumlah = number_format($data->jumlah, 0, ",", ".");
                                    };
                                    if ($data->setor == "Ya") {
                                        $setor = "Disetor";
                                    } else {
                                        $setor = "--";
                                    };
                                    $nis = $data->nis;
                                    $tahap = $data->tahap;
                                    //nama Bayar
                                    $classNB = new namaBayar();
                                    $ceknamaBayar = $classNB->ceknamaBayar($tahun, $data->jenis, $data->jenjang);

                                    //startAt
                                    $classTr = new Transaksi();
                                    $startAt = $classTr->startAt($tb_siswa, $nis);
                                    $cekbulan = $classTr->cekPeriode($startAt, $tahap, $tahun1, $tahun2);

                                    //nama Bayar

                                    $ceknamaBayar = $classNB->ceknamaBayar($tahun, $data->jenis, $data->jenjang);

                                    $showJenis = $classNB->shownamaBayar($tahun, $data->jenis, $data->jenjang);
                                    $datajenis = $showJenis->fetch(PDO::FETCH_OBJ);
                                    $field_tang = 'tang_' . $datajenis->kode;
                                    $setbulanan = $datajenis->bulanan; //Cek Apakah Bulanan

                                    if ($setbulanan == "Tidak") {
                                        $periode = "Tahap " . $tahap;
                                    } else {
                                        $periode = $cekbulan;
                                    };

                                    //Status Setor
                                    //$clsSetor = new setor;
                                    $statusSetor = $clsSetor->statusSetor($data->setor);

                                    $link = new linkpage;
                                    echo "
                                    <tr>
                                        <td width='5px'>
                                        <input type='checkbox' class='d-inline small chk_boxes1' name='id_trans[]' value='" . $data->no . "'> 
                                        </td>
                                        <td align=left>$data->time</td>
                                        <td align=left>$data->nama</td>
                                        <td align=left>$nis</td>
                                        <td align=left>$data->jenjang - $data->paralel</td>
                                        <td align=left>$data->jenis : $ceknamaBayar</td>
                                        <td align=left>$periode</td>
                                        <td align=left>" . $jumlah . "</td>
                                        <td align=left>$data->metode</td>
                                        <td align=left>$data->penerima</td>
                                        <td align=left><i style='font-size:8px'>$data->catatan</i></td>
                                        <td width='100px' align='center'>$statusSetor</td>
                                    </tr>";
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>