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

<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 Jurnal</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 "JR".$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]; ; ?>" max="<?=date('Y-m-d')?>" required="" onKeyDown="changeFocus(event,'j_debet')"autofocus>
            </div>


             
            <div class="form-group row">
              <label for="nama" class="col-sm-2" >Akun Debet</label>
             
                  <select name="j_debet" id="j_debet" class="form-control select2 col-sm-9" onKeyDown="changeFocus(event,'j_kredit')">
                   <?php
                   include ('koneksi.php');
                   $query="SELECT * from kode_akun";
                   $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">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";
                   $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" >
            <!-- <a href="" class="btn btn-secondary">
              Batal
            </a> -->
          </div>
            <div class="col-sm-6 text-right">
            <a href="home.php?home=<?php echo md5("inputjurnal");?>"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 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_debet= $('#j_debet').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_debet=="0" ||j_kredit=="0"||j_nominal=="0" || j_keterangan=="0"){ 
      Swal.fire({
icon: 'error',
title: 'Hati-hati...',
text: 'Data masih ada yg belum diisi!',
footer: '<a href="">Anda Perlu teliti sedikit lagi?</a>'
});
      //window.location.href='/rakerugt/home.php?page=cap_realita';
    
  } else if(j_faktur== ""|| j_tgl=="" || j_debet=="" ||j_kredit==""||j_nominal==""|| j_keterangan==""){ 
      Swal.fire({
icon: 'error',
title: 'Hati-hati...',
text: 'Data masih ada yg belum diisi!',
footer: '<a href="">Anda Perlu teliti sedikit lagi?</a>'
});
     
  }else{
    $.ajax({
      type: 'POST',
      url: 'simpan/simpan_jurnal.php',
      data: data,
      success: function(data) {
       console.log(data)
       let timerInterval
       /* alert("Data Sudah Tersimpan");
      alert("Cetak Validasi?");


      window.location.href="laporan/cetak_faktur2.php" ;*/ 

       Swal.fire({
title: 'Mau Print?',
text: "Pilih Tombol Print!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',

confirmButtonText: '<a href="faktur/cetak_jurnal.php" target="_bank" class="text-white">Print</a>'  
}).then((result) => {
if (result.value) {

  /*
  Swal.fire(
    'Deleted!',
    '<a class="fa fa-print" href="laporan/cetak_faktur2.php" target="_blank">Print</a>',
    'Clik Tombol di atas'
  )*/
}
})

      

      },
      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>