<!DOCTYPE html>
<?php
date_default_timezone_set('Asia/Jakarta'); //Menyesuaikan waktu dengan tempat kita tinggal
$tanggal = DATE('d-M-Y');
$jam = Date('H:i');
header("Content-Type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=Ketepatan_Waktu_Pelayanan_IGD_≤_6_jam_$tanggal-jam_$jam.xls");
header("Pragma: no-cache");
header("Expires: 0");
include "../model/koneksi.php";

$awal  = date('Y-m-d H:i:s', strtotime($_GET['awal']));
$akhir = date('Y-m-d H:i:s', strtotime($_GET['akhir']));

?>
<html>

<head>
    <title></title>
    <link href="https://cdn.jsdelivr.net/npm/simple-datatables@latest/dist/style.css" rel="stylesheet" />
</head>

<body>

    <?php
    $tanggal = DATE('d-M-Y');
    $jam = Date('H:i');
    ?>
    <table class='table table-striped table-bordered ' width='100%' cellspacing='0' style='font-size: 12px;' border="1">
        <thead>

            <div style='font-size:12pt; font-weight:bold;'>
                <center>
                    Ketepatan Waktu Pelayanan IGD ≤ 6 jam
                    <p>periode <?= $awal; ?> -s/d- <?= $akhir; ?></p>
                </center>
            </div>
            <tr style="background-color: cadetblue; align-content:center;">
                <th style='width:1%'>No</th>
                <th style='width:15%'>Tanggal masuk</th>
                <th style='width:15%'>Register</th>
                <th style='width:1%'>Num</th>

            </tr>
        </thead>
        <tbody>
            <?php
            $query = "SELECT * FROM tb_indikator_mutu WHERE tanggal BETWEEN '$awal' AND '$akhir'";
            $query_los = mysqli_query($openinmut, "$query AND los=1");
            $no = 0;
            while ($data = mysqli_fetch_assoc($query_los)) {
                $no++;
                echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;'>";
                echo " <td>$no</td>";
                echo " <td>" . date('d-m-Y H:i', strtotime($data['tanggal'])) . "</td>";
                echo " <td>$data[register]</td>";
                echo " <td>$data[los]</td>";

                echo " </tr>";
            ?>

            <?php } ?>
        </tbody>
    </table><br>
    <table class='table table-striped table-bordered table-hover datatable' width='100%' cellspacing='0' style='font-size: 12px;' border="1" align="center">
        <thead>
            <tr>
                <th style='width:1%'>Numerator</th>
                <th style='width:1%'>Denumerator</th>
                <th style='width:15%'>Percentage</th>
                <th style='width:5%'>Target</th>
            </tr>
        </thead>
        <tbody>
            <div>
                <?php
                $num_los = mysqli_num_rows(mysqli_query($openinmut, "$query AND los=1"));
                $denum_los = mysqli_num_rows(mysqli_query($open, "SELECT * FROM datapasien WHERE tanggal BETWEEN '$awal' AND '$akhir'  AND NOT status_keluar like '%delete%'"));

                echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;' align='center'>";
                echo " <td>$num_los</td>";
                echo " <td>$denum_los</td>";
                if ($denum_los  > 0) {
                    $per_los  = number_format((($num_los  / $denum_los) * 100), 2);
                    echo " <td>$per_los  %</td>";
                } else {
                    echo " <td>0 %</td>";
                }
                echo " <td>100 %</td>";
                echo " </tr>";
                ?>
            </div>
        </tbody>
    </table>
    </div>
    <?php
    //tutup koneksi
    mysqli_close($openinmut);

    ?>
</body>

</html>