<main id="main" class="main">
    <div class="pagetitle">
        <h1>Laporan Transaksi Pembelian</h1>
        <nav>
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url('beranda') ?>">Beranda</a></li>
                <li class="breadcrumb-item">Laporan</li>
                <li class="breadcrumb-item active">Pembelian</li>
            </ol>
        </nav>
    </div>
    <!-- End Page Title -->

    <section class="section">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-header">
                        <div class="row g-2">
                            <div class="col-md-2">
                                <label class="form-label">Tanggal Awal</label>
                                <input type="date" class="form-control" id="awal" name="awal" value="<?php echo @$awal ?>" onkeypress="tampilkan()" onkeyup="tampilkan()" onchange="tampilkan()" oninput="tampilkan()" autofocus>
                            </div>
                            <div class="col-md-2">
                                <label class="form-label">Tanggal Akhir</label>
                                <input type="date" class="form-control" id="akhir" name="akhir" value="<?php echo @$akhir ?>" onkeypress="tampilkan()" onkeyup="tampilkan()" onchange="tampilkan()" oninput="tampilkan()">
                            </div>
                            <div class="col-md-3">
                                <label class="form-label">Suplier</label>
                                <select class="form-control" id="suplier" name="suplier" onchange="tampilkan()">
                                    <option value="">-- pilih suplier --</option>
                                    <?php
                                    foreach ($datasuplier as $hasil) {
                                        ?>
                                        <option value="<?php echo $hasil->kode_suplier ?>"><?php echo $hasil->suplier ?></option>
                                        <?php
                                    }
                                    ?>
                                </select>
                            </div>
                            <div class="col-md-2">
                                <label class="form-label" style="color: white;">&nbsp;</label>
                                <button type="button" class="btn btn-primary" style="width: 100%;" onclick="tampilkan()"><i class="bi bi-search"></i> Tampilkan</button>
                            </div>
                            <div class="col-md-2">
                            <label class="form-label" style="color: white;">&nbsp;</label>
                                <button type="button" class="btn btn-success" style="width: 100%;" onclick="cetak()"><i class="bi bi-file-excel"></i> Cetak</button>
                            </div>
                        </div>
                    </div>
                    <div class="card-body" id="konten">
                    
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>
<?php @$this->load->view($footer) ?>
<!-- Page specific script -->
<script type="text/javascript">
$(document).ready(function() {
    tampilkan();
});

function tampilkan() {
    var awal=$("#awal").val();
    var akhir=$("#akhir").val();
    var suplier=$("#suplier").val();
    $.ajax({
        url:"<?php echo base_url('laporan/ajax_beli') ?>",
        cache:false,
        type:"POST",
        data:{awal:awal,akhir:akhir,suplier:suplier},
        beforeSend: function(){
            $("#konten").html('<center><img src="<?php echo base_url('assets/img/loading.gif') ?>"></center>');
        },
        success:function(result){
            $("#konten").html(result);
        }
    });
}

function cetak() {
    var awal=$("#awal").val();
    var akhir=$("#akhir").val();
    var suplier=$("#suplier").val();
    window.open("<?php echo base_url('laporan/xls_beli?') ?>awal="+awal+"&akhir="+akhir+"&suplier="+suplier);
}
</script>
<?php @$this->load->view($footerend) ?>
<!-- Page specific script -->