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

    <div class="pagetitle">
        <h1><i class="bi bi-truck"></i>&nbsp;Laporan Pengiriman</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-4">
                                    <input type="date" class="form-control" id="mulai">
                                </div>
                                <div class="col-md-4">
                                    <input type="date" class="form-control" id="hingga">
                                </div>
                                <div class="col-md-4">
                                    <button onclick="tampildatakirim()" type="button" class="btn btn-primary">
                                        Lihat
                                    </button>
                                    <?php
                                    if ($akses['unduh'] == 1) {
                                    ?>
                                        <button type="button" onclick="unduh()" class="btn btn-success">
                                            Download
                                        </button>
                                    <?php
                                    }
                                    ?>
                                </div>

                            </div>
                            <br>
                            <div class="datatable-container">
                                <div id="tbpengiriman"></div>
                            </div>
                        </div>
                        <!-- End Table with stripped rows -->
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>

<div class="modal fade" id="f_detail" tabindex="-1" aria-hidden="true" style="display: none;">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Detail Pengiriman</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div id="tb_detail"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-primary" onclick="simpan_rit_balik()">Simpan</button>
            </div>
        </div>
    </div>
</div>

<script>
    function tampildatakirim() {
        var mulai = $("#mulai").val();
        var hingga = $("#hingga").val();
        $.get("<?= base_url('Gudang/tb_pengiriman?s='); ?>" + mulai + "&e=" + hingga, function(data, status) {
            $("#tbpengiriman").html(data);
        });
    }

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

    function detail_ritase(sopir, kendaraan) {
        var mulai = $("#mulai").val();
        var hingga = $("#hingga").val();
        $.get("<?= base_url('Scan/tb_do_detail?s='); ?>" + mulai + "&e=" + hingga + "&d=" + sopir + "&k=" + kendaraan, function(data, status) {
            $("#tb_detail").html(data);
        });
        $("#f_detail").modal("show");
    }
</script>