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

    <div class="pagetitle">
        <h1>Nomor Lot FG</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-2">
                                    <button class="btn btn-primary" id="btnview" onclick="tampildata()"><i class='bi bi-search'></i>&nbsp;Lihat FG</button>
                                    <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>
                                </div>
                            </div>
                            <br>
                            <div class="datatable-container">
                                <div id="tbllot"></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("tb_lotfg.php?mulai=" + mulai + "&hingga=" + hingga, function(data, status) {
            $("#tbllot").html(data);
            document.getElementById("btnloading").style.display = "none";
            document.getElementById("btnview").style.display = "block";
        });
    }

    $(document).ready(function() {
        tampildata();
    });

    function cetaklot(id) {
        window.open("cetak_lotfg.php?id=" + id, "_blank");
    }

    function tflot(id) {
        Swal.fire({
            title: "Transfer Stok FG ke Gudang ?",
            icon: "question",
            showCancelButton: true,
            confirmButtonColor: "#3085d6",
            cancelButtonColor: "#d33",
            confirmButtonText: "Ya, Transfer"
        }).then((result) => {
            if (result.isConfirmed) {
                $.ajax({
                    url: "transferfg.php",
                    type: 'POST',
                    cache: false,
                    data: {
                        id: id
                    },
                    success: function() {
                        tampildata();
                    }
                });
            }
        });
    }

    function simpanlot() {
        var tgllot = $("#tgllot").val();
        var shiftlot = $("#shiftlot").val();
        var mesinlot = $("#mesinlot").val();
        var qtylot = $("#qtylot").val();
        var brglot = $("#brglot").val();
        if (tgllot == '') {
            document.getElementById('tgllot').focus();
            Swal.fire({
                title: "Tanggal harus diisi",
                icon: "warning"
            });
        } else {
            if (qtylot == '') {
                document.getElementById('qtylot').focus();
                Swal.fire({
                    title: "Jumlah FG harus diisi",
                    icon: "warning"
                });
            } else {
                $.ajax({
                    url: "simpanlotfg.php",
                    type: 'POST',
                    cache: false,
                    data: {
                        brglot: brglot,
                        tgllot: tgllot,
                        shiftlot: shiftlot,
                        mesinlot: mesinlot,
                        qtylot: qtylot
                    },
                    success: function() {
                        tampildata();
                    }
                });
            }
        }
    }
</script>