<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

$current_stock_res = $db->query("stock_control", "SELECT * FROM stock_control WHERE status = 0");

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['item_name']}</td>
                <td>{$stock['description']}</td>
                <td>{$stock['quantity']}</td>
                <td>
                <input type='button' class='submit_btn' value='EDIT STOCK' onclick='window.location.href=\"../stock_control/edit_stock.php?record_id={$stock['record_id']}\"'>
                </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>CURRENT STOCK</h1>
    <style>
        table {
            border-collapse: collapse;
            width: 90%;
            background-color: whitesmoke;
        }
        table, th, td {
            border: 2px solid black;
            padding-left: 1vw;
        }
        th {
            padding: 1vw;
        }
    </style>

    <table>
        <tr>
            <th>Received From</th>
            <th>Received By</th>
            <th>Quantity</th>
            <th>Odo</th>
            <th></th>
        </tr>
        <?php echo $table_data; ?>
    </table>
    <br>
</div>
