<?php
include "classes/html.class.php";
session_start();
$db = new db();
$html = new html("bin dashboard");

$batches = $db->exec_query('batches', ['*'], '', '', '', '', "status = 'DRYING BINS'", '', false);
if ($batches->num_rows > 0) {
    $bins_trans_res = $db->exec_query('bins_trans', ['*'], '', '', '', '', "silo_id = 0 AND bin_id <> 0", 'order by record_id desc', false);
    while ($bins_trans = $bins_trans_res->fetch_assoc()) {

        $variety_res = $db->exec_query('variety', ['*'], '', '', '', '', "record_id = {$bins_trans['variety_id']}", '', false);
        $variety = $variety_res->fetch_assoc();

        $bin_res = $db->exec_query('drying_bins', ['*'], '', '', '', '', "record_id = {$bins_trans['bin_id']}", '', false);
        $bin = $bin_res->fetch_assoc();

        $table_data = $table_data . "<tr>
                <td><input type='text' class='table_input' value='BA {$bins_trans['batch_id']}' readonly /></td>
                <td><input type='text' class='table_input' value='{$variety['name']}' readonly /></td>
                <td><input type='text' class='table_input' value='{$bins_trans['amount']}' readonly /></td>
                <td><input type='text' class='table_input' value='{$bins_trans['date']}' readonly /></td>
                <td><input type='text' class='table_input' value='{$bin['name']}' readonly /></td>
                <td><a href='drying_bins.php' target='_blank'><input type='submit' value='GO TO' class='form_btn' readonly /></a></td>
                </tr>
            ";
    }

} else {
    $table_data = "<tr>
        <td> NO RESULTS</td>
    </tr>";
}

?>

<div class='form' style="padding-bottom: 0%;width: 98%;">

    <h2 style="font-size: 2vw;">CURRENT BATCHES IN DRYING BINS </h2>
    <hr><br>

    <table style='width:100%; text-align:center;'>
        <tr style="font-size: 1.3vw;">
            <th>BATCH ID</th>
            <th>VARIETY</th>
            <th>AMOUNT</th>
            <th>DATE</th>
            <th>DRYING BIN</th>
            <th> </th>

        </tr>
        <?php echo $table_data; ?>
    </table>
    <br>
</div>

<br><br><br>

<script>
    //create a 30 second timer to refresh the page
    setInterval(function () {
        location.reload();
    }, 30000);

</script>