 <div class='row'>
        <div class='col-md-12'>
           <div class="card">
             <div class="card-header">	
               <h5 class="card-title"><i class="fas fa-th"></i> Managemen Peminjam Buku</h4>
			   </div>    
			  
			  
				 <div class='card-body'>
            <div class='table-responsive'>
                        <table style="font-size: 12px" id='example1' class='table table-hover'>
                            <thead >
                                <tr>
                                    <th width='3px' height="40px">No</th>
									  <th width="10%">Tgl Pinjam</th>
                                    <th>Judul Buku</th> 
                                      <th>Nama Siswa</th> 
                                      <th>Kelas</th> 										  
                                       <th width="5%">Jml</th>
                                       <th width="10%">Lama Pinjam</th>  
                                        <th width="10%">Tgl Kembali</th>									   
									<th width="5%">Action</th>
										</tr>
									</thead>							
							<tbody>							
                                <?php
								$no = 0;
								
								 $query = mysqli_query($koneksi, "select * from buku_pinjam WHERE status='1'");
                            while ($tjn = mysqli_fetch_array($query)) {
							$buku = fetch($koneksi,'buku',['id_buku'=>$tjn['idbuku']]);
							$siswa = fetch($koneksi,'siswa',['id_siswa'=>$tjn['idsiswa']]);
								 $tp=date('d',strtotime($tjn['tgl_pinjam']));
								 $tk = date('d');
								$lamapinjam = $tk-$tp;
                                $no++;
                            ?>
							 <tr>
                                    <td><?= $no; ?></td>
							        <td><?= $tjn['tgl_pinjam'] ?></td>
									<td ><?= $buku['judul'] ?></td>
									<td><?= $siswa['nama'] ?></td>
									<td><?= $tjn['kelas'] ?></td>
									<td><?= $tjn['jumlah'] ?></td>
									<td><?= $lamapinjam ?> &nbsp;&nbsp;hari</td>
									<td>
									<?php if($tjn['tgl_kembali']<>''){ ?>
									<?= $tjn['tgl_kembali'] ?>
									<?php }else{ ?>
									<b style="color:red">BELUM KEMBALI</b>
									<?php } ?>
									</td>
									<td>
									 <button data-id="<?= $tjn['id_pinjam'] ?>" class="hapus btn-sm btn btn-danger"><i class="fas fa-arrow-right"></i></button>
									</td>
									</tr>
                            <?php } ?>
                        </tbody>
                        </table>
		 </div>
		 </div>   </div>
        </div>
    </div>
	<script>
	$('#example1').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Are you sure?',
            text: 'Akan Mengembalikan Buku ini!',
			type:'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, Kembali'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_perpus/crud.php?pg=kembali',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                       iziToast.info(
									{
						title: 'Sukses!',
						message: 'Data berhasil mengembalikan',
						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>
		 </div>
		

