<?php

$id_billing = $id_page;
//$cekID = new cekID();
//$jmldata = $cekID->cek('user_siswa', 'id', $id_page);
//
//$user_admin = new crudData();
//$editUser = $user_admin->editData('user_siswa', 'id', $id_page);
//$data = $editUser->fetch(PDO::FETCH_OBJ);
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <?php //require('./layout/headerpage.php');
    //require('./layout/quickmenu.php') 
    ?>
    <!-- Content Header (Page header) -->
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">

                    <?php
                    //echo $username . "<br>";
                    //echo $tahun . "<br>";
                    //echo $iduser . "<br>";
                    //echo $level . "<br>";
                    //echo $tahun_open;

                    //echo $classTabungan->validTahun($tahun);
                    ?>
                </div><!-- /.col -->
                <div class="col-sm-6">

                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <section class="content">
        <div class="container">
            <!-- Info boxes -->

            <!-- /.row -->
            <div class="row mb-3">
                <div class="col-md-12">
                    <div class="timeline-header bg-secondary  py-1 pl-1">
                        <b class="text-light judul pl-1" style="font-family:consolas;font-size:14px"><span class="bi bi-card-list"></span> Pilih Jenis Pembayaran</b>
                    </div>

                </div>

            </div>

            <?php
            // $crud
            $showData = $crud->editData($tb_siswa, 'id', $id_siswa);
            $data = $showData->fetch(PDO::FETCH_OBJ);

            $namaBayar = new namaBayar();
            $siswa = new siswa();
            $showJenis = $namaBayar->NamaTransaksi('tb_nama_bayar', 'tp', $tahun, $data->jenjang, 'kode');
            $count = $showJenis->rowCount();
            while ($datajenis = $showJenis->fetch(PDO::FETCH_OBJ)) {
                $field_tang = 'tang_' . $datajenis->kode;

                if ($data->{$field_tang} == "" || !is_numeric($data->{$field_tang})) {
                    $val_tang = 0;
                } else {
                    $val_tang = $data->{$field_tang};
                }; //Cek jika jumlah tanggungan kosong / bukan angka

                $setbulanan = $datajenis->bulanan; //Cek Apakah Bulanan

                $rupiah_tang = @(number_format($val_tang, 0, ".", "."));
                $jenis = $datajenis->kode;

                //Terbayar & Kurang
                $classTrans = new transaksi();
                $link = new linkpage();
                $infoTerbayar = $classTrans->infoterbayar($tb_transaksi, $data->nis, $jenis);
                $terbayar = @(number_format($infoTerbayar, 0, ".", "."));
                $kurang = @(number_format(($val_tang - $infoTerbayar), 0, ".", "."));

                if ($setbulanan == "Ya" || $setbulanan == "ya") {
                    $bulanan = @(number_format(($val_tang / (12 - ($startAt - 1))), 0, ".", "."));
                } else {
                    $bulanan = "--";
                };
                $linkPlus = $link->pageIDBilling($id_billing, 'billing/tambah_step2', $nis, $jenis);

                echo  $siswa->modeListTanggungan($tahun, $jenjang, $jenis, $val_tang, $infoTerbayar, $linkPlus);
            };
            //Jumlah
            $dt_jenis = new listTanggungan();
            $jumlah = $dt_jenis->tanggunganSiswa($tb_siswa, 'id', $id_siswa);
            $total_tang = number_format($jumlah, 0, ".", ".");

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

            ?>

            <div class="row">
                <div class="col-12 col-sm-12 col-md-12">
                    <div class="info-box bg-secondary">
                        <span class="info-box-icon bg-light elevation-1">#</span>

                        <div class="info-box-content">
                            <span class="info-box-text text-light"><strong>T : Rp. <?php echo $total_tang; ?></strong></span>
                            <span class="info-box-number text-light">
                                B : Rp. <?php echo $terbayarTotal; ?>
                                <br> <b class="text-warning float-right">K : Rp. <?php echo $kurangTotal; ?></b>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="clearfix hidden-md-up"></div>
            </div>

        </div>
        <!--/. container-fluid -->
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->