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

    <div class="pagetitle">
        <h1>Laporan Surat Jalan</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">
                            <div class="row g-3">
                                <div class="col-md-1">
                                    <label class="form-label">Mulai</label>
                                </div>
                                <div class="col-md-3">
                                    <input type="date" class="form-control" id="mulai" value="<?= date('Y-m-d'); ?>">
                                </div>
                                <div class="col-md-1">
                                    <label class="form-label">Hingga</label>
                                </div>
                                <div class="col-md-3">
                                    <input type="date" class="form-control" id="hingga" value="<?= date('Y-m-d'); ?>">
                                </div>
                                <div class="col-md-4">
                                    <button type="button" style="float:left;margin: 2px;" class="btn btn-primary" id="btnview" onclick="tampildata()"><i class='bi bi-search'></i>&nbsp;Lihat SJ</button>
                                    <button type="button" style="display:none;float:left;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>
                                    <?php
                                    if ($akses['unduh'] == 1) {
                                    ?>
                                        <button type="button" style="float:left;margin: 2px;" class="btn btn-success" onclick="unduh()"><i class='bi bi-download'></i>&nbsp;Unduh</button>
                                    <?php
                                    }
                                    ?>
                                </div>
                            </div>
                            <br>
                            <div class="datatable-container">
                                <div id="tbfglist"></div>
                            </div>
                        </div>
                        <!-- End Table with stripped rows -->

                    </div>
                </div>

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

</main>

<script src="assets/libs/js/jquery-3.6.0.min.js"></script>
<script>
    function tampildata() {
        var mulai = $("#mulai").val();
        var hingga = $("#hingga").val();
        document.getElementById("btnloading").style.display = "block";
        document.getElementById("btnview").style.display = "none";
        $.get("<?= base_url(); ?>Gudang/tb_sj?s=" + mulai + "&e=" + hingga, function(data, status) {
            $("#tbfglist").html(data);
            document.getElementById("btnloading").style.display = "none";
            document.getElementById("btnview").style.display = "block";
        });
    }

    function unduh() {
        var mulai = $("#mulai").val();
        var hingga = $("#hingga").val();
        window.open("<?= base_url(); ?>Gudang/tb_sj_xls?s=" + mulai + "&e=" + hingga, "_self");
    }
</script>