<?php
require('../../../../asset/mod/autoLoad.php');
require('../../../config.php');

$tahun = $_GET['thn'];
$id_tr = $_GET['id_tr'];
$id_siswa = $_GET['id_siswa'];

$tahun1 = substr($tahun, 0, 4);
$tahun2 = substr($tahun, 5, 4);

$tahun_tabel = substr($tahun, 2, 2) . substr($tahun, 7, 2);

$tb_siswa = "tb_siswa" . $tahun_tabel;
$tb_transaksi = "db_transaksi" . $tahun_tabel;
$tb_detailakun = "detail_akun" . $tahun_tabel;
$tb_setor = "setor_kjks" .  $tahun_tabel;
$tb_transaksisim = "sim_transaksi" . $tahun_tabel;


$user_admin = new crudData();
$editUser = $user_admin->editData($tb_siswa, 'id', $id_siswa);
$data = $editUser->fetch(PDO::FETCH_OBJ);
$nis = $data->nis;
if ($data->startAt == "") {
    $startAt = 1;
} else {
    $startAt = $data->startAt;
};
date_default_timezone_set('Asia/Jakarta');
$time = date('Y-m-d H:i:s');


$id_tr = $_GET['id_tr'];

//Jumlah Kuitansi
$classTransaksi = new transaksi();
$jmlKuitansi = $classTransaksi->jumlahKuitansi($tb_transaksi, $nis, $id_tr);


?>
<style>
    .font {
        font-family: arial;
        font-size: 11px;
    }

    .fontInput {
        font-size: 11px;
        font-family: arial;
    }

    .fontJudul {
        font-size: 12px;
        font-family: arial;
        color: dodgerblue;
        background: #000;
    }
</style>


<div class="col-12 mb-4 pb-5 font">
    <div class="row d-inline">
        <div class="col-12 ">
            <div class="col-2 d-inline">
                <label for="exampleEmail" class="col-sm-12 col-form-label">Kuitansi Pembayaran </label>
            </div>
            <div class="col-10">
                <label for="exampleEmail" class="col-sm-12 col-form-label">Kuitansi Pembayaran </label>
            </div>
        </div>
    </div>
</div>

<!-- Content Wrapper. Contains page content -->


<div class="container col-12 mb-4 pb-5 font">
    <div class="row">
        <div class="col-12">
            <div class="col-12">
                <div class="card  mx-3">
                    <div class="card-header bg-primary">
                        <h4 class="card-title"><span class="bi bi-printer"></span> Cetak Transaksi <?php echo $tahun_tabel; ?></h4>
                    </div>
                    <div class="card-body mb-1">
                        <form action="" method="post">
                            <input type="text" name="id" value="<?php echo $data->id; ?>" hidden>
                            <input type="text" name="nis" value="<?php echo $data->nis; ?>" hidden>
                            <input type="text" name="nama" value="<?php echo $data->nama; ?>" hidden>
                            <input type="text" name="kelamin" value="<?php echo $data->kelamin; ?>" hidden>
                            <input type="text" name="jenjang" value="<?php echo $data->jenjang; ?>" hidden>
                            <input type="text" name="paralel" value="<?php echo $data->paralel; ?>" hidden>
                            <input type="text" name="id_tr" value="<?php echo $id_tr; ?>" hidden>
                            <div class="row mx-3 mt-0">
                                <div class="col-md-6">
                                    <div class="card-body mt-0 px-1 mx-2">
                                        <div class="row">
                                            <label for="exampleEmail" class="col-sm-4 col-form-label">Nomor Induk </label>
                                            <div class="col-sm-8">
                                                <input type="text" name="" value="<?php echo $data->nis; ?>" class="form-control form-control-sm fontInput text-secondary" style='text-align:left;font-size:14px;font-weight:bold' placeholder="NIS Siswa" disabled>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <label for="exampleEmail" class="col-sm-4 col-form-label">Nama Siswa </label>
                                            <div class="col-sm-8">
                                                <input type="text" name="" value="<?php echo $data->nama; ?>" class="form-control form-control-sm fontInput" placeholder="Nama Siswa" disabled>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <label class="col-sm-4 col-form-label">Kelas</label>
                                            <div class="col-md-2">
                                                <select name="" class="form-control form-control-sm fontInput small" disabled>
                                                    <option><?php echo $data->jenjang; ?></option>
                                                    <?php

                                                    $sekolah = $user_admin->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 class="col-md-6">
                                                <select name="" class="form-control form-control-sm fontInput small" disabled>
                                                    <option><?php echo $data->paralel; ?></option>
                                                    <?php
                                                    $opval = $opt->optSelect('tb_paralel', ' order by no asc');
                                                    while ($datapar = $opval->fetch(PDO::FETCH_OBJ)) {
                                                        echo "<option>$datapar->paralel</option>";
                                                    };

                                                    ?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <?php echo $tahun_tabel; ?>
                                <div class="col-md-6">
                                    <div class="card-body mt-0 px-1 mx-2">
                                        <div class="row">
                                            <label for="nis" class="col-sm-4 col-form-label">ID-Transaksi</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control form-control-sm fontInput" value="<?php echo $id_tr; ?>" placeholder="No Telpon User" name="hp" disabled>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <label for="nis" class="col-sm-4 col-form-label">Tanggal</label>
                                            <div class="col-sm-8">
                                                <input type="email" class="form-control form-control-sm fontInput" value="<?php echo $time; ?>" placeholder="email@mail.com" name="email" disabled>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <label for="nis" class="col-sm-4 col-form-label">Jumlah</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control form-control-sm fontInput text-primary" value="<?php echo @(number_format($jmlKuitansi, 0, ".", "."));; ?>" style='text-align:left;font-size:16px;font-weight:bold' disabled>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                            <div class="row mx-3 mt-0">

                                <div class="card-body my-1 mx-1">

                                    <table id="example14" class="table table-bordered table-striped table-hover table-sm small mb-4">
                                        <thead>
                                            <tr>
                                                <th><input type="checkbox" class="small check_all"></th>
                                                <th>Kode : Jenis Pembayaran</th>
                                                <th>Periode</th>
                                                <th>Jumlah</th>
                                                <th>Aksi</th>

                                                <th>Catatan</th>

                                            </tr>
                                        </thead>
                                        <tbody>

                                            <?php
                                            $class = new transaksi();
                                            $showList = $class->showTransaksiID($tb_transaksi, $id_tr);
                                            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, ",", ".");
                                                };

                                                $tahap = $data->tahap;

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

                                                //nama Bayar
                                                $classNB = new namaBayar();
                                                $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;
                                                };

                                                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->jenis : $ceknamaBayar</td>
                                                        <td align=left>$periode</td>
                                                        <td align=left>" . $jumlah . "</td>
                                                        <td align=left>$setbulanan </td>
                                                       
                                                        <td align=left><i style='font-size:8px'>$data->catatan</i></td>
                                                        </tr>";
                                            }

                                            ?>

                                        </tbody>
                                    </table>
                                </div>
                            </div>

                        </form>
                    </div>

                </div>
            </div>

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