<!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=Kepatuhan_pelaporan_reaksi_tranfusi_$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>
                    KEPATUHAN PELAPORAN REAKSI TRANFUSI
                    <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_tranfusi WHERE tanggal BETWEEN '$awal' AND '$akhir'";
            $query_tranfusi = mysqli_query($openinmut, "$query");
            $no = 0;
            while ($data = mysqli_fetch_assoc($query_tranfusi)) {
                $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[reaksi]</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_tranfusi = mysqli_num_rows(mysqli_query($openinmut, "$query AND reaksi=1"));
                $denum_tranfusi = mysqli_num_rows(mysqli_query($openinmut, "SELECT * FROM tb_tranfusi WHERE tanggal BETWEEN '$awal' AND '$akhir' "));
                echo "<tr class='table table-striped table-bordered' style='font-size:10pt; font-weight:bold;' align='center'>";
                echo " <td>$num_tranfusi</td>";
                echo " <td>$denum_tranfusi</td>";
                if ($denum_tranfusi  > 0) {
                    $per_tranfusi  = number_format((($num_tranfusi  / $denum_tranfusi) * 100), 2);
                    echo " <td>$per_tranfusi  %</td>";
                } else {
                    echo " <td>0 %</td>";
                }
                echo " <td>100 %</td>";
                echo " </tr>";
                ?>
            </div>
        </tbody>
    </table>
    </div>
    <?php
    //tutup koneksi
    mysqli_close($openinmut);

    ?>
</body>

</html>