<?php include "header.php"; ?>

<script>
    $(document).ready(function() {
        var filter = document.getElementById('filter').innerHTML;
        document.getElementById('linkfilter').innerHTML = document.getElementById('linkfilter').innerHTML + " : " + filter;
    })
    document.getElementById('tittlepage').innerHTML = "Ketepatan Waktu Pelayanan IGD 《 6 jam";
    document.getElementById('tindakan').value = "6 jam";
</script>
<!-- ================================= -->

<div class="table-responsive">
    <div class="container-fluid">
        <table class='table table-striped table-hover datatable' width='100%' cellspacing='0' style='font-size: 12px;'>
            <thead>
                <tr>
                    <th style='width:1%'>No</th>
                    <th style='width:1%'>Ruang</th>
                    <th style='width:10%'>Tanggal Masuk</th>
                    <th style='width:1%'>Register</th>
                    <th style='width:30%'>Nama</th>
                    <th style='width:50%'>Status Keluar</th>
                    <th style='width:5%'></th>
                    <th style='width:5%'>Status</th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
</div>
<script>
    $(document).ready(load_data());

    function load_data() {
        var table;
        $(document).ready(function() {
            table = $('.datatable').DataTable({
                "processing": false,

                "ordering": true, // Set true agar bisa di sorting
                "order": [
                    [0, 'asc']
                ], // Default sortingnya berdasarkan kolom / field ke 0 (paling pertama)
                "ajax": {
                    // URL file untuk proses select datanya
                    "url": "data_prolong.php?awal=<?= $_POST['awal']; ?>&akhir=<?= $_POST['akhir']; ?>&tindakan=<?= $_POST['tindakan']; ?>",
                    "type": "GET"
                },
                "deferRender": true,
                "aLengthMenu": [
                    [10, 25, 50, 100],
                    [10, 25, 50, 100]
                ], // Combobox Limit
                "columns": [{
                        data: 'no'
                    },
                    {
                        data: 'ruang'
                    },
                    {
                        data: 'tanggal'
                    },
                    {
                        data: 'register'
                    },
                    {
                        data: 'nama'
                    },
                    {
                        data: 'tindakan'
                    },
                    {
                        data: 'add'
                    },
                    {
                        data: 'status'
                    },
                ]
            });
        });
    }
</script>

<?php include "footer.php"; ?>
<?php
include "model/koneksi.php";
include "function_tanggal.php";
if ($_POST['awal'] == true) {
    $printf = tanggal(date('Y-m-d', strtotime($_POST['awal']))) . ' - s/d - ' . tanggal(date('Y-m-d', strtotime($_POST['akhir'])));
    echo "<div id='filter' hidden>" . $printf . "</div>";
} else {
    echo "<div id='filter' hidden></div>";
}
if (isset($_POST['tambahData'])) {
    $link = "awal=$_POST[awal]&akhir=$_POST[akhir]&tindakan=$_POST[tindakan]";
    $id_pasien = $_POST['id_pasien'];
    $checkdata = mysqli_num_rows(mysqli_query($openinmut, "SELECT*FROM tb_indikator_mutu WHERE id_pasien='$id_pasien' AND los=1"));
    if ($checkdata > 0) {
?>
        <script>
            alert('Data sudah tersimpan , silahkan Refresh');
        </script>
    <?php
    } else {
        $id_pasien = $_POST['id_pasien'];
        $tanggal    = $_POST['tanggal'];
        $register   = $_POST['register'];
        $keterangan = '<8_jam';
        $survey = mysqli_query($openinmut, "INSERT INTO tb_indikator_mutu(id_pasien,tanggal, register,los, keterangan)VALUES('$id_pasien','$tanggal','$register','1','$keterangan')");
    ?>
        <script>
            alert('data tersimpan');
        </script>
<?php
    }
} ?>