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

<div class="container-fluid">

    <div class="card card-primary">

        <div class="card-header">

            <h3 class="card-title">
                <i class="fas fa-user-graduate"></i>
                Detail Laporan Siswa
            </h3>

            <div class="card-tools">

                <a href="<?= base_url('laporan') ?>"
                    class="btn btn-danger btn-sm">

                    <i class="fas fa-arrow-left"></i>

                    Kembali

                </a>

            </div>

        </div>

        <div class="card-body">

            <?php

            if(empty($detail)) :

            ?>

                <div class="alert alert-warning">

                    Data belum tersedia.

                </div>

            <?php

            else :

            ?>

            <div class="row">

                <div class="col-md-6">

                    <table class="table table-bordered">

                        <tr>

                            <th width="200">Nama</th>

                            <td><?= $detail[0]['nama'] ?? '-' ?></td>

                        </tr>

                        <tr>

                            <th>NIS</th>

<td><?= $detail[0]['nisn'] ?? '-' ?></td>

                        </tr>

                        <tr>

                            <th>Kelas</th>

                            <td><?= $detail[0]['kelas'] ?? '-' ?></td>

                        </tr>

                    </table>

                </div>

                <div class="col-md-6">

                    <table class="table table-bordered">

                        <tr>

                            <th>Total Denda</th>

                            <td>

                                <strong class="text-danger">

                                    Rp <?= number_format($totalDenda,0,',','.') ?>

                                </strong>

                            </td>

                        </tr>

                        <tr>

                            <th>Total Buku</th>

                            <td><?= count($detail) ?></td>

                        </tr>

                    </table>

                </div>

            </div>

            <hr>

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

                <thead>

                    <tr>

                        <th>No</th>

                        <th>Kode Buku</th>

                        <th>Judul Buku</th>

                        <th>Tanggal Pinjam</th>

                        <th>Batas Kembali</th>

                        <th>Tanggal Kembali</th>

                        <th>Status</th>

                        <th>Terlambat</th>

                        <th>Denda</th>

                    </tr>

                </thead>

                <tbody>

                <?php

                $no=1;

                foreach($detail as $d):

                ?>

                    <tr>

                        <td><?= $no++ ?></td>

                        <td><?= $d['kode_buku'] ?></td>

                        <td><?= $d['judul'] ?></td>

                        <td><?= date('d-m-Y',strtotime($d['tanggal_pinjam'])) ?></td>

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

                        <td>

                            <?php

                            if($d['tanggal_dikembalikan']==NULL){

                                echo "<span class='badge badge-warning'>Belum Kembali</span>";

                            }else{

                                echo date('d-m-Y',strtotime($d['tanggal_dikembalikan']));

                            }

                            ?>

                        </td>

                        <td>

                            <?php

                            if($d['status']=="Dipinjam"){

                                ?>

                                <span class="badge badge-danger">

                                    Dipinjam

                                </span>

                                <?php

                            }else{

                                ?>

                                <span class="badge badge-success">

                                    Dikembalikan

                                </span>

                                <?php

                            }

                            ?>

                        </td>

                        <td>

                            <?php

                            if($d['hari_terlambat']>0){

                                ?>

                                <span class="badge badge-danger">

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

                                </span>

                                <?php

                            }else{

                                ?>

                                <span class="badge badge-success">

                                    Tepat Waktu

                                </span>

                                <?php

                            }

                            ?>

                        </td>

                        <td>

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

                        </td>

                    </tr>

                <?php endforeach; ?>

                </tbody>

                <tfoot>

                    <tr>

                        <th colspan="8" class="text-right">

                            TOTAL DENDA

                        </th>

                        <th>

                            Rp <?= number_format($totalDenda,0,',','.') ?>

                        </th>

                    </tr>

                </tfoot>

            </table>

            <div class="mt-3">

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

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

                    Cetak Struk Denda

                </a>

            </div>

            <?php endif; ?>

        </div>

    </div>

</div>

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