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

<!-- 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 ">Edit Pencairan</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>
              <!-- /.card-header -->
        <div class="card-body">

          <!-- Croping Photo -->

<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css">
 -->  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.2/croppie.min.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.2/croppie.js"></script>

<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
                  error_reporting(E_ALL^(E_NOTICE|E_WARNING));
                  ini_set('display_errors',1);
                  error_reporting(0);
                 include 'koneksi.php'; 
                      if(isset($_POST['r_register'])){                  
                      $id=$_POST["r_register"];
                   
                        $query4 = "SELECT no_bukti,register,rekening,plafond,jeniscair,kelengkapan,barang,kondisi,jenisbarang,jaminan,taksasi,jangkawaktu,margin,noseri,keterangan, COUNT(register) as jml,tglsystem FROM pinjaman where rekening='".$id."' ";
                         
                        $hasil1 = mysqli_query($koneksi, $query4);
                        $reg = mysqli_fetch_assoc($hasil1); 
                        extract($reg);      
                         }
                         ?>

              

            <form action="" method="POST">
          <div class="row">
            <div class="col-sm-6">
              
             <div class="form-group row ">
              <label for="nama" class=" col-sm-3">No Rekening </label>
        
              <input type="text" name="r_register" id="r_register" placeholder="Ketik Rekening" class="form-control col-sm-6" value="<?php echo  $_POST['r_register'];?>" onchange="this.form.submit();" onKeyDown="changeFocus(event,'tgl')"/>
              
                    
                <button type="submit" class="  btn btn-info"  ><i class="fas fa-search"></i></button>
               </div>
            </form>
                    <?php
                    if(isset($_POST['r_register'])){                  
                      $id=$_POST["r_register"];  
                    ?>   

          <form name="form-simpanpencairan" action="" method="POST"  class="form-simpanpencairan" id="form-simpanpencairan">
              
              <input type="hidden" name="tglsystem" id="tglsystem" class="form-control col-sm-8" value="<?php echo  $reg['tglsystem']; ?>" readonly="rekening"/>

              <input type="hidden" name="rekening" id="rekening" class="form-control col-sm-8" value="<?php echo  $_POST['r_register'] ?>" readonly="rekening"/>
              
              <input type="hidden" name="no_bukti" id="no_bukti" class="form-control col-sm-8" value="<?php echo $no_bukti ?>" /> 

              <div class="form-group row">
                <label for="nama" class="col-sm-4">Tanggal</label>
                <input type="date" name="tgl" id="tgl" class="form-control col-sm-8" value="<? echo date('d-m-Y')?>" max="<?=date('Y-m-d')?>"onKeyDown="changeFocus(event,'plafond')"autofocus/>
              </div>
               
                
             

              <div class="form-group row">
                <label for="nama" class="col-sm-4">Plafond</label>
                <input type="text" name="plafond" id="plafond" class="form-control col-sm-8" value="<?php echo  number_format($plafond,0); ?>" onKeyDown="changeFocus(event,'jcair')"/> 
              </div>

              <div class="form-group row">
                <label for="nama" class="col-sm-4">Jenis Cair</label>
                <div class="custom-control custom-radio col-sm-3 ">
                          <input type="radio" class="custom-control-input"  id="customRadio1" name="jcair" onKeyDown="changeFocus(event,'pbarang')" value="B"<?php echo ($jeniscair=='B')?"checked":""; ?> >   
                          <label for="customRadio1" class="custom-control-label">Baru </label>
                </div>
                <div class="custom-control custom-radio col-sm-4">
                          <input class="custom-control-input " type="radio" id="customRadio2" name="jcair" onKeyDown="changeFocus(event,'pbarang')" value="P" <?php echo ($jeniscair=='P')?"checked":""; ?> > 
                          <!-- https://rajaputramedia.com/artikel/membuat-form-dan-script-edit-data-php-mysql.php -->
                          <label for="customRadio2" class="custom-control-label">Perpanjangan</label>
                 </div>
              </div>
               

            <div class="form-group row">
                <label for="nama" class="col-sm-4">Pengajuan Barang</label>
                <input type="text" name="pbarang" id="pbarang" class="form-control col-sm-8" value="<?php echo  $barang; ?>" onkeyup="this.value = this.value.toUpperCase()" onKeyDown="changeFocus(event,'jbarang')"/>

            </div>
            
            <div class="form-group row">
                <label for="nama" class="col-sm-4">Jenis Barang</label>
                <div class="custom-control custom-radio col-sm-3 ">
                          <input class="custom-control-input " type="radio" id="customRadio4" name="jbarang" onKeyDown="changeFocus(event,'kelengkapan')"  value="Elektronik" <?php echo ($jenisbarang=='Elektronik')?"checked":""; ?> > 
                          <label for="customRadio4" class="custom-control-label">Elektronik </label>
                        </div>
                        <div class="custom-control custom-radio col-sm-4">
                          <input class="custom-control-input " type="radio" id="customRadio5" name="jbarang" onKeyDown="changeFocus(event,'kelengkapan')" value="Kendaraan" <?php echo ($jenisbarang=='Kendaraan')?"checked":""; ?> >
                          <label for="customRadio5" class="custom-control-label">Kendaraan</label>
                 </div>
              </div>
 
          <div class="form-group row">
                <label for="nama" class="col-sm-4">Kelengkapan</label>
                <select id="kelengkapan" name="kelengkapan" class="form-control col-sm-8 select2" onKeyDown="changeFocus(event,'jaminan')">
                
                <option value="UNIT KOTAK" <?php echo ($kelengkapan=='UNIT KOTAK')?"selected":""; ?>>UNIT KOTAK</option>  
                <option value="UNIT CHAS" <?php echo ($kelengkapan=='UNIT CHAS')?"selected":""; ?>>UNIT CHAS</option>
                <option value="UNIT CHAS KOTAK" <?php echo ($kelengkapan=='UNIT CHAS KOTAK')?"selected":""; ?>>UNIT CHAS KOTAK</option>
                <option value="UNIT CHAS TAS" <?php echo ($kelengkapan=='UNIT CHAS TAS')?"selected":""; ?>>UNIT CHAS TAS</option>
                <option value="UNIT KOTAK REMOT" <?php echo ($kelengkapan=='UNIT KOTAK REMOT')?"selected":""; ?>>UNIT KOTAK REMOT</option>
                <option value="UNIT REMOT" <?php echo ($kelengkapan=='UNIT REMOT')?"selected":""; ?>>UNIT REMOT</option>
                <option value="UNIT BPKB STNK" <?php echo ($kelengkapan=='UNIT BPKB STNK')?"selected":""; ?>>UNIT BPKB STNK</option>
                <option value="STNK KTP" <?php echo ($kelengkapan=='STNK KTP')?"selected":""; ?>>STNK KTP</option>

                    <!-- https://rajaputramedia.com/artikel/membuat-form-dan-script-edit-data-php-mysql.php -->
                  </select>
            </div>

            <div class="form-group row">
                <label for="nama" class="col-sm-4">Jaminan</label>
                <select id="jaminan" name="jaminan" class="form-control col-sm-8 select2" onKeyDown="changeFocus(event,'taksasi')">
                  <option value="TV" <?php echo ($jaminan=='TV')?"selected":""; ?>>TV</option>
                <option value="HP" <?php echo ($jaminan=='HP')?"selected":""; ?>>HP</option>
                <option value="LAPTOP" <?php echo ($jaminan=='LAPTOP')?"selected":""; ?>>LAPTOP</option>
                <option value="SPEKAR AKTOR" <?php echo ($jaminan=='SPEKAR AKTOR')?"selected":""; ?>>SPEKAR AKTOR</option>
                <option value="DRON" <?php echo ($jaminan=='DRON')?"selected":""; ?>>DRON</option>
                <option value="PROYEKTOR" <?php echo ($jaminan=='PROYEKTOR')?"selected":""; ?>>PROYEKTOR</option>
                <option value="SEPEDA YAMAHA" <?php echo ($jaminan=='SEPEDA YAMAHA')?"selected":""; ?>>SEPEDA YAMAHA</option>
                <option value="SEPEDA HONDA<" <?php echo ($jaminan=='SEPEDA HONDA<')?"selected":""; ?>>SEPEDA HONDA<</option>
                <option value="SEPEDA SUZUKI" <?php echo ($jaminan=='SEPEDA SUZUKI')?"selected":""; ?>>SEPEDA SUZUKI</option>
                <option value="SEPEDA KAWASAKI" <?php echo ($jaminan=='SEPEDA KAWASAKI')?"selected":""; ?>>SEPEDA KAWASAKI</option>
                <option value="MOBIL TOYOTA" <?php echo ($jaminan=='MOBIL TOYOTA')?"selected":""; ?>>MOBIL TOYOTA</option>
                <option value="MOBIL DAIHATSU" <?php echo ($jaminan=='MOBIL DAIHATSU')?"selected":""; ?>>MOBIL DAIHATSU</option>
                <option value="MOBIL SUZUKI" <?php echo ($jaminan=='MOBIL SUZUKI')?"selected":""; ?>>MOBIL SUZUKI</option>
                <option value="MOBIL MITSUBISHI" <?php echo ($jaminan=='MOBIL MITSUBISHI')?"selected":""; ?>>MOBIL MITSUBISHI</option>

                    
                  </select>

            </div>

          </div>
        
            <?php 
            $query1 = "SELECT * FROM registrasi where id='".substr($id,0,10)."' ";
              $hasil2 = mysqli_query($koneksi, $query1);
              $row = mysqli_fetch_assoc($hasil2);
             ?>

              <div class="col-sm-6">

              <div class="form-group row">
                <label for="nama" class="col-sm-4">Taksiran</label>
                <input type="text" name="taksasi" id="taksasi" maxlength="12" minlength="11" class="form-control col-sm-8" value="<?php echo  number_format($reg['taksasi'],0); ?>"  onkeyup="validAngka(this)" onkeypress="return hanyaAngka(event)" onKeyDown="changeFocus(event,'jwaktu')"/>      
              </div>

              <div class="form-group row">
                <label for="nama" class="col-sm-4">No Hp</label>
                <input type="text" name="nohp" id="nohp" maxlength="12" minlength="11" class="form-control col-sm-8" value="<?php echo  $row['nohp']; ?>"  onkeyup="validAngka(this)" onkeypress="return hanyaAngka(event)" onKeyDown="changeFocus(event,'jwaktu')"/>      
              </div>

              <div class="form-group row">
                <label for="nama" class="col-sm-4">Jangka Waktu</label>
                <input type="text" name="jwaktu" id="jwaktu" value="<?php echo $jangkawaktu;?>" class="form-control col-sm-8"onkeyup="validAngka(this)" onkeypress="return hanyaAngka(event)" minlength="1" maxlength="2" onKeyDown="changeFocus(event,'margin')"/>    
              </div>
              

              <div class="form-group row">
                <label for="nama" class="col-sm-4">Margin</label>
                <input type="text" name="margin" id="margin" value="<?php echo $margin;?>" class="form-control col-sm-8" minlength="1" maxlength="3" onKeyDown="changeFocus(event,'noseri')"/>      
              </div>
                            
              <div class="form-group row">
                <label for="nama"  class="col-sm-4">SN/Plat</label>
                <input type="text" name="noseri" id="noseri" value="<?php echo $noseri;?>" class="form-control col-sm-8" onKeyDown="changeFocus(event,'kondisi')"/>    
              </div>
              
               <div class="form-group row">
                <label for="nama"  class="col-sm-4">Kondisi</label>
                <input type="text" name="kondisi" id="kondisi" value="<?php echo $kondisi;?>" class="form-control col-sm-8" onKeyDown="changeFocus(event,'keterangan')"/>    
              </div>

              <div class="form-group row">
                <label for="nama"  class="col-sm-4">Keterangan</label>
               <input type="text" name="keterangan" id="keterangan" value="<?php echo $keterangan;?>" class="form-control col-sm-8" onKeyDown="changeFocus(event,'simpanpencairan')"/>
                
              </div>

              <div class="form-group row">
                <label for="nama" class="col-sm-4">Nama</label>  
                <input type="text" class="form-control col-sm-8"required="" readonly="nama" value="<?php echo $row['nama']; ?>"/>  
              </div>

              <div class="form-group row">
                <label for="nama" class="col-sm-4">Alamat</label>  
                <input type="text" class="form-control col-sm-8" required="" value="<?php echo $row['alamat']; ?>" readonly="alamat"/>
                  
              </div>
                  

                </div>
              </div>
        
           </div>
              
            <!-- /.card-body -->
            <div class="card-footer bg-info">
              <input type="button" name="simpanpencairan" id="simpanpencairan" 
              class="btn btn-primary" value="Simpan" onclick='document.geElementById("form-simpanpencairan").submit()'>
              <!-- <a href="" class="btn btn-secondary">
                Batal
              </a> -->
              <a href="home.php?home=<?php echo md5("pencairan");?>" class="btn btn-secondary">
                Tambah
              </a>
              <?php if($_SESSION['level']<0){ ?>
              <a href="home.php?home=<?php echo md5("edit_pencairan");?>" class="btn btn-warning">
                Edit
              </a>
              <a href="" class="btn btn-danger">
                Hapus
              </a>
            <?php }?>
            </div>  
          </form>
        <?php } ?>

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


<!-- <style>
input:out-of-range {
  border:2px solid red;
}
</style> -->
<!-- <script type="text/javascript" src="jquery.js"></script>  -->
<script type="text/javascript">

 $(document).ready(function(){
    $("#simpanpencairan").click(function(){
      var data = $('#form-simpanpencairan').serialize();
      var register= $('#register').val();
      var rekening= $('#rekening').val();
      var tgl= $('#tgl').val();
      var plafond= $('#plafond').val().replace(/,(?=\d{3})/g, '');
      var jcair= $('#jcair').val();
      var pbarang= $('#pbarang').val();
      var jbarang= $('#jbarang').val();
      var kelengkapan= $('#kelengkapan').val();
      var jaminan= $('#jaminan').val();
      var nohp= $('#nohp').val();
      var jwaktu= $('#jwaktu').val();
      var margin= $('#margin').val();
      var noseri= $('#noseri').val();
      var keterangan= $('#keterangan').val();
      var no_bukti= $('#no_bukti').val();
      var taksasi= $('#taksasi').val();
      
      

      
      

      if(tgl=="0" ||rekening=="0"||plafond=="0"||jcair=="0"||pbarang=="0"||jbarang=="0"||kelengkapan=="0"||jaminan=="0"||nohp=="0"||jwaktu=="0"||margin=="0"||noseri=="0"||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>'
});
/*https://sweetalert2.github.io/*/
       /* alert ("Data Masih ada yang kosong 1");*/
        //window.location.href='/rakerugt/home.php?page=cap_realita';
      
    } else if(tgl=="" ||rekening==""||plafond==""||jcair==""||pbarang==""||jbarang==""||kelengkapan==""||jaminan==""||nohp==""||jwaktu==""||margin==""||noseri==""||keterangan==""){ 

      Swal.fire(
  'Data Masih ada yang Kosong !',
  'Mohon data dilengkapi dlu !',
  'question'
);
        /*alert ("Data Masih ada yang kosong 2");*/
       
    }else{

      $.ajax({
        type: 'POST',
        url: 'simpan/simpan_pinjaman_edit.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=f14cbd957174c9ad73d33ce51523378d';
        },
        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
 $('#plafond').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>   

<!-- 
input huruf besar
https://bloggerbodrex.blogspot.com/2017/05/cara-agar-input-data-menjadi-huruf.html
  <td><input type="text" name="vnama" size="20" onkeyup="this.value = this.value.toUpperCase()" required></td>
 -->
<script>
  /*required onkeypress='return harusHuruf(event)' tinggal pasang ke input
  https://kursuswebdesign.org/cara-membuat-validasi-input-form-hanya-text-dengan-javascript/*/
function harusHuruf(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode < 65 || charCode > 90)&&(charCode < 97 || charCode > 122)&&charCode>32)
            return false;
        return true;
}
</script>

<script>
    function hanyaAngka(evt) {
      var charCode = (evt.which) ? evt.which : event.keyCode
       if (charCode > 31 && (charCode < 48 || charCode > 57))
 
        return false;
      return true;
    }
  </script>

</head>
</html>