<html>

<head>
    <title>Faktur Pembayaran</title>
    <style>
        #tabel {
            font-size: 15px;
            border-collapse: collapse;
        }

        #tabel td {
            padding-left: 5px;
            border: 1px solid black;
        }
    </style>
</head>

<body style="margin-left: 20px ;" style='font-family:tahoma;' onload="javascript:">
    <center>
        <table style='width:550px; font-family:calibri; border-collapse: collapse;' border='0'>
            <td width='100%' align='left' style='padding-right:80px; vertical-align:top'>
                <H2>PONDOK TAHFIDZ MODERN AL-IMAM</H2>
                <div style="margin-top: -22px; font-size:12pt;"> Tiru Kidul, Kec. Gurah, Kab. Kediri <br>
                    HP : 0823 3131 1998</div>
            </td>

        </table><br>
        <table style='width:550px; font-size:15pt; font-family:calibri; border-collapse: collapse;' border='0'>
            <td width='100%' align='left' style='padding-right:80px; vertical-align:top'>
                09 Januari 2021 11:09:12 <br>
                ID TRAN. : 6253821534721 <br>
                ------------------------------------- <br>
                ID Santri : Pelanggan</br>
                Nama : bagus setyo <br>
                Jenis : SPP/ Infaq bulanan <br>
                bulan 12 tahun 2022 <br>
                ------------------------------------- <br>
                Jumlah Bayar : Rp.600.000 <br>
                bagus setyo cahyono bayar bulanan pondok tahfidz modern alimam <br>
                ------------------------------------- <br>
                User : Bagus (p001) <br>
                Tgl Cetak 12/12/2021
            </td>

        </table>

    </center>

    <?php
    $hp1 = mysqli_query($conn, "SELECT * FROM pengaturan WHERE id_pengaturan=1");
    $hp = mysqli_fetch_array($hp1);

    $query = mysqli_query($conn, "SELECT * FROM transaksi WHERE id_transaksi='$_GET[id_tran]' order by tanggal ASC ");



    while ($row = mysqli_fetch_array($query)) {
        if ($row['id_jenis'] == "11" or $row['id_jenis'] == "12") {
            //rumahtahfidz
            $keri = mysqli_query($conn, "SELECT * FROM santri_rt WHERE id_santri='$row[id_santri]'");
            $r = mysqli_fetch_array($keri);

            $kelas1 = mysqli_query($conn, "SELECT nama_jenis FROM jenis_rt WHERE id='$r[jenis_rt]'");
            $kls = mysqli_fetch_array($kelas1);
        } else {
            $keri = mysqli_query($conn, "SELECT * FROM santri WHERE id_santri='$row[id_santri]'");
            $r = mysqli_fetch_array($keri);
        }

        $b1 = mysqli_query($conn, "SELECT * FROM bulan WHERE id_bulan='$row[spp_bulan]'");
        $b = mysqli_fetch_array($b1);

        //nama admin
        $adm1 = mysqli_query($conn, "SELECT * FROM pegawai WHERE id_pegawai='$row[id_pegawai]'");
        $adm = mysqli_fetch_array($adm1);

        try {


            /* mulai cetak */
            $printer->setJustification(Printer::JUSTIFY_CENTER);
            $printer->bitImage($tux);
            $printer->text("Pondok Tahfidz Modern AL-IMAM \n");
            $printer->text("Ds. Tirukidul, Kec. Gurah\n");
            $printer->text("Kabupaten Kediri\n");
            $printer->text("Telp. : " . $hp['telephone'] . "\n");
            $printer->text("-----------------------------\n");
            $printer->text("ADMIN : " . $adm['nama'] . "| " . $row['tanggal'] . " \n");
            $printer->text("NO TRANSAKSI : $row[id_transaksi] \n");
            $printer->text("-----------------------------\n");

            /* buat perulangan data transaksi */


            /* bagian footer */
            $jns1 = mysqli_query($conn, "SELECT * FROM jenis_transaksi WHERE id_jenis='$row[id_jenis]'");
            $jns = mysqli_fetch_array($jns1);

            $printer->setJustification(Printer::JUSTIFY_LEFT);
            if ($row['id_jenis'] == "5") {
                $printer->text("Jenis Pembayaran : $jns[nama_jenis]\n");
                $printer->text("Bulan/Tahun : $b[nama_bulan] $row[spp_tahun] \n");
            } elseif ($row['id_jenis'] == "14") {
                $printer->text("Jenis Pembayaran : Dana awal masuk\n");
            } elseif ($row['id_jenis'] == "11" or $row['id_jenis'] == "12") {
                $printer->text("Jenis Pembayaran : $jns[nama_jenis] | $kls[nama_jenis]\n");
                $printer->text("Bulan/Tahun : $b[nama_bulan] $row[spp_tahun] \n");
            }
            $printer->text("Id Santri : $row[id_santri] \n");
            $printer->text("Nama Santri: $r[nama] \n");
            $printer->setJustification(Printer::JUSTIFY_CENTER);
            $printer->text("-----------------------------\n");
            $printer->setJustification(Printer::JUSTIFY_LEFT);
            $rp = rupiah($row['debit']);
            $printer->text("JUMLAH BAYAR : Rp.$rp \n");
            $printer->text("KETERANGAN : $row[keterangan]\n");
            $printer->setJustification(Printer::JUSTIFY_CENTER);
            $printer->text("-----------------------------\n");
            $printer->text("Jazakallah Khairan \n");
            $printer->text("tgl cetak struk " . date('d/m/y H:i') . " \n");
            $printer->text(" \n");
            $printer->text(" \n");
            $printer->text(" \n");
            $printer->text(" \n");
            $printer->text(" \n");


            //potong kertas
            $printer->cut();

            /* Close printer */
            $printer->close();
        } catch (Exception $e) {
            echo "TIDAK TERKONEKSI DENGAN PRINTER: " . $e->getMessage() . "\n";
        }
        $id_san = $row['id_santri'];

        //lokasi setelah print
        // if ($row['id_jenis'] == "5") {
        //     echo "<script>alert('Pastikan cetak 2 kali, untuk arsip!');history.go(-1);</script>";
        //     //echo "<script language='javascript'>document.location='../../?module=pembayaran-spp&aksi=tambah_spp&id=$id_san';</script>";

        // } elseif ($row['id_jenis'] == "14") {
        //     echo "<script>alert('Pastikan cetak 2 kali, untuk arsip!');history.go(-1);</script>";
        //     //echo "<script language='javascript'>document.location='../../?module=pembayaran-dam&aksi=tambah_dam&id=$id_san';</script>";     
        // }
        echo "<script>alert('Pastikan cetak 2 kali, untuk arsip!');history.go(-1);</script>";
    }
    ?>


</body>


<script type="text/javascript">
    window.print();
    window.onafterprint = window.close;
</script>

</html>