<?php
include '../../config/conn.php';


if ($_GET['aksi'] == '') {
    if ($_GET['id'] == "") {
        $idd = addslashes($_POST['id']);
    } else {
        $idd = addslashes($_GET['id']);
    }
    $id = $idd;

    $cekjenis = mysqli_query($conn, "SELECT * FROM santri WHERE id_santri='$id'");
    if (mysqli_num_rows($cekjenis) == 0) {
        $cek = mysqli_query($conn, "SELECT * FROM nasabah_umum WHERE rekening='$id'");
        if (mysqli_num_rows($cek) == 0) {
            echo "<script>nCari('?module=home');</script>";
        } else {
            $query = mysqli_query($conn, "SELECT * FROM nasabah_umum WHERE rekening='$id'");
            $r = mysqli_fetch_array($query);

            $idrek = $r['rekening'];
            $dir = "../sikeung/images_nasabah/";
        }
    } else {

        $query = mysqli_query($conn, "SELECT * FROM santri WHERE id_santri='$id'");
        $r = mysqli_fetch_array($query);
        $idrek = $r['id_santri'];
        $dir = "../sikeung/images/";
    }


    if (isset($idrek)) {





        $tgl = date('d-m-Y', strtotime($r['tanggal_lahir']));
        $tgl1 = date('d-m-Y', strtotime($r['tanggal_masuk']));
?>

        <script>

        </script>

        <div class="col" role="main">
            <div class="">
                <div class="clearfix"></div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel" style="padding-bottom:50px;">
                            <div class="x_title" style="text-transform: capitalize;">
                                <h2>PROSES TRANSAKSI</h2>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <div class="row">
                                    <div class="col-md-2">
                                        <?php include 'foto.php';
                                        ?>


                                    </div>
                                    <div class="col-md-4">
                                        <label for="id">REK. / ID santri :</label>
                                        <input type="text" class="form-control" disabled value="<?php echo $idrek; ?>">
                                        <input type="hidden" class="form-control" name="id" value="<?php echo $idrek; ?>">

                                        <label for="nama">Namaas :</label>
                                        <input type="text" class="form-control" name="nama" disabled value="<?php echo $r['nama']; ?>">

                                        <label for="nama">tempat, Tanggal Lahir :</label>

                                        <div class="input-group">
                                            <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                                            <input type="text" class="form-control " autocomplete="no" disabled value="<?php echo $r['tempat_lahir'] . ", " . $tgl; ?>" id="tanggal" name="tanggal_lahir">
                                        </div>
                                        <label for="nama">Alamat :</label>
                                        <input type="text" class="form-control" name="tempat_lahir" disabled value="<?php echo $r['alamat']; ?>">
                                        
                                        <label for="nama">Max Saku Harian :</label>
                                        <input type="text" class="form-control" name="max_saku" disabled value="<?php echo rupiah($r['max_saku']); ?>">


                                        <label for="nama">Jumlah Saldo :</label>
                                        <input style="font-size:x-large; font-weight:bold; color:black;" type="text" class="form-control" id="saldo" name="saldo" value="<?php echo rupiah(saldo($idrek)); ?>" readonly>
                                        <input type="hidden" id="sisasaldo" value="<?php echo saldo($idrek); ?>">

                                        <label for="nama">Jumlah Pinjaman :</label>
                                        <input style="font-size:x-large; font-weight:bold; color:black;" type="text" class="form-control" id="jumlahpinjam" name="jumlahpinjam" value="<?php echo rupiah(pinjaman($idrek)); ?>" readonly>


                                    </div>
                                </div>
                                <div class="ln_solid"></div>

                                <form action="?module=<?php echo $_GET['module']; ?>&id=<?php echo $_GET['id']; ?>&periode=y" enctype="multipart/form-data" method="POST">


                                    <div class="col-md-12 col-sm-12 col-xs-12" style="padding: 4px;">
                                        <label for="nama">Pilih Periode :</label>
                                    </div>

                                    <div class="col-md-6 col-sm-12 col-xs-12" style="padding: 4px;">

                                        <div class="input-group">
                                            <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                                            <input type="text" autocomplete="off" class="form-control " id="tanggal3" required value="<?php if ($_GET['periode'] == 'y') {
                                                                                                                                            echo $_POST['tanggal1'];
                                                                                                                                        } else {
                                                                                                                                            echo "";
                                                                                                                                        } ?>" name="tanggal1">
                                            <div class="input-group-addon" style="background:white;"><small>Sampai</small></i></div>
                                            <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                                            <input type="text" autocomplete="off" class="form-control " required value="<?php if ($_GET['periode'] == 'y') {
                                                                                                                            echo $_POST['tanggal2'];
                                                                                                                        } else {
                                                                                                                            echo "";
                                                                                                                        } ?>" id="tanggal2" name="tanggal2">
                                        </div>
                                    </div>


                                    <button type="submit" class="btn btn-primary btn-sm">Pilih</button>



                                </form>

                                <div class="row">
                                    <div class="col-md-4">

                                        <?php if ($r['status_emoney'] == '1') { ?>
                                            <div class="form-group">
                                                <button type="button" class="btn btn-default btn-lg" onclick=self.history.back()>Batal</button>

                                                <a style="float: center;" class="btn btn-success btn-lg" data-toggle="modal" data-target="#modalsetor"><i class="glyphicon glyphicon-download"></i> Tambah Saldo</a>
                                                <a style="float: center;" class="btn btn-danger btn-lg" data-toggle="modal" data-target="#modaltarik"><i class="glyphicon glyphicon-download"></i> Ambil Uang</a>



                                                <!--<button type="submit" onclick="return confirm('Apakah yakin akan diedit?')" class="btn btn-success btn-sm">Simpan</button><br>-->
                                            </div>
                                        <?php } else { ?>
                                            <span class="btn btn-danger btn-lg"><i class="glyphicon glyphicon-remove"></i> Rekening NONAKTIF</span>
                                        <?php } ?>
                                        <div class="col-md-4">
                                        </div>
                                    </div>
                                    <!--tampil data pembayaran-->
                                    <table id="datatable" class="table table-striped table-bordered">
                                        <thead>
                                            <tr>
                                                <th>Tipe</th>
                                                <th>Kode transaksi</th>
                                                <th>Tanggal</th>
                                                <!-- JEnis kas -->
                                                <!-- <td>
                                                Jenis Kas
                                            </td> -->
                                                <th>Keterangann</th>
                                                <th>Debit</th>
                                                <th>Kredit</th>
                                                <th>Saldo</th>
                                                <th>cetak</th>



                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                            $no = 0;
                                            if ($_GET['periode'] == 'y') {
                                                $tgl1 = date('Y-m-d', strtotime($_POST['tanggal1']));
                                                $tgl2 = date('Y-m-d', strtotime($_POST['tanggal2']));
                                                $harisaldo = date('Y-m-d', strtotime($_POST['tanggal1']));
                                                $query = mysqli_query($conn, "SELECT * FROM transaksi_ewallet WHERE tgl_transaksi BETWEEN '$tgl1' AND '$tgl2' AND rekening='$idd' order by id_transaksi ASC ");
                                            } else {
                                                $hariini = date('Y-m-d');
                                                $harisaldo = date('Y-m-d');
                                                $query = mysqli_query($conn, "SELECT * FROM transaksi_ewallet WHERE rekening='$idd' AND tgl_transaksi='$hariini' order by id_transaksi ASC ");
                                            }

                                            $count = 2;



                                            while ($row = mysqli_fetch_array($query)) {
                                                $no++;
                                            ?>

                                                <tr style="background: <?php if ($row['kredit'] == 0) { ?>
                          #defff1;
                          <?php } else { ?>
                            #feeeea;
                            <?php } ?>">
                                                    <td><?php if ($row['kredit'] == 0) { ?><a class="btn btn-success btn-xs"><i class="glyphicon glyphicon-save-file"></i></a> <?php } else { ?> <a class="btn btn-danger btn-xs"><i class="glyphicon glyphicon-open-file"></i></a><?php } ?></td>
                                                    <td><?php echo $row['id_transaksi']; ?></td>
                                                    <td><?php echo tgl($row['tgl_transaksi']); ?></td>



                                                    <!-- Jenis kas
                                                <td>
                                                    <?php
                                                    // $jeniskas = mysqli_query($conn, "SELECT * FROM jenis_kas WHERE id='$row[jenis_kas]'");
                                                    // $jekas = mysqli_fetch_array($jeniskas);
                                                    // echo $jekas['nama'];
                                                    ?>
                                                </td> -->

                                                    <td><?php


                                                        echo $jen . $row['keterangan']; ?></td>

                                                    <?php

                                                    if ($_GET['periode'] == 'y') {
                                                        // $qsaldo = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi_ewallet WHERE rekening='$idd' AND NOT BETWEEN '$tgl1' AND '$tgl2'");
                                                        $qsaldo = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi_ewallet WHERE rekening='$idd' AND tgl_transaksi < '$tgl1'");
                                                    } else {
                                                        $qsaldo = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi_ewallet WHERE rekening='$idd' AND NOT tgl_transaksi='$harisaldo'");
                                                    }
                                                    $qrow = mysqli_fetch_array($qsaldo);
                                                    $qrowhasil = $qrow['jumlah_debit'] - $qrow['jumlah_kredit'];



                                                    if ($count == 1) { ?>

                                                        <td><?php echo "Rp." . rupiah($row['debit']); ?></td>
                                                        <td><?php echo "Rp." . rupiah($row['kredit']); ?></td>
                                                        <td>
                                                            <?php
                                                            $debit = $row['debit'];
                                                            $saldo = $row['debit'];


                                                            echo "Rp." . rupiah($saldo);
                                                            ?>
                                                        </td>

                                                        <?php } else {
                                                        if ($row['debit'] != 0) {
                                                        ?>
                                                            <td><?php echo "Rp." . rupiah($row['debit']); ?></td>
                                                            <td><?php echo "Rp." . rupiah($row['kredit']); ?></td>
                                                            <td>
                                                                <?php
                                                                $debit = $debit + $row['debit'];


                                                                if ($no == 1) {
                                                                    $saldo = $qrowhasil + $row['debit'];
                                                                } else {
                                                                    $saldo = $saldo + $row['debit'];
                                                                }
                                                                echo "Rp." . rupiah($saldo);
                                                                ?>


                                                            <?php } else { ?>
                                                            <td><?php echo "Rp." . rupiah($row['debit']); ?></td>
                                                            <td><?php echo "Rp." . rupiah($row['kredit']); ?></td>
                                                            <td>
                                                        <?php
                                                            $kredit = $kredit + $row['kredit'];
                                                            if ($no == 1) {
                                                                $saldo = $qrowhasil - $row['kredit'];
                                                            } else {
                                                                $saldo = $saldo - $row['kredit'];
                                                            }
                                                            echo "Rp." . rupiah($saldo);
                                                        }
                                                    }
                                                    $count++


                                                        ?>


                                                            <td width="50px">
                                                                <?php
                                                                if ($row['kredit'] == 0) {
                                                                ?>
                                                                    <a class="btn btn-primary btn-xs" onclick="window.open('component/com_transaksi_ewallet/cetak.php?id_tran=<?php echo $row['id_transaksi']; ?>','nama window','width=1000,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=no,resizable=yes,copyhistory=no')"><i class="glyphicon glyphicon-print"></i></a>

                                                                <?php
                                                                }else{
                                                                    ?>
                                                                    <a class="btn btn-primary btn-xs" onclick="window.open('component/com_transaksi_ewallet/cetak_ambil.php?id_tran=<?php echo $row['id_transaksi']; ?>','nama window','width=1000,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=no,resizable=yes,copyhistory=no')"><i class="glyphicon glyphicon-print"></i></a>

                                                                <?php
                                                                }
                                                                ?>
                                                            </td>

                                                </tr>

                                            <?php

                                            } ?>




                                        </tbody>
                                    </table>


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

            <?php } ?>

            <!--form tambah pembayaran-->
            <div class="modal fade" id="modaltarik" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header" style="background-color:tomato; color:white">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h3 class="modal-title" id="myModalLabel">Tarik Uang</h3>
                        </div>
                        <div class="modal-body">
                            <form action="?module=<?php echo "proses-transaksi&aksi=aksitarik"; ?>" enctype="multipart/form-data" method="POST">
                                <?php
                                $query = "SELECT max(id_transaksi) as maxID FROM transaksi ";
                                $hasil = mysqli_query($conn, $query);
                                $data = @mysqli_fetch_array($hasil);
                                $rand = rand(100, 999);
                                $urut = date('ymdHi');

                                $char = $urut . $rand;
                                $newID = $char;
                                ?>
                                <label for="id">ID Transaksi * :</label>
                                <input type="text" class="form-control" disabled value="<?php echo id_transaksi(); ?>">
                                <input type="hidden" class="form-control" name="id" value="<?php echo id_transaksi(); ?>">
                                <label for="id">ID / Rekening * :</label>
                                <input type="text" class="form-control" disabled value="<?php echo $id; ?>">
                                <input type="hidden" class="form-control" name="rek" value="<?php echo $id; ?>">

                                <label f>Tanggal * :</label>
                                <div class="input-group">
                                    <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                                    <input type="text" class="form-control " disabled autocomplete="off" value="<?php echo date('d-m-Y'); ?>" id="tanggal4" required>
                                    <input type="hidden" value="<?php echo date('d-m-Y'); ?>" name="tanggal">

                                </div>

                                <label>Jumlah Tarik Uang *:</label>
                                <input type="text" style="font-size: x-large; color:black;font-weight:bold" onkeyup="currency('rupiah2','rupiahesc2');" id="rupiah2" class="form-control" autocomplete="off" required>

                                <input type="hidden" id="rupiahesc2" class="form-control" autocomplete="off" name="jumlah_tarik" required>

                                <label f>Jenis Pembayaran * :</label>
                                <select style="font-weight: bold;color:black;font-size:large" id="heard" class="form-control" required name="jenis_kas">

                                    <option value="" selected>- Pilih Jenis -</option>
                                    <?php

                                    $query2  = "SELECT * FROM jenis_kas ORDER BY id";
                                    $tampil2 = mysqli_query($conn, $query2);
                                    while ($w = mysqli_fetch_array($tampil2)) {
                                        echo "<option value=\"$w[id]\">$w[nama]</option>";
                                    }
                                    ?>
                                </select>

                                <label for="alamat">Keterangan :</label>
                                <textarea class="form-control" name="keterangan"></textarea>


                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Batal</button>
                            <button type="submit" class="btn btn-success btn-sm">Simpan</button>
                        </div>
                        </form>
                    </div>
                </div>
            </div>

            <!-- untuk setor dana -->
            <div class="modal fade" id="modalsetor" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header" style="background-color:seagreen; color:white">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h3 class="modal-title" id="myModalLabel">Setor Dana</h3>
                        </div>
                        <div class="modal-body">
                            <form action="?module=<?php echo "proses-transaksi&aksi=aksitransaksi"; ?>" enctype="multipart/form-data" method="POST">
                                <?php
                                $query = "SELECT max(id_transaksi) as maxID FROM transaksi ";
                                $hasil = mysqli_query($conn, $query);
                                $data = @mysqli_fetch_array($hasil);
                                $rand = rand(100, 999);
                                $urut = date('ymdHi');

                                $char = $urut . $rand;
                                $newID = $char;
                                ?>
                                <label for="id">ID Transaksi * :</label>
                                <input type="text" class="form-control" disabled value="<?php echo id_transaksi(); ?>">
                                <input type="hidden" class="form-control" name="id" value="<?php echo id_transaksi(); ?>">
                                <label for="id">ID / Rekening * :</label>
                                <input type="text" class="form-control" disabled value="<?php echo $id; ?>">
                                <input type="hidden" class="form-control" name="rek" value="<?php echo $id; ?>">

                                <label f>Tanggal * :</label>
                                <div class="input-group">
                                    <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                                    <input type="text" class="form-control " disabled autocomplete="off" value="<?php echo date('d-m-Y'); ?>" id="tanggal4" required>
                                    <input type="hidden" value="<?php echo date('d-m-Y'); ?>" name="tanggal">

                                </div>

                                <label>Jumlah setor *:</label>
                                <input type="text" style="font-size: x-large; color:black;font-weight:bold" onkeyup="currency('rupiah1','rupiahesc1');" id="rupiah1" class="form-control" autocomplete="off" required>

                                <input type="hidden" id="rupiahesc1" class="form-control" autocomplete="off" name="jumlah_setor" required>

                                <label f>Jenis Pembayaran * :</label>
                                <select style="font-weight: bold;color:black;font-size:large" id="heard" class="form-control" required name="jenis_kas">

                                    <option value="" selected>- Pilih Jenis -</option>
                                    <?php

                                    $query2  = "SELECT * FROM jenis_kas ORDER BY id";
                                    $tampil2 = mysqli_query($conn, $query2);
                                    while ($w = mysqli_fetch_array($tampil2)) {
                                        echo "<option value=\"$w[id]\">$w[nama]</option>";
                                    }
                                    ?>
                                </select>

                                <label for="alamat">Keterangan :</label>
                                <textarea class="form-control" name="keterangan"></textarea>


                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Batal</button>
                            <button type="submit" class="btn btn-success btn-sm">Simpan</button>
                        </div>
                        </form>
                    </div>
                </div>
            </div>

            <!-- untuk Transfer -->
            <div class="modal fade" id="modaltransfer" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header" style="background-color:darkgoldenrod; color:white">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h3 class="modal-title" id="myModalLabel">TRANSFER Dana</h3>
                        </div>
                        <div class="modal-body">
                            <form action="?module=<?php echo "proses-transaksi&aksi=aksitransfer"; ?>" enctype="multipart/form-data" method="POST">
                                <?php
                                $query = "SELECT max(id_transaksi) as maxID FROM transaksi ";
                                $hasil = mysqli_query($conn, $query);
                                $data = @mysqli_fetch_array($hasil);
                                $rand = rand(100, 999);
                                $urut = date('ymdHi');

                                $char = $urut . $rand;
                                $newID = $char;
                                ?>
                                <!-- rek pengirim -->
                                <input type="hidden" class="form-control" name="rek" value="<?php echo $id; ?>">


                                <input type="hidden" class="form-control" name="id" value="<?php echo id_transaksi(); ?>">

                                <input type="hidden" value="<?php echo date('d-m-Y'); ?>" name="tanggal">


                                <label for="id">Cari Rek. Tujuan * :</label>
                                <input type="text" autocomplete="off" class="form-control" name="rek1" value="" id="rek1">
                                <input type="submit" onclick="isi_otomatis()" class="btn btn-primary btn-sm" value="Cari"></input><br>



                                <div id="tf">
                                    <div id="tampil">

                                    </div>

                                    <label for="id">Nama Penerima * :</label>
                                    <input type="text" readonly onchange="cek1()" class="form-control" name="nama1" id="nama1" value="">

                                    <label for="id">Alamat Penerima * :</label>
                                    <input type="text" readonly class="form-control" id="alamat1" value="">


                                    <label>Jumlah Transfer *:</label>
                                    <input type="text" style="font-size:xx-large; color:black;font-weight:bold" onkeyup="currency('rupiah3','rupiahesc3');" id="rupiah3" class="form-control" autocomplete="off" required>

                                    <input type="hidden" id="rupiahesc3" class="form-control" autocomplete="off" name="jumlah_tf" required>

                                    <label for="alamat">Keterangan Khusus :
                                    </label>
                                    <textarea class="form-control" name="keterangan"></textarea>



                                    <div class="modal-footer">
                                        <button type="button" onclick="resetall()" class="btn btn-default btn-sm" data-dismiss="modal">Batal</button>
                                        <button type="submit" class="btn btn-success btn-sm">Simpan</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <script type="text/javascript">
                var o = document.getElementById("tf");
                var rek1 = document.getElementById("rek1");



                function sembunyi() {
                    o.style.display = "none";

                }

                function tampil() {

                    o.style.display = "block";
                    rek1.readOnly = true;

                }

                function cek() {
                    alert("Hello! I am an alert box!!");

                }

                function cek1() {
                    var t1 = document.getElementById("nama1").value;
                    if (t1 === "") {

                        sembunyi();
                        window.alert("Rekening Tidak Terdaftar");
                        document.getElementById("rek1").value = "";

                    } else {


                        tampil();
                    }
                }



                sembunyi();

                function resetall() {
                    rek1.readOnly = false;
                    sembunyi();
                    document.getElementById("rek1").value = "";
                    reset();


                }



                function isi_otomatis() {
                    var rek = $("#rek1").val();
                    $.ajax({
                        method: "POST",
                        url: 'component/com_transaksi_ewallet/ajaxrespon.php',
                        data: "rek=" + rek,
                    }).success(function(data) {
                        var json = data,
                            obj = JSON.parse(json);
                        $('#nama1').val(obj.nama);
                        $('#alamat1').val(obj.alamat);

                        cek1();
                    });

                    var request = $.ajax({
                        method: "POST",
                        url: "component/com_transaksi_ewallet/foto_transfer.php",
                        data: "rek=" + rek,
                        dataType: "html"
                    });

                    //menampilkan pesan Sedang mencari saat aplikasi melakukan proses pencarian
                    $('#tampil').html('Sedang Mencari…');

                    //Jika pencarian selesai
                    request.done(function(output) {
                        //Tampilkan hasil pencarian pada tag div dengan id hasil-cari
                        $('#tampil').html(output);
                    });

                }
            </script>


            <script type="text/javascript">
                // $(document).ready(function() {
                //     $('#cari').on('keyup', function() {
                //         $.ajax({
                //             type: 'POST',
                //             url: 'component/com_transaksi_ewallet/foto_transfer.php',
                //             data: {
                //                 cari: $(this).val()
                //             },
                //             cache: false,
                //             success: function(data) {
                //                 $('#tampil').html(data);
                //             }
                //         });
                //     });
                // });
            </script>
            <!--untuk edit data dam-->
        <?php } elseif ($_GET['aksi'] == 'form_edit') { ?>
            <div class="col" role="main">
                <div class="">
                    <div class="clearfix"></div>
                    <div class="row">
                        <div class="col-md-12 col-sm-12 col-xs-12">
                            <div class="x_panel">

                                <form action="?module=<?php echo "proses-transaksi"; ?>&aksi=simpan_edit" enctype="multipart/form-data" method="POST">
                                    <?php


                                    $query = "SELECT * FROM transaksi_ewallet WHERE id_transaksi='$_GET[id_tran]' ";
                                    $hasil = mysqli_query($conn, $query);
                                    $data = mysqli_fetch_array($hasil);

                                    ?>
                                    <label for="id">ID Transaksi * :</label>
                                    <input type="text" class="form-control" disabled value="<?php echo $_GET['id_tran'];
                                                                                            ?>">
                                    <input type="hidden" class="form-control" name="id" value="<?php echo $_GET['id_tran']; ?>">
                                    <label for="id">No. Id/Rekening * :</label>
                                    <input type="text" class="form-control" readonly name="rek" value="<?php echo $data['rekening']; ?>">


                                    <label f>Tanggal pembayaran * :</label>
                                    <div class="input-group">
                                        <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                                        <input type="text" class="form-control " autocomplete="off" value="<?php echo date('d-m-Y', strtotime($data['tgl_transaksi'])); ?>" id="tanggal4" name="tanggal" required>
                                    </div>

                                    <label>Jumlah pembayaran *:</label>

                                    <?php
                                    if ($data['debit'] == 0) {
                                        $jumlah = $data['kredit'];
                                        $name = "kredit";
                                    } else {
                                        $jumlah = $data['debit'];
                                        $name = "debit";
                                    }
                                    ?>
                                    <input type="number" class="form-control" autocomplete="off" name="<?php echo $name; ?>" value="<?php echo $jumlah; ?>" required>

                                    <label for="alamat">Keterangan :</label>
                                    <textarea class="form-control" name="keterangan"><?php echo $data['keterangan']; ?></textarea>


                            </div>
                            <div class="modal-footer">

                                <a href="?module=proses-transaksi&id=<?php echo $data['rekening']; ?>"><button type="button" class="btn btn-default btn-sm">Batal</button></a>
                                <button type="submit" class="btn btn-success btn-sm">Simpan</button>
                            </div>
                            </form>

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





        <?php } elseif ($_GET['aksi'] == 'aksitransaksi') {
        $module = $_GET['module'];
        $tgl = date('Y-m-d', strtotime($_POST['tanggal']));
        if (!isset($_POST['jumlah_tarik'])) {
            $jen = '2';
            $save = mysqli_query($conn, "INSERT INTO transaksi_ewallet(id_transaksi,
                                  rekening,
                                  tgl_transaksi,
                                  debit,
                                  kredit,
                                  keterangan,user_id,jenis) VALUES('$_POST[id]',
                                                 '$_POST[rek]',
                                                 '$tgl',
                                                 '$_POST[jumlah_setor]',
                                                 '0',
                                                 'Input adm bend- $_POST[keterangan]','$_SESSION[id]','$jen')");
        } else {
            if (($_POST['jumlah_tarik']) > saldo($_POST['rek'])) {
                // echo "<script>nSimpansaldo('?module=proses-transaksi&id=$rek');</script>";
                echo "<script>alert('Saldo tidak Mencukupi, silahkan hubungi Wali santri !!!');</script>";
            } else {
                $jen = '1';
                $save = mysqli_query($conn, "INSERT INTO transaksi_ewallet(id_transaksi,
            rekening,
            tgl_transaksi,
            debit,
            kredit,
            keterangan,user_id,jenis) VALUES('$_POST[id]',
                           '$_POST[rek]',
                           '$tgl',
                           '0',
                           '$_POST[jumlah_tarik]',
                           '$_POST[keterangan]','$_SESSION[id]','$jen')");
            }
        }


        $rek = $_POST['rek'];
        // echo "<script language='javascript'>document.location='?module=pembayaran-dam&aksi=tambah_dam&id=$id_san';</script>";
        if (!$save) {
            echo "gagal";
            echo "<script>nSimpan('?module=proses-transaksi&id=$rek');</script>";
        } else {
            historysimpan($_POST['id'], $_SESSION['id'], $_SESSION['mac'], $jen);
            $save1 = mysqli_query($conn, "INSERT INTO transaksi(id_santri,
                                          tanggal,
                                          debit,
                                          kredit,
                                          keterangan,id_jenis,id_pegawai,jenis_kas) VALUES('$_POST[rek]',
                                                         '$tgl',
                                                         '$_POST[jumlah_setor]',
                                                         '0',
                                                         'Input adm bend- $_POST[keterangan]','21','$_SESSION[id]','$_POST[jenis_kas]')");


            if (!$save1) {
                echo "gagal masuk pembukuan utama";
                echo "<script>nSimpan('?module=proses-transaksi&id=$rek');</script>";
            } else {
                echo "<script>ySimpan('?module=proses-transaksi&id=$rek');</script>";
                echo "sukses";
            }
        }
    }
    
     elseif ($_GET['aksi'] == 'aksitarik') {
        $module = $_GET['module'];
        $tgl = date('Y-m-d', strtotime($_POST['tanggal']));
        if (!isset($_POST['jumlah_tarik'])) {
            $jen = '2';
            $save = mysqli_query($conn, "INSERT INTO transaksi_ewallet(id_transaksi,
                                  rekening,
                                  tgl_transaksi,
                                  debit,
                                  kredit,
                                  keterangan,user_id,jenis) VALUES('$_POST[id]',
                                                 '$_POST[rek]',
                                                 '$tgl',
                                                 '$_POST[jumlah_setor]',
                                                 '0',
                                                 'Input adm bend- $_POST[keterangan]','$_SESSION[id]','$jen')");
        } else {
            if (($_POST['jumlah_tarik']) > saldo($_POST['rek'])) {
                // echo "<script>nSimpansaldo('?module=proses-transaksi&id=$rek');</script>";
                echo "<script>alert('Saldo tidak Mencukupi, silahkan hubungi Wali santri !!!');</script>";
            } else {
                $jen = '1';
                $save = mysqli_query($conn, "INSERT INTO transaksi_ewallet(id_transaksi,
            rekening,
            tgl_transaksi,
            debit,
            kredit,
            keterangan,user_id,jenis) VALUES('$_POST[id]',
                           '$_POST[rek]',
                           '$tgl',
                           '0',
                           '$_POST[jumlah_tarik]',
                           'Input adm bend- $_POST[keterangan]','$_SESSION[id]','$jen')");
            }
        }


        $rek = $_POST['rek'];
        // echo "<script language='javascript'>document.location='?module=pembayaran-dam&aksi=tambah_dam&id=$id_san';</script>";
        if (!$save) {
            echo "gagal";
            echo "<script>nSimpan('?module=proses-transaksi&id=$rek');</script>";
        } else {
            historysimpan($_POST['id'], $_SESSION['id'], $_SESSION['mac'], $jen);
            $save1 = mysqli_query($conn, "INSERT INTO transaksi(id_santri,
                                          tanggal,
                                          debit,
                                          kredit,
                                          keterangan,id_jenis,id_jenis_sumber,id_pegawai,jenis_kas) VALUES('$_POST[rek]',
                                                         '$tgl',
                                                         '0',
                                                         '$_POST[jumlah_tarik]',
                                                         'Input adm bend- Tarik Uang $_POST[keterangan]','99','21','$_SESSION[id]','$_POST[jenis_kas]')");


            if (!$save1) {
                echo "gagal masuk pembukuan utama";
                echo "<script>nSimpan('?module=proses-transaksi&id=$rek');</script>";
            } else {
                echo "<script>ySimpan('?module=proses-transaksi&id=$rek');</script>";
                echo "sukses";
            }
        }
    }
    
    
    
    
    //transferrr
    elseif ($_GET['aksi'] == 'aksitransfer') {
        $module = $_GET['module'];
        $tgl = date('Y-m-d', strtotime($_POST['tanggal']));
        $jen = '3';

        if (($_POST['jumlah_tf']) > saldo($_POST['rek'])) {
            // echo "<script>nSimpansaldo('?module=proses-transaksi&id=$rek');</script>";
            echo "<script>alert('Saldo tidak Mencukupi, silahkan hubungi Wali santri !!!');</script>";
        } else {
            $nama = nama($_POST['rek']);
            $nama1 = nama($_POST['rek1']);
            $idtran1 = id_transaksi();
            $save = mysqli_query($conn, "INSERT INTO transaksi_ewallet(id_transaksi,
            rekening,
            tgl_transaksi,
            debit,
            kredit,
            keterangan,user_id,jenis) VALUES('$_POST[id]',
                           '$_POST[rek1]',
                           '$tgl',
                           '$_POST[jumlah_tf]',
                           '0',
                           'TF dari $_POST[rek]-$nama-$_POST[keterangan]','$_SESSION[id]','3')");

            $save1 = mysqli_query($conn, "INSERT INTO transaksi_ewallet(id_transaksi,
            rekening,
            tgl_transaksi,
            debit,
            kredit,
            keterangan,user_id,jenis) VALUES('$idtran1',
                           '$_POST[rek]',
                           '$tgl',
                           '0',
                           '$_POST[jumlah_tf]',
                           'TF ke $_POST[rek1]-$nama1-$_POST[keterangan]','$_SESSION[id]','3')");
        }






        $rek = $_POST['rek'];
        // echo "<script language='javascript'>document.location='?module=pembayaran-dam&aksi=tambah_dam&id=$id_san';</script>";
        if (!$save or !$save1) {
            echo "gagal";
            echo "<script>nSimpan('?module=proses-transaksi&id=$rek');</script>";
        } else {
            historysimpan($_POST['id'], $_SESSION['id'], $_SESSION['mac'], $jen);
            echo "<script>ySimpan('?module=proses-transaksi&id=$rek');</script>";
            echo "sukses";
        }
    } elseif ($_GET['aksi'] == 'simpan_edit') {
        $module = $_GET['module'];
        $tgl1 = date('Y-m-d', strtotime($_POST['tanggal']));

        //log edit 
        // $query = "SELECT * FROM transaksi_ewallet WHERE id_transaksi='$_POST[id]' ";
        // $hasil = mysqli_query($conn, $query);
        // $data = mysqli_fetch_array($hasil);


        // $logedit = $data['log_edit'] . "[" . $_SESSION['id'] . "~" . date('Y-m-d H:i:s') . "]";

        if (!isset($_POST['debit'])) {
            $save = mysqli_query($conn, "UPDATE transaksi_ewallet SET tgl_transaksi = '$tgl1',
            kredit = '$_POST[kredit]',
            keterangan = '$_POST[keterangan]',
            jenis = '1'
            WHERE id_transaksi = '$_POST[id]'") or die("GAGAL");
        } else {
            $save = mysqli_query($conn, "UPDATE transaksi_ewallet SET tgl_transaksi = '$tgl1',
            debit = '$_POST[debit]',
            keterangan = '$_POST[keterangan]',
            jenis = '2'
            WHERE id_transaksi = '$_POST[id]'") or die("GAGAL");
        }

        $jen = 'e';
        // echo "<script language='javascript'>document.location='?module=pembayaran-dam&aksi=tambah_dam&id=$id_san';</script>";
        if (!$save) {
            echo "<script>nSimpan('?module=proses-transaksi&id=$_POST[rek]');</script>";
        } else {
            historysimpan($_POST['id'], $_SESSION['id'], $_SESSION['mac'], $jen);
            echo "<script>ySimpan('?module=proses-transaksi&id=$_POST[rek]');</script>";
        }
    } elseif ($_GET['aksi'] == 'hapus') {
        $module = $_GET['module'];
        $id = $_GET['id'];
        $query = mysqli_query($conn, "DELETE FROM transaksi_ewallet WHERE id_transaksi='$_GET[id_tran]'");
        // echo "< language='javascript'>document.location='?module=pembayaran-dam&aksi=tambah_dam&id=$idd';</>";
        $jen = 'h';
        if (!$query) {

            echo "<script>nHapus('?module=$module&id=$id');</script>";
        } else {
            historysimpan($_GET['id_tran'], $_SESSION['id'], $_SESSION['mac'], $jen);
            echo "<script>yHapus('?module=$module&id=$id');</script>";
        }
    } ?>


        <div class="modal fade" id="modal_delete">
            <div class="modal-dialog">
                <div class="modal-content" style="margin-top:100px;">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" style="text-align:center;">Apakah anda yakin menghapus data ini ?</h4>
                    </div>
                    <div class="modal-footer" style="margin:0px; border-top:0px; text-align:center;">
                        <a href="#" class="btn btn-danger btn-sm" id="delete_link">Hapus</a>
                        <button type="button" class="btn btn-success btn-sm" data-dismiss="modal">Batal</button>
                    </div>
                </div>
            </div>
        </div>

        <script>
            function currency(id, idesc) {

                var rupiah1 = document.getElementById(id);
                var rupiahesc = document.getElementById(idesc);
                var isisaldo = document.getElementById('saldo');
                var sisasaldo = document.getElementById('sisasaldo');




                if (rupiah1.value == 0) {
                    rupiah1.value = '';
                }

                if (id == 'rupiah2') {
                    if (escrupiah(rupiah1.value) > parseInt(sisasaldo.value)) {
                        alert('SALDO TIDAK MENCUKUPI !!!');
                        rupiah1.value = '';
                        rupiahesc.value = '';
                    }

                }

                if (rupiah3.value == 0) {
                    rupiah3.value = '';
                }

                if (id == 'rupiah3') {
                    if (escrupiah(rupiah3.value) > parseInt(sisasaldo.value)) {
                        alert('SALDO TIDAK MENCUKUPI !!!');
                        rupiah3.value = '';
                        rupiahesc3.value = '';
                    }

                }


                rupiah1.addEventListener("keyup", function(e) {

                    rupiah1.value = convertRupiah(this.value);
                    rupiahesc.value = escrupiah(rupiah1.value);




                });
                rupiah1.addEventListener('keydown', function(event) {
                    return isNumberKey(event);
                });

                function convertRupiah(angka, prefix) {
                    var number_string = angka.replace(/[^,\d]/g, "").toString(),
                        split = number_string.split(","),
                        sisa = split[0].length % 3,
                        rupiah = split[0].substr(0, sisa),
                        ribuan = split[0].substr(sisa).match(/\d{3}/gi);

                    if (ribuan) {
                        separator = sisa ? "." : "";
                        rupiah += separator + ribuan.join(".");
                    }

                    rupiah = split[1] != undefined ? rupiah + "," + split[1] : rupiah;
                    return prefix == undefined ? rupiah : rupiah ? prefix + rupiah : "";
                }

                function escrupiah(angka) {
                    return (angka.replace(/\D/g, ''))
                }

                function isNumberKey(evt) {
                    key = evt.which || evt.keyCode;
                    if (key != 188 // Comma
                        &&
                        key != 8 // Backspace
                        &&
                        key != 17 && key != 86 & key != 67 // Ctrl c, ctrl v
                        &&
                        (key < 48 || key > 57) // Non digit
                    ) {
                        evt.preventDefault();
                        return;
                    }
                }

            }
        </script>