<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

$current_stock_res = $db->query("stock_trans", "SELECT * FROM stock_trans");

if ($current_stock_res->num_rows > 0) {
    while ($stock = $current_stock_res->fetch_assoc()) {
        $table_data = $table_data . "
            <tr>
                <td>{$stock['stock_no']}</td>
                <td>{$stock['jobcard_no']}</td>
                <td>{$stock['item_name']}</td>
                <td>{$stock['description']}</td>
                <td>{$stock['date_booked']}</td>
                <td>{$stock['quantity']}</td>
            </tr>
        ";
    }
} else {
    $table_data = $table_data . "
        <tr>
            <td></td>
            <td></td>
            <td>NO STOCK FOUND</td>
            <td></td>
            <td></td>
        </tr>
    ";
}

?>
<div class="form_down">
    <h1>BOOKED STOCK</h1>
    <style>
        table {
            border-collapse: collapse;
            width: 90%;
            background-color: whitesmoke;
        }
        table, th, td {
            border: 2px solid black;
            padding: 1vw;
        }
        th {
            padding: 1vw;
        }
    </style>

    <table>
        <tr>
            <th>Stock No</th>
            <th>Jobcard No</th>
            <th>Item Name</th>
            <th>Description</th>
            <th>Date Booked Out</th>
            <th>Quantity</th>
        </tr>
        <?php echo $table_data; ?>
    </table>
    <br>
</div>

<script>
    setInterval(function () {
        location.reload();
    }, 100000);
</script>