<?php

error_reporting(0);
$cekid = new cekID();
$jmldata = $cekid->Cek($tb_siswa, 'id', $id_page);


$crud = new crudData();
$format = new format();
$link = new linkpage();
$editUser = $crud->editData($tb_siswa, 'id', $id_page);
$data = $editUser->fetch(PDO::FETCH_OBJ);
$nis = $data->nis;
if ($data->startAt == "") {
    $startAt = 1;
} else {
    $startAt = $data->startAt;
};


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

//Data sekolah
$clssekolah = new sekolah;
$sekolah_nama_kuitansi = $clssekolah->dataSekolah('nama_kuitansi');
$sekolah_model_kw = $clssekolah->dataSekolah('model_kw');


$crud = new crudData();
$sqlSiswa = $crud->editData($tb_siswa, 'id', $id_page);
$data = $sqlSiswa->fetch(PDO::FETCH_OBJ);
$siswa_nis = $data->nis;
$siswa_kelas = $data->jenjang . '-' . $data->paralel;
$siswa_ortu = $data->ortu;
$siswa_alamat = $data->alamat;
$siswa_hp = $data->hp;
$siswa_email = $data->email;
$siswa_id = $data->id;
$siswa_nama = $data->nama;

//Nama Pembayar Siswa/Ortu
if ($sekolah_nama_kuitansi == "Nama Siswa") {
    $pembayar1 = $siswa_nama;
    $pembayar2 = $siswa_nis;
    $pembayar3 = $siswa_kelas;
    $pembayar4 = $siswa_hp;
    $val_pembayar1 = "Nama";
    $val_pembayar2 = "NIS";
    $val_pembayar3 = "Kelas";
    $val_pembayar4 = "HP";
} else {
    $pembayar1 = $siswa_ortu;
    $pembayar2 = $siswa_hp;
    $pembayar3 = 'Wali dari ' . $siswa_nama;
    $pembayar4 = $siswa_alamat;
    $val_pembayar1 = "Nama";
    $val_pembayar2 = "HP";
    $val_pembayar3 = "Nama Siswa";
    $val_pembayar4 = "Alamat";
};


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

$timeTr = $crud->getValue($tb_transaksi, " where id_tr='$id_tr'", 'tanggal');
if ($sekolah_model_kw == 4) {
    $persenmodel = 41;
} else {
    $persenmodel = 80;
};

$dt_jenis = new listTanggungan();
$jumlah = $dt_jenis->tanggunganSiswa($tb_siswa, 'id', $data->id);
$total_tang = number_format($jumlah, 0, ".", ".");

//Terbayar & Kurang Total
$infoTerbayartotal = $classTransaksi->infoterbayartotal($tb_transaksi, $nis);
$terbayarTotal = @(number_format($infoTerbayartotal, 0, ".", "."));
$kurangTotal = @(number_format(($jumlah - $infoTerbayartotal), 0, ".", "."));

$penerima_id = $crud->getValue($tb_transaksi, "where id_tr='$id_tr'", 'penerima');
$penerima = $crud->getValue('user', "where id='$penerima_id'", 'nama');


$whatsapp = new whatsapp;
$mailer = new mailer;

$aktif_wa = $crud->getValue('whatsapp', '', 'aktif');
$aktif_mailer = $crud->getValue('mailer', '', 'aktif');

if (strlen($data->hp >= 10 && $aktif_wa == 1)) {
    echo $whatsapp->notifikasiTransaksi($data->nama, $data->nis, $data->jenjang . "-" . $data->paralel, $data->hp, $infoJenis, $jmlKuitansi, $id_tr, $penerima, $id_tr, $tahun);
} else {
    echo "";
};
if (strlen($siswa_email >= 7 && $aktif_mailer == 1)) {
    $mailer->sendMail($siswa_email, $data->nama, $data->nis, $data->jenjang . "-" . $data->paralel, $data->hp, $jmlKuitansi, $id_tr, $penerima, $penerima_id);
} else {
    echo "";
};

if ($sekolah_model_kw > 5) {
    include "print_" . $sekolah_model_kw . ".php";
} else {
    echo "";
};



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

    .fontJudul {
        font-size: 12px;
        font-family: arial;
        color: dodgerblue;
        background: #000;

    }
</style>
<script>
    function formatNumber(num) {
        return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.')
    }
</script>

<!-- 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 mt-3">
            <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-printer"></span> Cetak Kuitansi</b>
                        </div>
                        <div class="card-body mb-1">

                            <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 = $crud->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>
                                <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 $format->dateTimeToIndo($timeTr);
                                                                                                                            ?>" placeholder="Tanggal" 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 class="col-md-12">
                                    <div class="col-12 d-inline pl-2">
                                        <button onclick="frames['cetak'].print()" name="submit" class="btn btn-primary btn-xs mb-2 btn-rounded small px-2"> <i class="bi bi-printer"></i> CETAK</button>


                                    </div>
                                    <div class='col-md-12 pl-3 ml-2' style='background:#c3c3c3;  padding-top:50px; padding-bottom:50px'>

                                        <div class="mb-2" style='background:#fff; width:<?php echo $persenmodel; ?>%; margin:0 auto; padding:5px; height:1200px;'>
                                            <div class=''>
                                                <div style='background:#fff; width:100%;  border:0; height:900px;  '>
                                                    <?php
                                                    if ($sekolah_model_kw > 5) {
                                                        echo "<iframe name='cetak' src='view/transaksi/print_" . strtoupper($penerima_id) . ".pdf' style='border:0; padding:10px; width:100%; height:1200px;'></iframe>";
                                                    } else {
                                                        echo "<iframe name='cetak' src='view/transaksi/print_template.php?thn=$tahun&id_tr=$id_tr&id_siswa=$data->id&timeTr=$timeTr' style='border:0; padding:10px; width:100%; height:1200px;'></iframe>";
                                                    }; ?>

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


                        </div>

                    </div>
                </div>

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