

<?php $__env->startSection('title', 'Laporan Peminjaman Aktif'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title mb-0">Laporan Peminjaman Aktif</h4>
                </div>
                <div class="card-body">
                    
                    <form action="<?php echo e(route('admin.laporan.peminjaman')); ?>" method="GET" class="mb-4">
                        <div class="row g-3">
                            <div class="col-md-3">
                                <label class="form-label">Dari Tanggal</label>
                                <input type="date" name="dari_tanggal" class="form-control" value="<?php echo e(request('dari_tanggal')); ?>">
                            </div>
                            <div class="col-md-3">
                                <label class="form-label">Sampai Tanggal</label>
                                <input type="date" name="sampai_tanggal" class="form-control" value="<?php echo e(request('sampai_tanggal')); ?>">
                            </div>
                            <div class="col-md-3">
                                <label class="form-label">Peminjam</label>
                                <select name="id_user" class="form-select">
                                    <option value="">Semua Peminjam</option>
                                    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($user->id_user); ?>" <?php echo e(request('id_user') == $user->id_user ? 'selected' : ''); ?>>
                                            <?php echo e($user->nama); ?> (<?php echo e($user->username); ?>)
                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="col-md-3">
                                <label class="form-label">Buku</label>
                                <select name="id_buku" class="form-select">
                                    <option value="">Semua Buku</option>
                                    <?php $__currentLoopData = $buku; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $b): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($b->id_buku); ?>" <?php echo e(request('id_buku') == $b->id_buku ? 'selected' : ''); ?>>
                                            <?php echo e($b->judul); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="col-md-3">
                                <label class="form-label">Status Jatuh Tempo</label>
                                <select name="status_jatuh_tempo" class="form-select">
                                    <option value="">Semua Status</option>
                                    <option value="akan_jatuh_tempo" <?php echo e(request('status_jatuh_tempo') == 'akan_jatuh_tempo' ? 'selected' : ''); ?>>
                                        Akan Jatuh Tempo (3 Hari)
                                    </option>
                                    <option value="sudah_jatuh_tempo" <?php echo e(request('status_jatuh_tempo') == 'sudah_jatuh_tempo' ? 'selected' : ''); ?>>
                                        Sudah Jatuh Tempo
                                    </option>
                                </select>
                            </div>
                            <div class="col-md-9">
                                <label class="form-label d-none d-md-block">&nbsp;</label>
                                <div class="d-flex gap-2">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fas fa-filter"></i> Filter
                                    </button>
                                    <a href="<?php echo e(route('admin.laporan.peminjaman')); ?>" class="btn btn-secondary">
                                        <i class="fas fa-redo"></i> Reset
                                    </a>
                                </div>
                            </div>
                        </div>
                    </form>

                    
                    <div class="d-flex gap-2 mb-3">
                        <form action="<?php echo e(route('admin.laporan.peminjaman.excel')); ?>" method="POST" class="d-inline">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="jenis" value="aktif">
                            <input type="hidden" name="dari_tanggal" value="<?php echo e(request('dari_tanggal')); ?>">
                            <input type="hidden" name="sampai_tanggal" value="<?php echo e(request('sampai_tanggal')); ?>">
                            <input type="hidden" name="id_user" value="<?php echo e(request('id_user')); ?>">
                            <input type="hidden" name="id_buku" value="<?php echo e(request('id_buku')); ?>">
                            <button type="submit" class="btn btn-success">
                                <i class="fas fa-file-excel"></i> Export Excel
                            </button>
                        </form>
                        <form action="<?php echo e(route('admin.laporan.peminjaman.pdf')); ?>" method="POST" class="d-inline">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="jenis" value="aktif">
                            <input type="hidden" name="dari_tanggal" value="<?php echo e(request('dari_tanggal')); ?>">
                            <input type="hidden" name="sampai_tanggal" value="<?php echo e(request('sampai_tanggal')); ?>">
                            <input type="hidden" name="id_user" value="<?php echo e(request('id_user')); ?>">
                            <input type="hidden" name="id_buku" value="<?php echo e(request('id_buku')); ?>">
                            <button type="submit" class="btn btn-danger">
                                <i class="fas fa-file-pdf"></i> Export PDF
                            </button>
                        </form>
                        <button onclick="window.print()" class="btn btn-secondary">
                            <i class="fas fa-print"></i> Print
                        </button>
                    </div>

                    
                    <div class="alert alert-info">
                        <i class="fas fa-info-circle"></i> 
                        Total Peminjaman Aktif: <strong><?php echo e($peminjaman->total()); ?></strong> buku
                    </div>

                    
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover">
                            <thead class="table-light">
                                <tr>
                                    <th width="50">No</th>
                                    <th>Tanggal Pinjam</th>
                                    <th>Peminjam</th>
                                    <th>Judul Buku</th>
                                    <th>Nomor Aset</th>
                                    <th>Jatuh Tempo</th>
                                    <th>Status</th>
                                    <th>Denda</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $peminjaman; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <?php
                                        $jatuhTempo = \Carbon\Carbon::parse($p->tanggal_jatuh_tempo);
                                        $now = \Carbon\Carbon::now();
                                        $isOverdue = $now->gt($jatuhTempo);
                                        $daysUntilDue = $now->diffInDays($jatuhTempo, false);
                                    ?>
                                    <tr class="<?php echo e($isOverdue ? 'table-danger' : ($daysUntilDue <= 3 && $daysUntilDue >= 0 ? 'table-warning' : '')); ?>">
                                        <td><?php echo e($peminjaman->firstItem() + $index); ?></td>
                                        <td><?php echo e(\Carbon\Carbon::parse($p->tanggal_pinjam)->format('d/m/Y')); ?></td>
                                        <td>
                                            <strong><?php echo e($p->user->nama ?? '-'); ?></strong><br>
                                            <small class="text-muted"><?php echo e($p->user->username ?? '-'); ?></small>
                                        </td>
                                        <td><?php echo e($p->asetBuku->buku->judul ?? '-'); ?></td>
                                        <td><span class="badge bg-secondary"><?php echo e($p->asetBuku->nomor_aset ?? '-'); ?></span></td>
                                        <td>
                                            <?php echo e($jatuhTempo->format('d/m/Y')); ?>

                                            <?php if($isOverdue): ?>
                                                <br><span class="badge bg-danger">Terlambat <?php echo e(abs($daysUntilDue)); ?> hari</span>
                                            <?php elseif($daysUntilDue <= 3 && $daysUntilDue >= 0): ?>
                                                <br><span class="badge bg-warning"><?php echo e($daysUntilDue); ?> hari lagi</span>
                                            <?php endif; ?>
                                        </td>
                                        <td><span class="badge bg-primary"><?php echo e($p->status_peminjaman); ?></span></td>
                                        <td class="text-end">
                                            <?php if($p->denda > 0): ?>
                                                <span class="text-danger fw-bold">Rp <?php echo e(number_format($p->denda, 0, ',', '.')); ?></span>
                                            <?php else: ?>
                                                <span class="text-muted">-</span>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="8" class="text-center text-muted py-4">
                                            <i class="fas fa-inbox fa-3x mb-3 d-block"></i>
                                            Tidak ada data peminjaman aktif
                                        </td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>

                    
                    <div class="d-flex justify-content-between align-items-center mt-3">
                        <div class="text-muted">
                            Menampilkan <?php echo e($peminjaman->firstItem() ?? 0); ?> - <?php echo e($peminjaman->lastItem() ?? 0); ?> 
                            dari <?php echo e($peminjaman->total()); ?> data
                        </div>
                        <?php echo e($peminjaman->links()); ?>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php $__env->startPush('styles'); ?>
<style>
    @media print {
        .card-header, .btn, nav, .sidebar, .navbar { display: none; }
        .table { font-size: 12px; }
    }
</style>
<?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\hizkia\Desktop\TUBES_MSBD\Perpustakaan-SMAN-1-Pangururan\resources\views/admin/laporan/peminjaman.blade.php ENDPATH**/ ?>