
<!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 -->
<?php
error_reporting(E_ALL^(E_NOTICE|E_WARNING));
ini_set('display_errors',1);
error_reporting(0);
?>
<!-- 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 ">PEMBAYARAN <?php if(isset($_POST['dataTable'])){echo strtoupper($_POST['dataTable']); }?> </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">

<style>
  .form-control {
    height: 30px; /* Atur tinggi sesuai kebutuhan */
    /*border-radius: 5px;*/ /* Atur border-radius untuk sudut yang lebih halus */
    /*border: 1px solid #007bff;*/ /* Warna border */
    border-radius: 5px; /* Melengkungkan sudut */
    border: 2px solid #ccc;
    border-radius: 3px;
    font-size: 13px;
    background-color: white;
    padding: 4px 10px;
    box-sizing: border-box; /* Menghitung padding dalam lebar elemen */
  }
  .btn {
    border-radius: 5px; /* Sesuaikan dengan tombol */
  }
  .custom-spacing {
    margin-bottom: 2px; /* Jarak antar input 2px */
    }
    label{

    font-family: 'Arial', sans-serif; /* Ganti dengan font yang Anda suka */
    font-size: 12px; /* Ukuran font */
    font-weight: bold; /* Gaya font */
    color: #333; /* Warna font */
    margin-bottom: 5px; /* Jarak antara label dan input */
    padding: 4px 10px;
    }

</style>

<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
include 'koneksi.php'; 
require './kalenderhijriah.php';
$kode         = $_SESSION['kode'];
if(isset($_POST['rekening1'])){   
            
$id = $_POST['rekening1'].".".sprintf("%06d",$_POST['rekening2']);

$id2 =$_POST['rekening'];
$dataTable =$_POST['dataTable'];

//$dataTable =$_POST['dataTable'];
$blnH = $calendar->monthName($hijri[0]);
$tglH = [
  "10" => $hijri[2]."-".$hijri[2]+1,
  "11" => $hijri[2]."-".$hijri[2]+1,
  "12" => $hijri[2]."-".$hijri[2]+1,
  "01" =>  ($hijri[2]-1)."-".$hijri[2],
  "02" => ($hijri[2]-1)."-".$hijri[2],
  "03" => ($hijri[2]-1)."-".$hijri[2],
  "04" => ($hijri[2]-1)."-".$hijri[2],
  "05" => ($hijri[2]-1)."-".$hijri[2],
  "06" => ($hijri[2]-1)."-".$hijri[2],
  "07" => ($hijri[2]-1)."-".$hijri[2],
  "08" => ($hijri[2]-1)."-".$hijri[2],
  "09" => ($hijri[2]-1)."-".$hijri[2], // Menambahkan bulan September yang hilang
];
$thnArab = $tglH[$blnH];

$query1 = "SELECT c.nim AS nim, c.nama AS nama,c.alamat AS alamat,a.id AS id,sum(a.kewajiban) AS kewajiban, sum(a.bayar) AS bayar,sum(a.bayar-a.kewajiban) AS sisa,tahun AS tahun,(SELECT no_kls 
     FROM kelas WHERE id = a.id ORDER BY tglmasehi DESC LIMIT 1) AS kls FROM $dataTable a LEFT JOIN registrasi c on c.id=a.id WHERE a.id='".$id."' GROUP BY a.id "; 
$hasil2 = mysqli_query($koneksi, $query1);
$reg = mysqli_fetch_assoc($hasil2); 

}
   



function Rp($angka) { 
$jadi = number_format($angka,0,'.',',');
return $jadi;
}

?>

<script type="text/javascript">
function hitungPaket2() {
var nilai_paket_1 = document.getElementById('pokok').value.replaceAll(",","");
var nilai_paket_2 = document.getElementById('margin').value.replaceAll(",","");
var jumlah = Number(nilai_paket_2) + Number(nilai_paket_1);
document.getElementById('jumlah').value = jumlah.toLocaleString();

}

</script>  

<form action="" method="POST">
<div class="row">
<div class="col-sm-6">
    <div class="form-group row custom-spacing">
    <label for="nama" class="col-sm-4">Bayar Kewajiban</label>
    <select id="dataTable" name="dataTable" class="form-control col-sm-8 select2" onkeydown="changeFocus(event,'jaminan')" required>
    <option value="">PILIH----</option>
    <option value="seragam">Seragam</option>
    <option value="kitab">Kitab</option>
    <option value="imda1">Imda-I</option>
    <option value="imda2">Imda-II</option>
    <option value="imda3">Imda-III</option>
    <option value="iuran">Iuran Maulid</option>
    <option value="alquran">Al Quran</option>
    <option value="imni">Imni</option>
    <option value="ikhtibar">Iktibar</option>
</select>


<!-- <p id="selectedValue"></p>
 <select id="dataTable" name="dataTable" class="form-control col-sm-8 select2" onkeydown="changeFocus(event,'jaminan')" required onchange="showSelectedValue()">
<script>
function showSelectedValue() {
    var select = document.getElementById("dataTable");
    var selectedOption = select.options[select.selectedIndex].text;
    document.getElementById("selectedValue").innerText = "Anda memilih: " + selectedOption;
}
</script> -->

</div>
<style>
.custom-input1 {
  width: 50px;
  margin-right: 10px;
}
.custom-input2 {
  width: 210px;
  margin-right: 10px;
}
</style>        

<div class="form-group row ">
<label for="nama" class=" col-sm-4">No ID </label>

<!-- Tiga input rekening bersampingan -->
<input type="text" name="rekening1" id="rekening1" class="form-control custom-input1" placeholder="Rekening 1" value="<?php echo $kode; ?>" onKeyDown="changeFocus(event,'rekening2')" readonly/>
<input type="text" name="rekening2" id="rekening2"required="" class="form-control custom-input2" value="<?php if(isset($_POST['rekening2'])){echo sprintf("%06d",$_POST['rekening2']); }?>"  onKeyDown="changeFocus(event,'cariid')"/> 
  
<button type="submit" id="cariid" name="cariid" class="  btn btn-info"  ><i class="fas fa-search"></i></button>
</div>
</form>

<script>
function changeFocus(event, nextFieldId) {
    if (event.key === 'Enter') {
        event.preventDefault(); // Mencegah pengiriman form saat Enter ditekan
        const nextField = document.getElementById(nextFieldId);
        if (nextField) {
            nextField.focus(); // Pindah fokus ke field berikutnya
        }
    }
}
</script>

<form action=".../../simpan/simpan_bayar_nonSyahriah_murid.php" method="POST"  class="form-simpanangsuran" id="form-simpanangsuran">


<div class="form-group row custom-spacing">
<label for="nama" class="col-sm-4">Tanggal</label>
<input type="text" name="tgl" id="tgl" class="tgl form-control col-sm-8" value="<?php  echo sprintf('%02d', $hijri[1]) . '-' . $calendar->monthName($hijri[0]) . '-' . $hijri[2]; ; ?>" max="<?= date('Y-m-d') ?>" onKeyDown="changeFocus(event,'kewajiban')" autofocus />
<input type="hidden" name="thnArab" id="thnArab" class="tgl form-control col-sm-8" value="<?php  echo $thnArab; ?>"  />
</div>



<input type="hidden" name="idM" id="idM"  class="form-control col-sm-7" value="<?php echo  $id;?>"/>
<input type="hidden" name="dataTable" id="dataTable" class="form-control col-sm-8"onkeyup="hitungPaket2()" value="<?php echo $_POST['dataTable'];?>" /> 
<input type="hidden"name="kelas" id="kelas"  value="<?php echo $reg['kls'] ;?>"/>
<input type="hidden"name="tahun" id="tahun"  value="<?php echo $reg['tahun'] ;?>"/>

<div class="form-group row custom-spacing">
<label for="nama" class="col-sm-4">Nominal</label>
<input type="text" name="bayar" id="bayar" class="form-control col-sm-8"onkeyup="hitungPaket2()" placeholder=" Ketik Pembayaran disini...!" onKeyDown="changeFocus(event,'keterangan')" required/>

</div>             


<div class="form-group row custom-spacing">
<label for="nama" class="col-sm-4">Keterangan</label>
<input type="text" name="keterangan" id="keterangan" class="form-control col-sm-8" required="" value="<?php echo "Bayar";?>"  onKeyDown="changeFocus(event,'simpanansyahriah')"/>
<input type="hidden" name="keterangan2" value="<?php echo $reg['rekening'] . "[" . $reg['nama'] . "]"; ?>"/>
</div>

</div>


<div class="col-sm-6">
<div class="form-group row custom-spacing"> 
<label for="nama" class="col-sm-3" style="margin-left: 12px;">Kwajiban</label> 
<input type="text"name="kewajiban" id="kewajiban" class="form-control col-sm-8" readonly="Kewajiban" value="<?php echo number_format($reg['kewajiban'],0); ?>" />
</div> 
<input type="hidden" name="nim" id="nim"  class="form-control col-sm-7" value="<?php echo  $reg['nim'];?>"/>
<div class="form-group row custom-spacing"> 
<label for="nama" class="col-sm-3"style="margin-left: 12px;">Terbayar</label> 
<input type="text"name="bayarpokok" id="bayarpokok" class="form-control col-sm-8" readonly="bayarpokok" value="<?php echo Rp($reg['bayar']);?>"/>
</div>

<div class="form-group row custom-spacing"> 
<label for="nama" class="col-sm-3"style="margin-left: 12px;">Sisa</label> 
<input type="text"name="sisa" id="sisa" class="form-control col-sm-8" readonly="sisa" value="<?php echo Rp($reg['sisa']);?>"/>
</div>

<div class="form-group row custom-spacing"> 
<label for="nama" class="col-sm-3"style="margin-left: 12px;">Nama</label> 
<input type="text"name="nama" id="nama" class="form-control col-sm-8" readonly="plafond" value="<?php echo $reg['nama']." [Kls-".$reg['kls']."]" ;?>"/>
</div>
<div class="form-group row custom-spacing"> 
<label for="nama" class="col-sm-3"style="margin-left: 12px;">Alamat</label> 
<input type="text"name="alamat" id="alamat" class="form-control col-sm-8" readonly="plafond" value="<?php echo $reg['alamat'];?>"/>
</div>
 

<!-- /.card-body -->
<div class="card-footer ">
<input type="submit" name="simpanansyahriah" id="simpanansyahriah" 
class="btn btn-primary"  value="Simpan" onclick='document.geElementById("myform").submit()'>
<a href="home.php?home=<?php echo md5("pembayar_murid");?>" id="tambah" class="btn btn-success">
Tambah
</a>
<?php if($_SESSION['level']<1){ ?>
<a href="home.php?home=<?php echo md5("edit_tagihansyahriah");?>" class="btn btn-warning">
Edit
</a>
<a href="home.php?home=<?php echo md5("delete_tagihansyahriah");?>" class="btn btn-danger">
Hapus
</a>
<?php } ?>
<a class="btn btn-secondary" type="button" href="pdf/cetak_validasi_angsuran_pdf.php?rekening=<?php echo $_POST['rekening'];?>" target="_bank">Print
</a>
<a href="home.php?home=<?php echo md5("cetakangsuran");?>" class="btn btn-secondary">
Cetak
</a>
</div>
</div>

</form>

</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">
// 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
$('#bayar').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>