<!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 ">Realisasi Gadai</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>  
  
<!-- <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet"> -->


     <?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 register, COUNT(register) as jml FROM pinjaman where register='".$id."' ";
                       
                      $hasil1 = mysqli_query($koneksi, $query4);
                      $reg = mysqli_fetch_assoc($hasil1);       
                       }
                       ?>

            

          <form action="" method="POST">
        
        <div class="row">

          <div class="col-sm-6">
             
           <div class="form-group row ">
            <label for="nama" class=" col-sm-4">No Register </label>
      
            <input type="text" name="r_register" id="r_register" placeholder="Ketik Register" class="form-control col-sm-6" value="<?php if(isset($_POST['r_register'])){ echo  $_POST['r_register'].".".sprintf("%02d",$reg['jml']+1);}?>" 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=".../../simpan/simpan_pinjaman.php" method="POST" class="form-simpanpencairan" id="form-simpanpencairan" >
            <input type="hidden" name="register" id="register"class="form-control col-sm-6" value="<?php echo $_POST['r_register'];?>">
            
            <input type="hidden" name="rekening" id="rekening" class="form-control col-sm-7" value="<?php echo  $_POST['r_register'].".".sprintf("%02d",$reg['jml']+1) ?>" readonly="rekening"/>
            

            <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-7" value="<?php echo date('Y-m-d');?>" 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" required="" class="form-control col-sm-7" 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" value="B" onKeyDown="changeFocus(event,'pbarang')" required="" /> <!-- checked -->
                        <label for="customRadio1" class="custom-control-label">Baru </label>
              </div>
              <div class="custom-control custom-radio col-sm-3">
                        <input class="custom-control-input " type="radio" id="customRadio2" name="jcair" value="P" onKeyDown="changeFocus(event,'pbarang')" required=""/>
                        <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"required="" class="form-control col-sm-7" onkeyup="this.value = this.value.toUpperCase()" onKeyDown="changeFocus(event,'customRadio3')"/>

          </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="customRadio3" name="jbarang" value="Elektronik" onKeyDown="changeFocus(event,'kelengkapan')" required=""/>
                        <label for="customRadio3" class="custom-control-label">Elektronik </label>
                      </div>
                      <div class="custom-control custom-radio col-sm-3">
                        <input class="custom-control-input " type="radio" id="customRadio4" name="jbarang" value="Kendaraan" onKeyDown="changeFocus(event,'kelengkapan')"required="" />
                        <label for="customRadio4" 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-7 select2" onKeyDown="changeFocus(event,'jaminan')"required="" >
                  <!--<option selected="selected">UNIT CHAS KOTAK</option>
                     -->
                  <option value="" >PILIH----</option>
                  <option value="UNIT KOTAK">UNIT KOTAK</option>
                  <option value="UNIT CHAS">UNIT CHAS</option>
                  <option value="UNIT CHAS KOTAK">UNIT CHAS KOTAK</option>
                  <option value="UNIT CHAS TAS">UNIT CHAS TAS</option>
                  <option value="UNIT KOTAK REMOT">UNIT KOTAK REMOT</option>
                  <option value="UNIT REMOT">UNIT REMOT</option>
                  <option value="UNIT BPKB STNK">UNIT BPKB STNK</option>
                  <option value="STNK KTP">STNK KTP</option>
                </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-7 select2" onKeyDown="changeFocus(event,'jwaktu')" required="">
                  <!-- <option selected="selected">TV</option> -->
                  <option value="">PILIH---</option>
                  <option value="TV">TV</option>
                  <option value="HP">HP</option>
                  <option value="LAPTOP">LAPTOP</option>
                  <option value="SPEKER AKTOR">SPEKER AKTOR</option>
                  <option value="DRON">DRON</option>
                  <option value="PROYEKTOR">PROYEKTOR</option>
                  <option value="SEPEDA YAMAHA">SEPEDA YAMAHA</option>
                  <option value="SEPEDA HONDA">SEPEDA HONDA</option>
                  <option value="SEPEDA SUZUKI">SEPEDA SUZUKI</option>
                  <option value="SEPEDA KAWASAKI">SEPEDA KAWASAKI</option>
                  <option value="MOBIL TOYOTA">MOBIL TOYOTA</option>
                  <option value="MOBIL DAIHATSU">MOBIL DAIHATSU</option>
                  <option value="MOBIL SUZUKI">MOBIL SUZUKI</option>
                  <option value="MOBIL MITSUBISHI">MOBIL MITSUBISHI</option>
                  
                </select>

          </div>

           </div>
      

        
          <?php 
                      $query1 = "SELECT * FROM registrasi where id='".$id."' ";
                      $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">Nilai Taksiran</label>
              <input type="text" name="taksasi" id="taksasi" class="form-control col-sm-7" onkeyup="validAngka(this)" onkeypress="return  hanyaAngka(event)" onKeyDown="changeFocus(event,'margin')" onfocus="use_number(this)" onblur="use_text(this)"/>    
            </div>

            <div class="form-group row">
              <label for="nama" class="col-sm-4">Jangka Waktu</label>
              <input type="text" name="jwaktu" id="jwaktu" class="form-control col-sm-7" value="45" readonly="jwaktu" 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">Biaya Titip</label>
              <div class="custom-control custom-radio col-sm-3 ">
                        <input type="radio" class="custom-control-input"  id="customRadio11" name="margin" value="5.00" onKeyDown="changeFocus(event,'noseri')" required="" /> <!-- checked -->
                        <label for="customRadio11" class="custom-control-label">5% </label>
              </div>
              <div class="custom-control custom-radio col-sm-3">
                        <input class="custom-control-input " type="radio" id="customRadio12" name="margin" value="7.50" onKeyDown="changeFocus(event,'noseri')" required=""/>
                        <label for="customRadio12" class="custom-control-label">7.5%</label>
               </div>
            </div>
                          
            <div class="form-group row">
              <label for="nama"  class="col-sm-4">SN/Plat</label>
              <input type="text" name="noseri" id="noseri" required="" class="form-control col-sm-7" 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" required="" class="form-control col-sm-7" onKeyDown="changeFocus(event,'keterangan')"/>    
            </div>

            <div class="form-group row">
              <label for="nama"  class="col-sm-4">Keterangan</label>
             <input type="text" value="Pencairan <?php echo $_POST['r_register'].".".sprintf("%02d",$reg['jml']+1)."[".$row['nama']."]";?>" name="keterangan" id="keterangan"required="" class="form-control col-sm-7" onKeyDown="changeFocus(event,'nama')"/>
              
            </div>

            <div class="form-group row">
              <label for="nama" class="col-sm-4">Nama</label>  
              <input type="text" class="form-control col-sm-7"required="" readonly="nama" value="<?php echo $row['nama']; ?>" onKeyDown="changeFocus(event,'simpanpencairan')"/>/>  
            </div>

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

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

      
    
    <!-- Kedua -->
       
 
        
            
         
            
          <!-- /.card-body -->
          <div class="card-footer bg-info">
            <input type="submit" 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-success">
              Tambah
            </a>
            <?php if($_SESSION['level']<1){ ?>
            <a href="home.php?home=<?php echo md5("edit_pencairan");?>" class="btn btn-warning">
              Edit
            </a>
            <a href="home.php?home=<?php echo md5("delet_pencairan");?>" class="btn btn-danger">
              Hapus
            </a>
          <?php } ?>
            <a class="btn btn-secondary" type="button" href="faktur/cetak_faktur_pinjaman.php" target="_bank">Print</a>
          </div>  
        </form>
      <?php } ?>
        

        </div>
      </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(){
  $("#simpanpencairan").click(function(){
    var data = $('#form-simpanpencairan').serialize();
    var rekening= $('#rekening').val();
    var tgl= $('#tgl').val();
    var plafond= $('#plafond').val();
    var jcair= $('#jcair').val();
    var pbarang= $('#pbarang').val();
    var jbarang= $('#jbarang').val();
    var kelengkapan= $('#kelengkapan').val();
    var jaminan= $('#jaminan').val();
    var taksasi= $('#taksasi').val();
    var jwaktu= $('#jwaktu').val();
    var margin= $('#margin').val();
    var noseri= $('#noseri').val();
    var kondisi= $('#kondisi').val();
    var keterangan= $('#keterangan').val();
    var nama= $('#nama').val();
    


    if(rekening== "0"|| tgl=="0" ||plafond=="0"||jcair=="0"||pbarang=="0"||jbarang=="0"||kelengkapan=="0"||jaminan=="0"||taksasi=="0"||jwaktu=="0"||margin=="0"||noseri=="0"||kondisi=="0"||keterangan=="0"||nama=="0"){ 
Swal.fire({
icon: 'error',
title: 'Hati-hati...',
text: 'Data masih ada yg belum diisi!',
footer: '<a href="">Anda Perlu teliti sedikit lagi?</a>'
});

    
  }else if(rekening== ""|| tgl=="" ||plafond==""||jcair==""||pbarang==""||jbarang==""||kelengkapan==""||jaminan==""||taksasi==""||jwaktu==""||margin==""||noseri==""||kondisi==""||keterangan==""||nama==""){ 

    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_pinjaman11.php',
      data: data,
      success: function(data) {
       console.log(data)

       Swal.fire({
title: 'Alhamdulillah...Data Sukses Tersimpan...!!!!',
text: 'Bisa Anda Cek...!!!',
imageUrl: 'img/logougt.png',
imageWidth: 75,
imageHeight: 80,
imageAlt: 'Custom image',
animation: false
})

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

$('#taksasi').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>

<script type="text/javascript">
function ClearFields() {
  /*https://stackoverflow.com/questions/14837466/clearing-a-text-field-on-button-click*/

   /*document.getElementById("tgl").value = "";
   document.getElementById("register").value = "";
   document.getElementById("plafond").value = "";*/
}
</script>



}



</head>
</html>