<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

$analysist_status_res = $db->query("nut_analysis_report", "SELECT * FROM nut_analysis_report WHERE status = 'DNIS INSPECTION'");

if ($analysist_status_res->num_rows > 0) {
    while ($row = $analysist_status_res->fetch_assoc()) {
            $table_data = $table_data . "
            <tr>
                <td>" . $row["receiving_batch_no"] . "</td>
                <td>" . $row["date_time_created"] . "</td>
                <td>" . $row["farm"] . "</td>
                <td>" . $row["date_harvested"] . "</td>
                <td>" . $row["date_received"] . "</td>
                <td>" . $row["status"] . "</td>
                <td>
                <button 
                class='submit_btn' 
                id='submit_btn_{$row['receiving_batch_no']}' 
                receiving_batch_no='{$row['receiving_batch_no']}'
                style='width: 95%;margin:1vw auto;'>
                COMPLETE
                </button>
                </td>
            </tr>
            ";
    }

} else {
    $table_data = $table_data . "
    <tr>
        <td></td>
        <td></td>
        <td>NO DATA FOUND</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    ";
}

?>

<style>
    body {
        background-image: url('');
        /* background-color: white; */
        background-repeat: repeat-y;
    }

    table {
        width: 95%;
        border-collapse: collapse;
    }

    th,
    td {
        padding-left: 10px;
        padding-right: 10px;
        border: 3px solid black;
        text-align: left;
        background-color: white;
    }
</style>
<div class="form_down">
    <h1>DNIS INSPECTION STATUS</h1>
    <table style='width:90%; text-align:center;'>
        <tr>
            <td style='font-size:1.5vw;'>
                RECEIVING BATCH NO:
            </td>
            <td style='font-size:1.5vw;'>
                DATE CREATED:
            </td>
            <td style='font-size:1.5vw;'>
                FARM:
            </td>
            <td style='font-size:1.5vw;'>
                DATE HARVESTED:
            </td>
            <td style='font-size:1.5vw;'>
                DATE RECEIVED:
            </td>
            <td>
                STATUS:
            </td>
            <td>

            </td>
        </tr>

        <?php echo $table_data; ?>
    </table>
    <br>
    <br>
</div>

<script>
    document.addEventListener("DOMContentLoaded", function () {
        document.querySelectorAll(".submit_btn").forEach(function (btn) {
            btn.addEventListener("click", function () {
                let receiving_batch_no = this.getAttribute("receiving_batch_no");
                window.location.href = '../pre-crack/dnis_inspection_form.php?receiving_batch_no=' + receiving_batch_no;
            });
        });
    });
</script>