
  <div class='row'>
  
         <div class='col-md-12'>
             <div class="card">
             <div class="card-header">									
                  
                    <div class='right'>
				      <button class='btn btn-outline-primary' data-bs-toggle="modal" data-bs-target="#tambahsiswa"><i class="fa fa-plus-circle" data-bs-toggle="tooltip" data-bs-placement="top" title="Tambah Master"></i>Master</button>
		        </div>
					<h5 class="card-title"><i class="fas fa-graduation-cap"></i> Master Pembayaran</h5>
                </div>
			
           <div class='card-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table table-hover'>
                            <thead>
                            <tr>
                                <tr>
                                    <th width='5%'></th>
                                    <th width='15%'>Kode</th>
                                    <th>Nama Pembayaran</th>
									<th width='15%'>Total Pembayaran</th>
									<th width='15%'>Mode Pembayaran</th>
									<th width='5%'>Jml Bayar (X)</th>
                                    <th width='15%'>Besar Pembayaran</th>								
                                   <th width='5%'>Action</th>
								  
                            </tr>
                        </thead>
                        <tbody>
                            <?php
							include"fungsi.php";
                            $query = mysqli_query($koneksi, "select * from m_bayar ");
                            $no = 0;
                            while ($bayar = mysqli_fetch_array($query)) {
						
                                $no++;
                              
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $bayar['kode'] ?></td>
									 <td><?= $bayar['nama_pembayaran'] ?></td>
									 <td>Rp <?= format_rupiah($bayar['total_bayar']) ?></td>
									 <td><?= $bayar['mode'] ?></td>
									 <td><?= $bayar['banyak_angsur'] ?> X</td>
                                    <td>Rp <?= format_rupiah($bayar['besar']) ?></td>
                                    <td>                                        
                                       <button type="button" class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#modaledit<?= $bayar['idb'] ?>">
                                                    <i class="fas fa-edit    "></i>
                                                </button>
                                    </td>
									</tr>
									 <div class="modal fade" id="modaledit<?= $bayar['idb'] ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
                                        <div class="modal-dialog modal-md" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">

                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                        <span aria-hidden="true">&times;</span>
                                                    </button>
                                                </div>
                                               <form method="post" action="" enctype="multipart/form-data">
                                                    <div class="modal-body">
                                                        <input type="hidden" value="<?= $bayar['idb'] ?>" name='idb'>
														 
														<div class='form-group-sm'>
														<label>Kode</label>
														<input type="text" class="form-control" name="kode" value="<?= $bayar['kode'] ?>"  autocomplete="off" required>
															</div>
														<div class='form-group-sm'>
														<label>Nama Pembayaran</label>
														<input type="text" class="form-control"  name="nama_bayar" value="<?= $bayar['nama_pembayaran'] ?>" autocomplete="off" required>
															</div>	
														<div class='form-group-sm'>
														<label>Total Pembayaran</label>
														<input type="text" class="form-control" name="total" value="<?= format_rupiah($bayar['total_bayar']) ?>" onkeyup="convertToRupiah(this);" required>
															</div>	
										               <div class='form-group-sm'>
                                            
                                                    <label>Model Pembayaran</label>
                                                      <select name='mode' class='form-control' style='width:100%' required>
												<option value="<?= $bayar['mode'] ?>"><?= $bayar['mode'] ?></option>
												 <option value=''></option>
                                               <option value='Bulan'>Bulan</option>
											    <option value='Tahun'>Tahun</option>
                                            </select>
                                                </div>
												<div class='form-group-sm'>
                                            
                                                    <label>Jumlah Angsuran X</label>
                                                      <input type="number" id="banyak" name="banyak" value="<?= $bayar['banyak_angsur'] ?>" class="form-control"  required>
                                                </div>    
														</div>	
														 <div class='modal-footer'>
														<div class='box-tools pull-right btn-group'>
														<br>
													<button type='submit' name='submit' class='btn btn-sm btn-success'><i class='fa fa-save'></i> Simpan</button>
														
																</div>
															</div>
		                                    
		                                       </form>
						</div>
                                        </div>
                                    </div>
							<?php } ?>
                    </table>
                </div>
            </div>
			</form>
        </div>
    </div>
   </div>
    </div>
 <?php
				
				 if (isset($_POST['submit'])) {
				$idb = $_POST['idb'];
				$kode = $_POST['kode'];
				$mode = $_POST['mode'];
				$nama_bayar = $_POST['nama_bayar'];
				$total = reset_rupiah($_POST['total']);
				$banyak = $_POST['banyak'];
	             $besar=$total/$banyak;
mysqli_query($koneksi,"UPDATE m_bayar SET kode='$kode', nama_pembayaran='$nama_bayar', total_bayar='$total', mode='$mode', besar='$besar', banyak_angsur='$banyak' WHERE idb='$idb' ");
if($koneksi){
echo"
	  <script type='text/javascript'>
		setTimeout(function () { 	
			swal({
				title: 'Sukses !!!',
				text:  'Data Berhasil disimpan',
				type: 'success',
				timer: 2000,
				showConfirmButton: true
			});		
		},10);	
		window.setTimeout(function(){ 
			window.location.replace('?pg=master_bayar');
		} ,2000);	
	  </script>";
	  
                }
            }
				
            ?>

 
 
   <div class="modal fade" id="tambahsiswa" tabindex="-1" aria-labelledby="tambahsiswa" aria-hidden="true">
   <div class="modal-dialog">
       <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="tambahsiswa">Tambah Master</h5>
               <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                      <div class="modal-body">
                                    <form id='form-tambah' action=''>
                                        
                                        <div class="form-group">
                                               <label class="bold">Kode</label>
                                            <input type='text' name='kode'  class='form-control' autocomplete="off" required />
                                        </div>
										 <div class='form-group'>
                                                    <label class="bold">Nama Pembayaran</label>
                                                    <input type="text"  name="nama" class="form-control" autocomplete="off" required>
                                                </div>
												<div class='form-group'>
                                                    <label class="bold">Total Pembayaran</label>
                                                      <input type="text" id="total" name="total" class="form-control" onkeyup="convertToRupiah(this);" required>
                                                </div>
                                            
										<div class='form-group'>                                         
                                                    <label class="bold">Model Pembayaran</label>
                                                      <select name='mode' class='form-control' style='width:100%' required>
												<option value=''></option>
												
                                               <option value='Bulan'>Bulan</option>
											    <option value='Tahun'>Tahun</option>
                                            </select>
                                                </div>
									
										<div class='form-group'>
                                            
                                                    <label class="bold">Jumlah Angsuran (X)</label>
                                                      <input type="number" id="banyak" name="banyak" class="form-control"  required>
                                                </div>                                                
	                                            <p>
                                            <div class='right'>
											 <button type='submit' class='btn btn-sm btn-success'><i class='fa fa-check-circle'></i> Simpan</button>
                                              
                                            </div>
                                      
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	
	<script>
	$('#form-tambah').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
        $.ajax({
            type: 'POST',
            url: 'sandik_bayar/crud_bayar.php?pg=tambah',
           enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
                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.reload();
                }, 2000);

            }
        });
        return false;
    });
	</script>