<?php
include '../../config/conn.php';
if ($_GET['aksi'] == '') {
    $jenis = $_GET['type'];


    if ($_GET['periode'] == 'y') {
        $tanggal1 = $_POST['tanggal1'];
        $tanggal2 = $_POST['tanggal2'];
        $tgl1 = date('Y-m-d', strtotime($tanggal1));
        $tgl2 = date('Y-m-d', strtotime($tanggal2));
        $query_saldo = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi WHERE tanggal BETWEEN '$tgl1' AND '$tgl2'");
      } else {
        $hariini = date('Y-m-d');
        $query_saldo = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi WHERE  tanggal='$hariini'");
     }

    $row_saldo = mysqli_fetch_array($query_saldo);
    $saldo_keseluruhan = $row_saldo['jumlah_debit'] - $row_saldo['jumlah_kredit'];


?>

    <!-- page content -->
    <div class="col" role="main">
        <div class="">


            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12 margin-center">
                    <div class="x_panel">
                        <div class="x_title" style="text-transform: capitalize; margin:0;">
                            <h2 style="align: center;">Data TRANSAKSI HARIAN <?php echo $hariini; ?></h2>

                            <div class="clearfix"></div>

                            <div class="well" style="overflow: auto">
                <form action="?module=rekap-lap-transaksiharian&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="tanggal" required value="<?php if ($_GET['periode'] == 'y') {
                                                                                                                  echo $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 $tanggal2;
                                                                                                  } else {
                                                                                                    echo "";
                                                                                                  } ?>" id="tanggal2" name="tanggal2">
                    </div>
                  </div>

                  <div class="col-md-6 col-sm-12 col-xs-12" style="padding: 4px;">
                    <button type="submit" class="btn btn-primary btn-sm">Pilih</button>



              </form>


            </div>



                        </div><br>
                                <div class="col-md-3 col-sm-12 col-xs-12" style="margin-left: 0px;">

                            <h4>
                                <table>
                                    <tr style="color:green">
                                        <td><small><b>TOTAL DEBIT </b></small></td>
                                        <td align="right">&nbsp; Rp. <?php echo rupiah($row_saldo['jumlah_debit']); ?></td>
                                    </tr>
                                    <tr style="color:red">
                                        <td id="hit"><small><b>TOTAL KREDIT </b></small></td>
                                        <td align="right">&nbsp; Rp. <?php echo rupiah($row_saldo['jumlah_kredit']); ?></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" height="2px" bgcolor="black"></td>
                                    </tr>
                                    <tr>
                                        <td id="hit"><small><b>TOTAL </b></small></td>
                                        <td align="right">&nbsp; Rp. <?php echo rupiah($saldo_keseluruhan); ?></td>
                                    </tr>
                                </table>
                            </h4>
                        </div>



                     
                        <div class="x_content" id="timestamp">

                            <table style="font-size:18px;color:black" id="datatable1" class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th>NO.</th>
                                        <th>Jenis Kas</th>
                                        <th>Pemasukan</th>
                                        <th>Pengeluaran</th>
                                        <th>
                                            Total
                                        </th>
                                        <th>+ Uang Awal</th>
                                        <th>- Bawa Uang</th>
                                        <th>+ Kembalikan Bawa Uang</th>
                                        <th>Total Akhir</th>

                                        
                                    </tr>
                                </thead>
                                <tbody >
                                    <?php
                                    $no = 0;

                                    $hariini = date('Y-m-d');

                                    if ($_GET['periode'] == 'y') {
                                    //untuk filter antara tanggal a dan b
                                     $query = mysqli_query($conn, "SELECT 
    j.id, 
    j.nama, 
    SUM(t.debit) AS jumlah_debit, 
    SUM(t.kredit) AS jumlah_kredit,
    COALESCE(u.jumlah_uangawal, 0) AS jumlah_uangawal,
    COALESCE(b1.total_bawa_tgl_totalan, 0) AS jumlah_bawa_tgl_totalan,
    COALESCE(b2.total_bawa_tgl_bawa, 0) AS jumlah_bawa_tgl_bawa
FROM jenis_kas j
LEFT JOIN (
    SELECT jenis_kas, SUM(debit) AS debit, SUM(kredit) AS kredit
    FROM transaksi
    WHERE tanggal BETWEEN '$tgl1' AND '$tgl2'
    GROUP BY jenis_kas
) t ON j.id = t.jenis_kas
LEFT JOIN (
    SELECT jenis_kas, SUM(jumlah) AS jumlah_uangawal
    FROM transaksi_uangawal
    WHERE tanggal BETWEEN '$tgl1' AND '$tgl2'
    GROUP BY jenis_kas
) u ON j.id = u.jenis_kas
LEFT JOIN (
    SELECT jenis_kas, SUM(jumlah_bawa) AS total_bawa_tgl_totalan
    FROM transaksi_bawauang
    WHERE tgl_totalan BETWEEN '$tgl1' AND '$tgl2' AND valid ='1'
    GROUP BY jenis_kas
) b1 ON j.id = b1.jenis_kas
LEFT JOIN (
    SELECT jenis_kas, SUM(jumlah_bawa) AS total_bawa_tgl_bawa
    FROM transaksi_bawauang
    WHERE tgl_bawa BETWEEN '$tgl1' AND '$tgl2'
    GROUP BY jenis_kas
) b2 ON j.id = b2.jenis_kas
GROUP BY j.id, j.nama;");
                                    } else {
                                      
                                    //untuk filter hari ini
                                    $query = mysqli_query($conn, "SELECT 
                                                                    j.id, 
                                                                    j.nama, 
                                                                    SUM(t.debit) AS jumlah_debit, 
                                                                    SUM(t.kredit) AS jumlah_kredit,
                                                                    COALESCE(u.jumlah_uangawal, 0) AS jumlah_uangawal,
                                                                    COALESCE(b1.total_bawa_tgl_totalan, 0) AS jumlah_bawa_tgl_totalan,
                                                                    COALESCE(b2.total_bawa_tgl_bawa, 0) AS jumlah_bawa_tgl_bawa
                                                                FROM jenis_kas j
                                                                LEFT JOIN (
                                                                    SELECT jenis_kas, SUM(debit) AS debit, SUM(kredit) AS kredit
                                                                    FROM transaksi
                                                                    WHERE tanggal = '$hariini'
                                                                    GROUP BY jenis_kas
                                                                ) t ON j.id = t.jenis_kas
                                                                LEFT JOIN (
                                                                    SELECT jenis_kas, SUM(jumlah) AS jumlah_uangawal
                                                                    FROM transaksi_uangawal
                                                                    WHERE tanggal = '$hariini'
                                                                    GROUP BY jenis_kas
                                                                ) u ON j.id = u.jenis_kas
                                                                LEFT JOIN (
                                                                    SELECT jenis_kas, SUM(jumlah_bawa) AS total_bawa_tgl_totalan
                                                                    FROM transaksi_bawauang
                                                                    WHERE tgl_totalan = '$hariini' AND valid ='1'
                                                                    GROUP BY jenis_kas
                                                                ) b1 ON j.id = b1.jenis_kas
                                                                LEFT JOIN (
                                                                    SELECT jenis_kas, SUM(jumlah_bawa) AS total_bawa_tgl_bawa
                                                                    FROM transaksi_bawauang
                                                                    WHERE tgl_bawa = '$hariini'
                                                                    GROUP BY jenis_kas
                                                                ) b2 ON j.id = b2.jenis_kas
                                                                GROUP BY j.id, j.nama;
                                                                ");
                                      }
                                    


                                    $count = 2;



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

                                        <tr style="background: <?php if ($no % 2 == 0) { ?>
                          #defff1;
                          <?php } else { ?>
                            #f2f2f2;
                            <?php } ?>;text-align: right;">
                                            <td><?php echo $no; ?></td>
                                            <td><?php echo $row['nama']; ?></td>
                                            <td><?php echo rupiah($row['jumlah_debit']); ?></td>
                                            <td><?php echo rupiah($row['jumlah_kredit']); ?></td>
                                            <td><?php echo rupiah($row['jumlah_debit']-$row['jumlah_kredit']); ?></td>
                                            <td><?php echo rupiah($row['jumlah_uangawal']); ?></td>
                                            <td><?php echo rupiah($row['jumlah_bawa_tgl_bawa']); ?></td>
                                            <td><?php echo rupiah($row['jumlah_bawa_tgl_totalan']); ?></td>
                                            <td style="font-weight: bold;"><?php echo rupiah($row['jumlah_debit']-$row['jumlah_kredit']+$row['jumlah_uangawal']-$row['jumlah_bawa_tgl_bawa']+$row['jumlah_bawa_tgl_totalan']); ?></td>
  

                                        </tr>

                                <?php
                                              
                                            } ?>




                                </tbody>
                            </table>

                            <div class="x_title" style="text-transform: capitalize; margin:0;">
                            <h2 style="text-align: center;color:black">Data Bawa Uang (Total : <?php echo rupiah(totalbawauang()); ?>)</h2>

                            <div class="clearfix"></div>




                        </div><br>
                            <table style="font-size:18px;color:black" id="datatable" class="table table-striped table-bordered">
                <thead>
                  <tr>
                  <th>No.</th>
                    <th>Id Bawa Uang</th>
                    <th>Print</th>
                    <th>Nama</th>
                    <th>Tgl Bawa</th>
                    <th>Waktu Input</th>
                    <th>Jenis Kas</th>
                    <th>Jumlah Bawa</th>
                    <th>Keterangan Bawa</th>
                    <th>Pemberi</th>
                    <th>Status</th>
                    <th>Tgl Totalan</th>
                    <th>Penerima Totalan</th>

                    <th>aksi</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
                  $no = 0;
                  if ($_GET['periode'] == 'y') {
                    $query = mysqli_query($conn, "SELECT * FROM transaksi_bawauang WHERE tgl_bawa BETWEEN '$tgl1' AND '$tgl2' order by tgl_bawa ASC ");
                  } else {
                    $hariini = date('Y-m-d');
                    $query = mysqli_query($conn, "SELECT * FROM transaksi_bawauang WHERE valid != '1' OR tgl_totalan = '$hariini' order by valid DESC, id_transaksi DESC ");
                  }

                  $count = 2;



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

                    <tr style="background: <?php if ($row['valid'] == "1") { ?>
                          #defff1;
                          <?php } else { ?>
                            #feeeea;
                            <?php } ?>">
                      <td><?php echo $no; ?></td>
                      <td><?php echo $row['id_transaksi']; ?></td>
                      <td>
                      <a class="btn btn-primary btn-xs" onclick="window.open('component/com_transaksi/cetak_bawauang.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>
                    </td>
                      <td><?php echo namapekerja($row['id_pekerja']); ?></td>
                      <td><?php echo $row['tgl_bawa']; ?></td>
                      <td><?php echo $row['waktu_real']; ?></td>
                      <td><?php echo namajeniskas($row['jenis_kas']); ?></td>
                      <td><?php echo rupiah($row['jumlah_bawa']); ?></td>
                      <td><?php echo $row['keterangan']; ?></td>
                      <td><?php echo namapegawai($row['id_pegawai_pemberi']); ?></td>
                      <td><?php 
                      
                      if ($_SESSION['leveluser'] == "admin" ) {
                        if ($row['valid']=="1") {
                          if ($_SESSION['id'] == "P0001" ) {
                            echo "<a class=\"btn  btn-success btn-xs\"  onclick=\"confirm_modal('?module=$_GET[module]&aksi=ubahstatus&valid=0&id_transaksi=$row[id_transaksi]');\">Sudah</a>";
                          }else{
                            echo "<div style='color:green;font-size:14px'>Sudah</div>";
                          }
                        } else {
                          echo "<a class=\"btn  btn-warning btn-xs\"  onclick=\"confirm_modal('?module=$_GET[module]&aksi=ubahstatus&valid=1&id_transaksi=$row[id_transaksi]');\">Belum</a>";
                        }
                      }else{
                        if ($row['valid']=="1") {
                          echo "<div style='color:green;font-size:14px'>Sudah</div>";
                        } elseif ($row['valid']=="0" OR $row['valid']==""){
                          echo "<a class=\"btn  btn-warning btn-xs\">Belum</a>";
                        }
                      }
                      
                      ?></td>
                      <td><?php echo $row['tgl_totalan']; ?></td>
                      <td><?php echo namapegawai($row['id_pegawai_penerima']); ?></td>
                      
                           <td>
                          <?php
                          if ($_SESSION['leveluser'] == 'admin' AND $_SESSION['id'] == 'P0001') {
                          ?>
                            <a class='open_modal btn  btn-default btn-xs' href="?module=lap-bawauang&aksi=form_edit&id_tran=<?php echo $row['id_transaksi']; ?>"><i class="glyphicon glyphicon-edit"></i> Edit</a>
                            <a class="btn  btn-danger btn-xs" onclick="confirm_modal('?module=lap-bawauang&aksi=hapus&type=<?php echo $_GET['type']; ?>&id_tran=<?php echo $row['id_transaksi']; ?>');"><i class="glyphicon glyphicon-trash"></i> Hapus</a>

                          <?php

                          } else {
                            echo "<a data-toggle='modal' data-target='#akses_edit'><i>Akses dibatasi</i></a>";
                          }

                          ?>

                        </td>
                          
                          
                          
                          <?php
                      
                    } ?>




                </tbody>
              </table>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <!-- /page content --><br>


    <!-- edit data transaksi -->
<?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=transaksiharian&aksi=simpan_edit" enctype="multipart/form-data" method="POST">
                            <?php


                            $query = "SELECT * FROM transaksi WHERE id_transaksi='$_GET[id_tran]' ";
                            $hasil = mysqli_query($conn, $query);
                            $data = mysqli_fetch_array($hasil);
                            if ($data['kredit'] == 0) {
                                $jenis = "1";
                            } else {
                                $jenis = "0";
                            }

                            ?>
                            <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']; ?>" />
                            <input type="hidden" class="form-control" name="type" value="<?php echo $_GET['type']; ?>" />

                            <label for="id">Jenis * :</label>
                            <input type="text" class="form-control" disabled value="<?php if ($jenis == "1") {
                                                                                        echo "pemasukan";
                                                                                    } else {
                                                                                        echo "pengeluaran";
                                                                                    }
                                                                                    ?>">
                            <input type="hidden" class="form-control" name="jenis" value="<?php echo $jenis; ?>" />


                            <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['tanggal'])); ?>" id="tanggal4" name="tanggal" required>
                            </div>
                            <label f>Jenis Transaksi * :</label>
                            <select id="heard" class="form-control" required name="jenis_transaksi">

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

                                $query2  = "SELECT * FROM jenis_transaksi ORDER BY nama_jenis ASC";
                                $tampil2 = mysqli_query($conn, $query2);
                                while ($w = mysqli_fetch_array($tampil2)) { ?>
                                    <option value="<?php echo $w['id_jenis']; ?>" <?php if ($data['id_jenis'] == $w['id_jenis']) {
                                                                                        echo "selected";
                                                                                    } ?>><?php echo $w['nama_jenis']; ?></option>";
                                <?php }
                                ?>
                            </select>

                            <label>Jumlah pembayaran *:</label>
                            <input style="font-weight: bold;color:black;font-size:large" type="number" class="form-control" autocomplete="off" name="jumlah_bayar" value="<?php if ($data['debit'] == "0") {
                                                                                                                                                                                echo $data['kredit'];
                                                                                                                                                                            } else {
                                                                                                                                                                                echo $data['debit'];
                                                                                                                                                                            } ?>" required />

                            <label f>Jenis Pembayaran * :</label>
                            <select 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)) {
                                ?>
                                    <option value="<?php echo $w['id']; ?>" <?php if ($data['jenis_kas'] == $w['id']) {
                                                                                echo "selected";
                                                                            } ?>><?php echo $w['nama']; ?></option>";
                                <?php
                                }
                                ?>
                            </select>

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


                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default btn-sm" onclick=self.history.back()>Batal</button>
                        <button type="submit" class="btn btn-success btn-sm">Simpan</button>
                    </div>
                    </form>

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






<?php } elseif ($_GET['aksi'] == 'pemasukan') {

    $tgl = date('Y-m-d', strtotime($_POST['tanggal']));
    $save = mysqli_query($conn, "INSERT INTO transaksi(
                                  tanggal,
                                  debit,
                                  kredit,
                                  keterangan,id_jenis,id_pegawai,jenis_kas) VALUES(
                                                 '$tgl',
                                                 '$_POST[debit]',
                                                 '0',
                                                 '$_POST[keterangan]','$_POST[jenis_transaksi]','$_SESSION[id]','$_POST[jenis_kas]')");
    // echo "<script language='javascript'>document.location='?module=transaksiharian';</script>";
    if (!$save) {
        echo "<script>nSimpan('?module=transaksiharian');</script>";
    } else {
        historysimpan($_POST['id'], $_SESSION['id'], $_SESSION['mac'], $_POST['jenis_transaksi']);
        echo "<script>ySimpan('?module=transaksiharian');</script>";
    }


?>


<?php


} elseif ($_GET['aksi'] == 'pengeluaran') {
    $tgl = date('Y-m-d', strtotime($_POST['tanggal']));
    $save = mysqli_query($conn, "INSERT INTO transaksi(
                                  tanggal,
                                  debit,
                                  kredit,
                                  keterangan,id_jenis,id_jenis_sumber,id_pegawai,jenis_kas,id_tag_hut) VALUES(
                                                 '$tgl',
                                                 '0',
                                                 '$_POST[kredit]',
                                                 '$_POST[keterangan]','$_POST[jenis_transaksi]','$_POST[jenis_transaksi_sumber]','$_SESSION[id]','$_POST[jenis_kas]','$_POST[id_tag_hut]')");

    // echo "<script language='javascript'>document.location='?module=transaksiharian';</script>";
    if (!$save) {
        echo "<script>nSimpan('?module=transaksiharian');</script>";
    } else {
        historysimpan($_POST['id'], $_SESSION['id'], $_SESSION['mac'], $_POST['jenis_transaksi']);
        echo "<script>ySimpan('?module=transaksiharian');</script>";
    }
}elseif ($_GET['aksi'] == 'uangawal') {
    $tgl = date('Y-m-d', strtotime($_POST['tanggal']));
    $save = mysqli_query($conn, "INSERT INTO transaksi_uangawal(
                                  tanggal,
                                  jumlah,
                                  keterangan,
                                  jenis_kas,id_pegawai) VALUES(
                                                 '$tgl',
                                                 '$_POST[jumlah]',
                                                 '$_POST[keterangan]','$_POST[jenis_kas]','$_SESSION[id]')");

    // echo "<script language='javascript'>document.location='?module=transaksiharian';</script>";
    if (!$save) {
        echo "<script>nSimpan('?module=transaksiharian');</script>";
    } else {
        historysimpan($_POST['id'], $_SESSION['id'], $_SESSION['mac'],"uang awal");
        echo "<script>ySimpan('?module=transaksiharian');</script>";
    }
} elseif ($_GET['aksi'] == 'simpan_edit') {

    $module = $_GET['module'];
    $tgl1 = date('Y-m-d', strtotime($_POST['tanggal']));

    //log edit 
    $query = "SELECT * FROM transaksi 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 ($_POST['jenis'] == "1") {

        $save = mysqli_query($conn, "UPDATE transaksi SET tanggal = '$tgl1',
                                    debit = '$_POST[jumlah_bayar]',
                                    keterangan = '$_POST[keterangan]',
                                    jenis_kas='$_POST[jenis_kas]',id_jenis='$_POST[jenis_transaksi]',
                                    log_edit='$logedit'
                                    WHERE id_transaksi = '$_POST[id]'");
    } else {
        $save = mysqli_query($conn, "UPDATE transaksi SET tanggal = '$tgl1',
    kredit = '$_POST[jumlah_bayar]',
    keterangan = '$_POST[keterangan]',
    jenis_kas='$_POST[jenis_kas]',id_jenis='$_POST[jenis_transaksi]',
    log_edit='$logedit',id_tag_hut='$_POST[id_tag_hut]'
    WHERE id_transaksi = '$_POST[id]'");
    }

    // echo "<script language='javascript'>document.location='?module=transaksiharian';</script>";
    if (!$save) {
        echo mysqli_error($conn);
        echo "gagal";
        echo "<script>nSimpan('?module=transaksiharian');</script>";
    } else {
        historyedit($_POST['id'], $_SESSION['id'], $_SESSION['mac'], $_POST['jenis_transaksi']);
        echo "<script>ySimpan('?module=transaksiharian');</script>";
    }
} elseif ($_GET['aksi'] == 'hapus') {

    $query = mysqli_query($conn, "DELETE FROM transaksi WHERE id_transaksi='$_GET[id_tran]'") or die("GAGAL");
    // echo "<script language='javascript'>document.location='?module=transaksi&type=$_GET[type]';</script>";
    if (!$query) {
        echo "<script>ySimpan('?module=transaksiharian');</script>";
    } else {
        historyhapus($_GET['id_tran'], $_SESSION['id'], $_SESSION['mac'], $_POST['jenis_transaksi']);
        echo "<script>ySimpan('?module=transaksiharian');</script>";
    }
} elseif ($_GET['aksi'] == 'mutasi') {
//untuk mutasi


 $ket_mutasi = "$_POST[dari_kas] to -> $_POST[ke_kas] | ";
 $module = $_GET['module'];
        $tgl = date('Y-m-d', strtotime($_POST['tanggal']));
            $jen = '2';
            $save = mysqli_query($conn, "INSERT INTO transaksi(
                                          tanggal,
                                          debit, 
                                          kredit,
                                          keterangan,id_jenis,id_pegawai,jenis_kas) VALUES(
                                                         '$tgl',
                                                         '0',
                                                         '$_POST[jumlah_mutasi]',
                                                         '$ket_mutasi- $_POST[keterangan]','22','$_SESSION[id]','$_POST[dari_kas]')");
        // 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(
                                          tanggal,
                                          debit,
                                          kredit,
                                          keterangan,id_jenis,id_pegawai,jenis_kas) VALUES(
                                                         '$tgl',
                                                         '$_POST[jumlah_mutasi]',
                                                         '0',
                                                         '$ket_mutasi- $_POST[keterangan]','22','$_SESSION[id]','$_POST[ke_kas]')");


            if (!$save1) {
                echo "gagal masuk pembukuan utama";
                echo "<script>nSimpan('?module=transaksiharian');</script>";
            } else {
                echo "<script>ySimpan('?module=transaksiharian');</script>";
                echo "sukses";
            }
        }
    }elseif ($_GET['aksi'] == 'ubahstatus') {
        $module = $_GET['module'];
          if ($_GET['valid']=="1"){
            $tgl1 = date('Y-m-d');
          $query=mysqli_query($conn, "UPDATE transaksi_bawauang SET valid = '$_GET[valid]',
                                              id_pegawai_penerima = '$_SESSION[id]',
                                              tgl_totalan = '$tgl1'
                                             WHERE id_transaksi = '$_GET[id_transaksi]'");
          }else{
            $query=mysqli_query($conn, "UPDATE transaksi_bawauang SET valid = '$_GET[valid]',
                                              id_pegawai_penerima = '', tgl_totalan = '0000-00-00'
                                             WHERE id_transaksi = '$_GET[id_transaksi]'");
          }
        
        if (!$query) {
          echo mysqli_error($conn);
          echo "gagal";
      } else {
          echo "<script>ySimpan('?module=" . $module . "');</script>";
      }
      }
 ?>




<!--  Tambah Bawa Uang -->



<!-- modal delete-->
<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 mengubah 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">Ubah</a>
        <button type="button" class="btn btn-success btn-sm" data-dismiss="modal">Batal</button>
      </div>
    </div>
  </div>
</div>

<!-- modal akses edit-->
<div class="modal fade" id="akses_edit">
  <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;">Hubungi Administrator Utama untuk merevisi atau menghapus</h4>
      </div>
      <div class="modal-footer" style="margin:0px; border-top:0px; text-align:center;">
        <button type="button" class="btn btn-success btn-sm" data-dismiss="modal">OK</button>
      </div>
    </div>
  </div>
</div>



<script>
   

    function isNumberKey(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))

            return false;
        return true;
    }

    //untuk pada tambah data transaksi pengeluaran (tagihan hutan)
  document.getElementById("inputtaghut").style.display = "none";

function taghut() {
  //aktif/nonaktif taghut
  var x = document.getElementById("inputtaghut");
  if (x.style.display === "none") {
    x.style.display = "block";
    document.getElementById("onoff").innnerHTML =
      "ON";
      } else {
    x.style.display = "none";
    Webcam.reset();
  }
}
</script>