<?php
$cari = $_GET['Kode'];
$trSql = "SELECT * FROM siswa WHERE nis like '%$cari%' ";
$trQry = mysql_query($trSql, $koneksidb)  or die("Query penjualan salah : " . mysql_error());
$trRow = mysql_fetch_array($trQry);
$A  =   $trRow['nis'];
$B  =   $trRow['nama_siswa'];
$C  =   $trRow['status'];
$D  =   $trRow['foto'];
?>

<div class="col-lg-12 mt-5">
    <div class="card">
        <div class="card-body">
            <div class="invoice-area">
                <div class="invoice-head">
                    <div class="row">
                        <div class="iv-left col-6">
                            <span>
                                <h2><?php echo ($B); ?></h2>
                            </span>
                            <span>
                                <h6><?php echo ($C); ?></h6>
                            </span>
                        </div>
                        <div class="iv-right col-6 text-md-right">
                            <span>
                                <h2><?php echo ($A); ?></h2>
                            </span>
                            <?php
                            # Menampilkan List untuk Nomor Transaksi Terpilih
                            $listBarangSql = "SELECT kelas.*, kelas_siswa.* FROM kelas, kelas_siswa 
                            WHERE kelas_siswa.nis='$cari' AND kelas_siswa.kdkelas=kelas.kdkelas";
                            $listBarangQry = mysql_query($listBarangSql, $koneksidb)  or die("Query list barang salah : " . mysql_error());
                            $nomor  = 0;
                            while ($listBarangRow = mysql_fetch_array($listBarangQry)) {

                                $nomor++;
                            ?>
                                <span>
                                    <h6><?php echo $listBarangRow['namakelas']; ?></h6>
                                </span><br>
                            <?php } ?>
                        </div>
                    </div>
                </div>

                <div class="invoice-table table-responsive mt-5">
                    <table class="table table-bordered table-hover text-right">
                        <thead>
                            <tr class="text-capitalize">
                                <th class="text-center" style="width: 5%;">No</th>
                                <th class="text-center" style="width: 15%;">No. Transaksi</th>
                                <th class="text-center" style="width: 15%">Tanggal Transaksi</th>
                                <th class="text-center" style="width: 10%">Kelas</th>
                                <th class="text-center" style="width: 30%">Keterangan</th>
                                <th class="text-center" style="width: 25%">Jumlah</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            # Menampilkan List untuk Nomor Transaksi Terpilih
                            $listBarangSql = "SELECT transaksi.no_transaksi, transaksi.tgl_transaksi, transaksi_item.nis, transaksi_item.kelas, bulan.keterangan, transaksi_item.banyak, transaksi_item.status FROM transaksi INNER JOIN transaksi_item ON transaksi.no_transaksi=transaksi_item.no_transaksi INNER JOIN bulan ON transaksi_item.kode_bayar=bulan.kode WHERE transaksi_item.nis='$cari' ORDER BY transaksi.tgl_transaksi ASC";
                            $listBarangQry = mysql_query($listBarangSql, $koneksidb)  or die("Query list barang salah : " . mysql_error());
                            $total = 0;
                            $nomor  = 0;
                            while ($listBarangRow = mysql_fetch_array($listBarangQry)) {
                                $nomor++;
                                $total = $total + intval($listBarangRow['banyak']);
                            ?>
                                <tr>
                                    <td class="text-center">
                                        <?php echo $nomor; ?>
                                    </td>
                                    <td class="text-center">
                                        <?php echo $listBarangRow['no_transaksi']; ?>
                                    </td>
                                    <td class="text-center"><?php echo IndonesiaTgl($listBarangRow['tgl_transaksi']); ?></td>
                                    <td class="text-center"><?php echo $listBarangRow['kelas'] ?></td>
                                    <td class="text-left"><?php echo $listBarangRow['keterangan'] ?></td>
                                    <td><?php echo "Rp. " . $listBarangRow['banyak'] ?></td>
                                </tr>
                            <?php } ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="5">Total Pembayaran :</td>
                                <td><?php echo "Rp. " . format_angka($total); ?></td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
            <!-- <div class="invoice-buttons text-right">
                        <a href="#" class="invoice-btn">print invoice</a>
                        <a href="#" class="invoice-btn">send invoice</a>
                    </div> -->
        </div>
    </div>
</div>