<?php
include "classes/html.class.php";
session_start();
$db = new db();
$html = new html("BATCH");

$batch_res = $db->exec_query('batches', ['*'],'','','','',"status = 'BATCH RECEIVED' AND sound_not_sound = 'YES'",'ORDER BY record_id DESC',false);

if ($batch_res->num_rows >= 1) {
    while ($batch_info = $batch_res->fetch_assoc()) {

        $variety_res = $db->exec_query("variety", ['*'], '', '', '', '', "record_id ={$batch_info['variety_id']}");
        $variety_info = $variety_res->fetch_assoc();

        $clients_res = $db->exec_query("clients", ['*'], '', '', '', '', "record_id ={$batch_info['client_id']}");
        $client_info = $clients_res->fetch_assoc();

        $table_data = $table_data . "<tr>
            <td><input type='text' class='table_input' value='BA {$batch_info['record_id']}' readonly /></td>
            <td><input type='text' class='table_input' value='{$variety_info['name']}' readonly /></td>
            <td><input type='text' class='table_input' value='{$batch_info['moisture']}%' readonly /></td>
            <td><input type='text' class='table_input' value='{$batch_info['date']}' readonly /></td>
            <td><input type='text' class='table_input' value='{$client_info['client_name']}' readonly /></td>

            <td><a href='check_batch.php?batch_id={$batch_info['record_id']}' target='_blank'><input type='submit' value='CHECK' class='form_btn' readonly /></a></td>
            </tr>
        ";
    }
} else {
    $table_data = "<tr>
        <td> NO RESULTS</td>
    </tr>";
}

?>
<style>
    body {
        background-image: url('');
        /* background-color: white; */
        background-repeat: repeat-y;
    }
</style>
<br>
<table style='width:100%; text-align:center;'>
    <tr>
        <td style='font-size:1.5vw;'>
            BATCH ID:
        </td>
        <td style='font-size:1.5vw;'>
            VARIETY:
        </td>
        <td style='font-size:1.5vw;'>
            MOISTURE:
        </td>
        <td style='font-size:1.5vw;'>
            DATE RECEIVED:
        </td>
        <td style='font-size:1.5vw;'>
            CLIENT:
        </td>

    </tr>

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