<main id="main" class="main">

    <div class="pagetitle">
        <h1>Laporan stok per barang</h1>
        <nav>
            <ol class="breadcrumb">

            </ol>
        </nav>
    </div><!-- End Page Title -->

    <section class="section">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <br>
                        <!-- Table with stripped rows -->
                        <div class="datatable-wrapper datatable-loading no-footer sortable searchable fixed-columns">
                            <form class="row g-3">
                                <div class="col-3">
                                    <label for="inputNanme4" class="form-label">Mulai</label>
                                    <input type="date" class="form-control" id="mulai">
                                </div>
                                <div class="col-3">
                                    <label for="inputNanme4" class="form-label">Hingga</label>
                                    <input type="date" class="form-control" id="hingga">
                                </div>
                                <div class="col-6">
                                    <label for="inputNanme4" class="form-label">Nama Barang</label>
                                    <select class="form-control" id="nm_brg">
                                        <option value="0">-Pilih barang-</option>
                                        <?php
                                        foreach ($fg as $f) {
                                            echo "<option value='" . $f['sku'] . "'>" . $f['sku'] . "-" . $f['barang'] . "</option>";
                                        }
                                        ?>
                                    </select>
                                </div>
                            </form>
                            <div class="row g-3">
                                <div class="col-md-12"><br>
                                    <button type="button" style="float:right;margin: 2px;" class="btn btn-primary" id="btnview" onclick="tampildata()"><i class='bi bi-search'></i>&nbsp;View</button>
                                    <button type="button" style="display:none;float:right;margin: 2px;" id="btnloading" class="btn btn-primary" type="button" disabled="">
                                        <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
                                        Loading...
                                    </button>
                                    <!--
                                    <button type="button" style="float:right;margin: 2px;" class="btn btn-success" onclick="unduh()"><i class='bi bi-download'></i>&nbsp;Unduh</button>
                                    -->
                                </div>
                            </div>
                            <br>
                            <div class="datatable-container">
                                <div id="tbstoklist"></div>
                            </div>
                        </div>
                        <!-- End Table with stripped rows -->
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>

<script>
    function tampildata() {
        var mulai = $("#mulai").val();
        var hingga = $("#hingga").val();
        var kode = $("#nm_brg").val();
        document.getElementById("btnloading").style.display = "block";
        document.getElementById("btnview").style.display = "none";
        $.get("<?= base_url(); ?>Gudang/tb_monitor_stok?s=" + mulai + "&e=" + hingga + "&k=" + kode, function(data, status) {
            $("#tbstoklist").html(data);
            document.getElementById("btnloading").style.display = "none";
            document.getElementById("btnview").style.display = "block";
        });
    }
</script>