
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>

  <script type="text/javascript">
/*  https://erroz.wordpress.com/2009/03/30/fungsi-pindah-baris/
    function nextfield(ID)
{
if (event.keyCode == 13)
document.getElementById(ID).focus();
}*/
</script>
<!-- Content Header (Page header) -->
<div class="content-header ">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-12">
        <!-- <h1 class="m-0 text-dark">Judul Atas</h1> -->
      </div><!-- /.col -->
    </div><!-- /.row -->
  </div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->

<!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            <!-- Default box -->
            <div class="card">
              <div class="card-header bg-info">
                <h3 class="card-title ">Transaksi Kas Masuk</h3>
                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>

              <script language="javascript" type="text/javascript">
/*https://www.diskusiweb.com/discussion/31709/entry-pake-key-enter-kok-gak-berhasil*/
var fromEnter = false ;
function changeFocus (event,nextFocus)
{
if (event.keyCode==13)
{
var obj = document.getElementsByName( nextFocus )[ 0 ] ;
if (obj)
obj.focus() ;
}
fromEnter = true ;
}
function checkSubmit ()
{
fromEnter = !fromEnter ;
return fromEnter ;
}
</script>         
                <?php
                $id= $_SESSION['username'];
                 include 'koneksi.php'; 
                 require './kalenderhijriah.php';
                $query1 = "SELECT * FROM user where username='".$id."' ";
                        $hasil2 = mysqli_query($koneksi, $query1);
                        $jr = mysqli_fetch_assoc($hasil2);                   ?>

              <!-- /.card-header -->
        <div class="card-body">
            <form action="home.php?home=<?php echo md5("inputjurnal");?>" method="POST" id="form-updatejurnal" name="form-updatejurnal" class="form-updatejurnal">
              <div class="form-group row">
                <label for="nama" class="col-sm-2">No Transaksi</label>
                <input type="text" name="j_faktur" id="j_faktur" readonly="j_faktur" class="form-control col-sm-9" value="<?php echo "KM".$jr['nokode'].date("YmdHis");?>">
              </div>

              <div class="form-group row">
                <label for="nama" class="col-sm-2">Tanggal</label>
                <input type="text" name="j_tgl" id="j_tgl" class="form-control col-sm-9"  value="<?php  echo sprintf('%02d', $hijri[1]) . '-' . $calendar->monthName($hijri[0]) . '-' . $hijri[2]; ; ?>" required="" onKeyDown="changeFocus(event,'j_kredit')"autofocus>
              </div>


               
              <div class="form-group row">
                <label for="nama" class="col-sm-2">Akun Kredit</label>
               
                    <select name="j_kredit" id="j_kredit" class="form-control select2 col-sm-9" onKeyDown="changeFocus(event,'j_nominal')">
                     <?php
                     include ('koneksi.php');
                     $query=" SELECT * FROM kode_akun WHERE k_akun NOT LIKE '%1.100%' ";
                     $result=$koneksi->query($query);
                     $num_result=$result->num_rows;
                     if ($num_result > 0 ) { 
                      $no=0;
                      while ($data=mysqli_fetch_assoc($result)) { ?>
                        <option  value="<?=$data['k_akun']?>" ><?=$data['k_akun'].' '.$data['n_akun']?></option>
                      <?php }
                    }
                    ?>
                  </select>
                </div>

                <div class="form-group row">
                <label for="nama" class="col-sm-2">Nominal</label>
                <input type="text" name="j_nominal" id="j_nominal" class="form-control col-sm-9" placeholder="Tulis Nominal" required=""onKeyDown="changeFocus(event,'j_keterangan')">
              </div>
              <div class="form-group row">
                <label for="nama" class="col-sm-2">Keterangan</label>
                <input type="text" name="j_keterangan" id="j_keterangan" class="form-control col-sm-9" placeholder="Tulis Keterangan" required="" onKeyDown="changeFocus(event,'updatejurnal')">
              </div>
              
            
                
              </div>
            <!-- /.card-body -->
            <div class="card-footer bg-info">
              <div class="row">
            <div class="col-sm-6 text-left">
              <input type="button" name="updatejurnal" id="updatejurnal" 
              class="btn btn-primary" value="Simpan">
            </div>

            <div class="col-sm-6 text-right">
              <!-- <a href="" class="btn btn-secondary">
                Batal
              </a> -->
              <a href="home.php?home=<?php echo md5("kM");?>" class="btn btn-secondary">
                Tambah
              </a>
              <?php if($_SESSION['level']<1){ ?>
              <a href="home.php?home=<?php echo md5("editjurnal");?>"class="btn btn-warning">
                Edit
              </a>
              <a href="home.php?home=<?php echo md5("deletjurnal");?>" class="btn btn-danger">
                Hapus
              </a>
            <?php }?>
              </a>
              <a class="btn btn-success" type="button" href="faktur/cetak_faktur_jurnal.php" target="_bank">Print</a>
            </div>
          </div>

          </form>
        </div>
        <!-- /.card -->
      </div>
      <!--/.col (left) -->
    </div>
    <!-- /.row -->
  </div><!-- /.container-fluid -->
</section>
<!-- /.content -->

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">

 $(document).ready(function(){
    $("#updatejurnal").click(function(){
      var data = $('#form-updatejurnal').serialize();
      var j_faktur= $('j_faktur').val();
      var j_tgl= $('#j_tgl').val();
      
      var j_kredit= $('#j_kredit').val();
      var j_nominal= $('#j_nominal').val();
      var j_keterangan= $('#j_keterangan').val();
      

      if(j_faktur== "0"|| j_tgl=="0" ||j_kredit=="0"||j_nominal=="0"){ 
        alert ("Data Masih ada yang kosong 1");
        //window.location.href='/rakerugt/home.php?page=cap_realita';
      
    } else if(j_faktur== ""|| j_tgl==""||j_kredit==""||j_nominal==""){ 
        alert ("Data Masih ada yang kosong 2");
       
    }else{
      $.ajax({
        type: 'POST',
        url: 'simpan/simpan_KM.php',
        data: data,
        success: function(data) {
         console.log(data)
         let timerInterval
Swal.fire({
  title: 'Alhamdulillah..! Data Tersimpan.',
  html: 'Silahkan Cek <b></b> Sendiri.',
  timer: 3000,
  timerProgressBar: true,
  didOpen: () => {
    Swal.showLoading()
    const b = Swal.getHtmlContainer().querySelector('b')
    timerInterval = setInterval(() => {
      b.textContent = Swal.getTimerLeft()
    }, 100)
  },
  willClose: () => {
    clearInterval(timerInterval)
  }
}).then((result) => {
  /* Read more about handling dismissals below */
  if (result.dismiss === Swal.DismissReason.timer) {
    console.log('I was closed by the timer')
  }
})

         /*alert("Data Sukses Disimpan");
         window.location.href='home.php?home=registrasi'; */
        },
        error: function(error){
          console.log(`error ${error}`)
         
        }
      });
    }
    });
  });
  
</script>
<script type="text/javascript">
  // untuk format koma
  //https://cobangoding.com/tips-dan-trick/memberi-titik-otomatis-pada-angka-saat-menginput-dengan-javascript/#comment-757
  //https://codepen.io/cobangoding/pen/QWOoLXN
 $('#j_nominal').on('keyup',function(){
  var angka = $(this).val();
 
  var hasilAngka = formatRibuan(angka);
 
  $(this).val(hasilAngka);
  });

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

  // tambahkan titik jika yang di input sudah menjadi angka ribuan
  if (ribuan) {
    separator = sisa ? ',' : '';
    angka_hasil += separator + ribuan.join(',');
  }

  angka_hasil =
    split[1] != undefined ? angka_hasil + '.' + split[1] : angka_hasil;
  return angka_hasil;
}
</script> 
</head>
</html>