<div class="content-wrapper">
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1><?= $title; ?></h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item active"><?= $title; ?></li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>
    <div class="container-fluid mt-3">
        <div class="card">
            <div class="card-header text-center">
                <h2>Laporan Peminjaman Inventaris</h2>
            </div>
            <div class="card-body">
                <?php echo $this->session->flashdata('notif'); ?>
                <div class="row">
               
                        <div class="col-md-3">
                            <label for="" class="badge badge-primary">Filter Bulan</label>
                            <select name="bulan" id="bulan" class="form-control">
                                <option value="">-- Filter Bulan --</option>
                                <option value="01">JANUARI</option>
                                <option value="02">FEBRUARI</option>
                                <option value="03">MARET</option>
                                <option value="04">APRIL</option>
                                <option value="05">MEI</option>
                                <option value="06">JUNI</option>
                                <option value="07">JULI</option>
                                <option value="08">AGUSTUS</option>
                                <option value="09">SEPTEMBER</option>
                                <option value="10">OKTOBER</option>
                                <option value="11">NOVEMBER</option>
                                <option value="12">DESEMBER</option>
                            </select>
                        </div>
                        <div class="col-ml-6 pd-left">
                            <div class="form-group">
                                <label for=""><br></label>
                                <button id="cetaklapjadwal" class="btn btn-success btn-block"><i class="fas fa-print"></i> Cetak</button>
                            </div>
                        </div>
                <div class="table-responsive">
                    <table id="tabel" class="table table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>No</th>
                                <th>Nama Peminjam </th>
                                <th>Nama Inventaris</th>
                                <th>Tanggal Peminjaman</th>
                                <th>Yang Melayani</th>
                                <th>Tanggal Pengembalian</th>
                                <th>Yang Menerima</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php $no = 1; ?>
                                <?php foreach ($laporpinjam as $lp) : ?>
                                    <tr>
                                        <td><?php echo $no++; ?></td>
                                        <td><?php echo $lp->nama_lengkap; ?></td>
                                        <td><?php echo $lp->nama_inv; ?></td>
                                        <td><?php echo $lp->tgl_pinjam; ?></td>
                                        <td><?php echo $lp->yg_melayani; ?></td>
                                        <td><?php $date = date_create($lp->tgl_pengembalian);
		                                echo date_format($date, 'd/m/Y'); ?></td>
                                        <td><?php echo $lp->yg_menerima; ?></td>
                                        
                                    </tr>
                                <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
$(document).ready(function(){
    // Ketika filter bulan diubah
    $('#bulan').change(function(){
        // Ambil nilai bulan yang dipilih
        var bulan = $(this).val();
        // Kirim request AJAX
        $.ajax({
            url: '<?php echo base_url('inventaris/filter'); ?>' + bulan,
            type: 'GET',
            dataType: 'json',
            success: function(data){
                // Hapus semua baris tabel kecuali header
                $('#tabel tbody tr').remove();
                // Tambahkan baris baru sesuai data yang diterima
                $.each(data, function(i, item){
                    $('#tabel tbody').append('<tr><td>'+item.no+'</td><td>'+item.nama_lengkap+'</td><td>'+item.nama_inv+'</td><td>'+item.tgl_pinjam+'</td><td>'+item.yg_melayani+'</td><td>'+item.tgl_pengembalian+'</td><td>'+item.yg_menerima+'</td></tr>');
                });
            },
            error: function(){
                alert('Terjadi kesalahan saat memproses data.');
            }
        });
    });
});
</script>
