<?= $this->extend('layout/template') ?>

<?= $this->section('content') ?>


<div class="card shadow">


<div class="card-header bg-success">

<h3 class="card-title text-white">

<i class="fas fa-book-reader"></i>

Pengembalian Buku

</h3>


</div>



<div class="card-body">



<?php if(session()->getFlashdata('success')): ?>

<div class="alert alert-success alert-dismissible fade show">

<i class="fas fa-check-circle"></i>

<?= session()->getFlashdata('success') ?>

</div>

<?php endif; ?>





<?php if(session()->getFlashdata('error')): ?>

<div class="alert alert-danger">

<i class="fas fa-exclamation-triangle"></i>

<?= session()->getFlashdata('error') ?>

</div>

<?php endif; ?>






<!-- ===========================
     PEMINJAMAN AKTIF
=========================== -->


<div class="card border-warning">


<div class="card-header bg-warning">

<h5 class="mb-0">

<i class="fas fa-clock"></i>

Buku Belum Dikembalikan

</h5>

</div>



<div class="card-body">



<div class="table-responsive">


<table class="table table-bordered table-hover"
id="tblKembali">


<thead class="bg-light">


<tr>

<th width="50">
No
</th>

<th>
Kode Pinjam
</th>

<th>
Nama Anggota
</th>

<th>
Jumlah Buku
</th>

<th>
Batas Kembali
</th>

<th>
Estimasi Denda
</th>

<th width="120">
Aksi
</th>


</tr>


</thead>





<tbody>


<?php $no=1; ?>


<?php foreach($pinjam as $p): ?>


<tr>


<td class="text-center">

<?= $no++ ?>

</td>




<td>

<span class="badge badge-primary">

<i class="fas fa-barcode"></i>

<?= $p['kode_pinjam'] ?>

</span>


</td>





<td>


<i class="fas fa-user text-primary"></i>

<?= $p['nama'] ?>


</td>





<td class="text-center">


<span class="badge badge-info">

<i class="fas fa-book"></i>

<?= $p['jumlah_buku'] ?> Buku

</span>


</td>





<td>


<i class="far fa-calendar-alt"></i>

<?= date(
'd-m-Y',
strtotime($p['tanggal_kembali'])
) ?>


</td>





<td class="text-center">


<?php if($p['estimasi_denda'] > 0): ?>


<span class="badge badge-danger">

Rp <?= number_format($p['estimasi_denda'],0,',','.') ?>

</span>


<small class="d-block text-danger">

(<?= $p['hari_terlambat'] ?> hari)

</small>


<?php else: ?>


<span class="badge badge-success">

Tidak ada denda

</span>


<?php endif; ?>


</td>





<td class="text-center">


<button class="btn btn-success btn-sm"
data-toggle="modal"
data-target="#kembali<?= $p['kode_pinjam'] ?>">


<i class="fas fa-undo"></i>

Kembali


</button>


</td>



</tr>









<!-- MODAL -->


<div class="modal fade"
id="kembali<?= $p['kode_pinjam'] ?>">


<div class="modal-dialog">


<div class="modal-content">



<form action="<?= base_url('pengembalian/store') ?>"
method="post">


<?= csrf_field(); ?>




<div class="modal-header bg-success">


<h5 class="modal-title text-white">

<i class="fas fa-undo"></i>

Form Pengembalian

</h5>



<button type="button"
class="close text-white"
data-dismiss="modal">

&times;

</button>


</div>






<div class="modal-body">



<input type="hidden"
name="kode_pinjam"
value="<?= $p['kode_pinjam'] ?>">





<div class="form-group">

<label>

Kode Pinjam

</label>

<input type="text"
class="form-control"
value="<?= $p['kode_pinjam'] ?>"
readonly>

</div>





<div class="form-group">

<label>

Nama Anggota

</label>


<input type="text"
class="form-control"
value="<?= $p['nama'] ?>"
readonly>


</div>





<div class="form-group">

<label>

Jumlah Buku

</label>


<input type="text"
class="form-control"
value="<?= $p['jumlah_buku'] ?> Buku"
readonly>


</div>





<div class="form-group">

<label>

Tanggal Pengembalian

</label>


<input type="date"
name="tanggal_kembali_real"
class="form-control"
value="<?= date('Y-m-d') ?>"
required>


</div>






<div class="form-group">


<label>

Denda Per Hari

</label>


<div class="input-group">


<div class="input-group-prepend">

<span class="input-group-text">

Rp

</span>

</div>


<input type="number"
name="tarif_denda"
class="form-control"
value="1000">


</div>


<small class="text-muted">

Jika melewati batas kembali maka denda dihitung otomatis.

</small>


</div>






</div>







<div class="modal-footer">


<button class="btn btn-success">

<i class="fas fa-save"></i>

Simpan

</button>


<button type="button"
class="btn btn-secondary"
data-dismiss="modal">

Tutup

</button>


</div>




</form>


</div>


</div>


</div>



<?php endforeach; ?>



</tbody>


</table>


</div>


</div>


</div>









<hr>










<!-- ===========================
     RIWAYAT
=========================== -->


<div class="card border-success">


<div class="card-header bg-success text-white">


<h5 class="mb-0">

<i class="fas fa-history"></i>

Riwayat Pengembalian

</h5>


</div>




<div class="card-body">



<div class="table-responsive">


<table class="table table-striped table-bordered">


<thead class="bg-light">


<tr>

<th>No</th>

<th>Kode</th>

<th>Nama</th>

<th>Tanggal</th>

<th>Terlambat</th>

<th>Denda</th>

<th>Status</th>

<th>Struk</th>


</tr>


</thead>






<tbody>



<?php $no=1; ?>


<?php foreach($riwayat as $r): ?>


<tr>


<td>

<?= $no++ ?>

</td>




<td>

<span class="badge badge-primary">

<?= $r['kode_pinjam'] ?>

</span>


</td>





<td>

<i class="fas fa-user"></i>

<?= $r['nama'] ?>

</td>






<td>

<?= date(
'd-m-Y',
strtotime($r['tanggal_kembali_real'])
) ?>


</td>





<td class="text-center">


<?php if($r['hari_terlambat']>0): ?>


<span class="badge badge-danger">

<?= $r['hari_terlambat'] ?> Hari

</span>


<?php else: ?>


<span class="badge badge-success">

Tepat Waktu

</span>


<?php endif; ?>


</td>







<td>


<span class="text-danger font-weight-bold">


Rp <?= number_format(
$r['denda'],
0,
',',
'.'
) ?>


</span>


</td>






<td>


<?php if($r['status_bayar']=="Belum Bayar"): ?>


<span class="badge badge-danger">

Belum Bayar

</span>


<?php else: ?>


<span class="badge badge-success">

Sudah Bayar

</span>


<?php endif; ?>


</td>







<td>


                    <a href="<?= base_url('laporan/struk/'.$r['anggota_id']) ?>"
target="_blank"
class="btn btn-primary btn-sm">


<i class="fas fa-print"></i>

Struk


</a>


</td>



</tr>


<?php endforeach; ?>



</tbody>



</table>


</div>



</div>


</div>



</div>


</div>







<script>


$(document).ready(function(){


$('#tblKembali').DataTable({

responsive:true,

language:{


search:"Cari:",

lengthMenu:"Tampilkan _MENU_ data",

info:"Menampilkan _START_ sampai _END_ dari _TOTAL_ data"


}


});


});


</script>




<?= $this->endSection() ?>