
<?php
function getRomawi($bln){
                switch ($bln){
                    case 1: 
                        return "I";
                        break;
                    case 2:
                        return "II";
                        break;
                    case 3:
                        return "III";
                        break;
                    case 4:
                        return "IV";
                        break;
                    case 5:
                        return "V";
                        break;
                    case 6:
                        return "VI";
                        break;
                    case 7:
                        return "VII";
                        break;
                    case 8:
                        return "VIII";
                        break;
                    case 9:
                        return "IX";
                        break;
                    case 10:
                        return "X";
                        break;
                    case 11:
                        return "XI";
                        break;
                    case 12:
                        return "XII";
                        break;
                }
}
$bulan = date('n');
$romawi = getRomawi($bulan);
$tahun = date ('YmdHis');
$nomor = "-".$romawi."-".$tahun;
$blnQ=date('m');
$query = "SELECT max(idt) as maxKode FROM trx";
$hasil = mysqli_query($koneksi,$query);
$data  = mysqli_fetch_array($hasil);
$no= $data['maxKode'];
$noUrut= $no + 1;

$kode =  sprintf("%06s", $noUrut);
$nomorbaru = "0483-3-TRX-".$kode.$nomor;
$bulane=fetch($koneksi,'bulan',['bln'=>$blnQ]);
?>

<div class='row'>
       <div class='col-md-12'>
            <div class="card">
             <div class="card-header">									
                
                    <div class='right'>
				      <a class="btn btn-sm btn-success"  href="?pg=datatrx" ><i class="fas fa-search"></i> Data Trx</a>&nbsp; 
		             </div>
					  <h5 class="card-title"><i class="fas fa-graduation-cap"></i> Pembayaran</h5>
                </div>
			
			  
           <div class='card-body'>
				<form id="formtujuan" class="form-horizontal"  action="" >
					 <div class="row mb-2">
						<label  class="col-md-3 col-form-label bold">Tanggal</label>
							<div class="col-sm-5">
								<input type="text"  class="form-control" value="<?= date('Y-m-d') ?>" readonly>
							</div>
						</div>
							<div class="row mb-2">
						<label  class="col-md-3 col-form-label bold">No Reff</label>
							<div class="col-sm-5">
								<input type="text"  class="form-control" name="bukti" value="<?= $nomorbaru ?>" readonly>
							</div>
						</div>
						<div class="row mb-2">
						<label  class="col-md-3 col-form-label bold">Id Siswa</label>
							<div class="col-sm-9">
								<div class="input-group">
									<input type="text" class="form-control" id="idsiswa" name="idsiswa"  readonly>
									<span class="input-group-btn">
									  <button type="button" class="btn btn-danger btn-flat" data-bs-toggle="modal" data-bs-target="#modal">Browse</button>
									</span>
								</div>
							</div>
						</div>
							<div class="row mb-2">
						<label  class="col-md-3 col-form-label bold">Nama Siswa</label>
							<div class="col-sm-9">
								<input type="text" id="nama" name="nama" class="form-control" readonly >
							</div>
						</div>
						<div class="row mb-2">
						<label  class="col-md-3 col-form-label bold">Kelas</label>
							<div class="col-sm-5">
								<input type="text" id="kelas" name="kelas" class="form-control"  readonly>
							</div>
						</div>
							<div class="row mb-2">
						<label  class="col-md-3 col-form-label bold">Kode Pembayaran</label>
							<div class="col-sm-9">								
									 <select name='kode' class='form-select'  onchange='changeValue(this.value)' style='width:100%' required>
                                                <option value=''>Pilih Kode Pembayaran</option>
                                               
												 <?php 
												 $query=mysqli_query($koneksi, "select * from m_bayar"); 
												 $result = mysqli_query($koneksi, "select * from m_bayar");  
												 $jsArray = "var prdName = new Array();\n";
												 while ($row = mysqli_fetch_array($result)) {  
												 echo '<option name="nim"  value="' . $row['kode'] . '">' . $row['kode'] . '</option>';  
												 $jsArray .= "prdName['" . $row['kode'] . "'] = {namabayar:'" . addslashes($row['nama_pembayaran']) . "',besar:'".$row['besar']."'};\n";
												  }
												  ?>
												</select>
                                           
							</div>
						</div>
							<div class="row mb-2">
						<label  class="col-md-3 col-form-label bold">Nama Pembayaran</label>
							<div class="col-sm-9">
								<input type="text" id="namabayar" name="namabayar" id="namabayar" class="form-control"  readonly>
							</div>
						</div>
							<div class="row mb-2">
						<label  class="col-md-3 col-form-label bold">Besar Pembayaran</label>
							<div class="col-sm-9">
								<input type="text" id="besar" name="besar" class="form-control"  onkeyup="convertToRupiah(this);" readonly>
							</div>
						</div>
							<div class="row mb-2">
						<label  class="col-md-3 col-form-label bold">Untuk Bulan</label>
							<div class="col-sm-9">
								 <select name='untuk' class='form-select' style='width:100%' required>
                                                <option value='<?= $blnQ ?>'><?= $bulane['ket'] ?></option>
												<option value=''></option>
                                                <?php $que = mysqli_query($koneksi, "SELECT * FROM bulan"); ?>
                                                <?php while ($bq = mysqli_fetch_array($que)) : ?>

                                                    <option value="<?= $bq['bln'] ?>"><?= $bq['ket'] ?></option>

                                                <?php endwhile ?>
                                            </select>
							</div>
						</div>
						
					<div class="right">
						<button type="submit"  class="btn btn-primary"><i class="fas fa-check-circle"></i> Simpan</button>
						</div>
				</form>
				</div>
					</div>
						</div>
						   </div>
				<script>
       $('#formtujuan').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'sandik_bayar/crud_bayar.php?pg=bayar',
            data: $(this).serialize(),
            success: function(data) {
                if (data == 'OK') {
                    iziToast.info(
				{
				title: 'Sukses!',
				message: 'Data berhasil disimpan',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
				 position: 'topRight'					  
				});
                    setTimeout(function() {
                        window.location.replace('?pg=cetaktrx');
                    }, 2000);
                    
                } else {
                    iziToast.info(
				{
				title: 'GAGAL!',
				message: 'Data sudah ada',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
				 position: 'topRight'					  
				});
					setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }

            }
        });
        return false;
    });

    </script>

	<div class="modal fade" id="modal" tabindex="-1" aria-labelledby="modal" aria-hidden="true">
   <div class="modal-dialog modal-lg">
       <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="tambahjadwal">Pilih Siswa</h5>
               <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                      <div class="modal-body">
				<form role="form" id="form-tambah" method="post" action="input.php">
						<div class='table-responsive'>
							<table class="table table-hover"  id="datatable1">
                                <thead>
                                    <tr>
                                        <th width="5%">No</th>
                                        <th>Nama Siswa</th>
                                        <th width="15%">Kelas</th>
                                       
                                    </tr>
                                </thead>
                                <tbody>
										<?php
											$no = 1;
											$data = mysqli_query ($koneksi, " select  * FROM siswa ORDER BY id_siswa ASC");
											while ($row = mysqli_fetch_array ($data))
											{
										?>
									<tr id="siswa" data-idsiswa="<?php echo $row['id_siswa']; ?>" data-nama="<?php echo $row['nama']; ?>" data-kelas="<?php echo $row['id_kelas']; ?>" >
										<td>
											<?php echo $no++; ?>
										</td>
										
										<td>
											<?php echo $row['nama']; ?>
										</td>
										<td>
											<?php echo $row['id_kelas']; ?>
										</td>
										
									</tr>
									<?php
										}
									?>
                            </table>
						
						
					</div>	
					
					<div class="modal-footer">
						<button type="button" class="btn btn-outline-danger" data-bs-dismiss="modal">Batal</button>
					</div>
			</div>
		</div>
	</div>
	
 <script>
			$('#datatable1').DataTable();
            $(document).ready(function(){setTimeout(function(){$("#pesan").fadeIn('slow');}, 500);});
            setTimeout(function(){$("#pesan").fadeOut('slow');}, 3000);
        </script>
	
	
		<script type="text/javascript">
		$(document).ready(function(){
			
			$(document).on('click', '#siswa', function (e) {
				document.getElementById("idsiswa").value = $(this).attr('data-idsiswa');
				document.getElementById("nama").value = $(this).attr('data-nama');
				document.getElementById("kelas").value = $(this).attr('data-kelas');

				$('#modal').modal('hide');
			});	
			
		});
		</script>	
	
	<script type="text/javascript"> 
<?php echo $jsArray; ?>
function changeValue(id){
    document.getElementById('namabayar').value = prdName[id].namabayar;
    document.getElementById('besar').value = prdName[id].besar;
   
};
</script>
 


 
