<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

$consumables_res = $db->query("consumable", "SELECT * FROM consumable");

if ($consumables_res->num_rows > 0) {
    $table_data = "<tr><td colspan=\"5\">No consumables found.</td></tr>";
} else {
    $table_data = $table_data . "<tr>   
        <td></td>
        <td></td>
        <td> NO CONSUMABLES FOUND</td>
        <td></td>
        <td></td>
    </tr>";
}


while ($consumables_row = $consumables_res->fetch_assoc()) {
    $table_data = $table_data . "<tr>
            <td>" . $consumables_row["stock_no"] . "</td>
            <td>" . $consumables_row["item_name"] . "</td>
            <td>" . $consumables_row["description"] . "</td>
            <td>" . $consumables_row["quantity"] . "</td>
            <td><a href=\"edit_consumable.php?consumable_id=" . $consumables_row["consumable_id"] . "\">Edit</a></td>
        </tr>";
}

?>

<div class="form_down">
    <h1>MANAGE CONSUMABLES</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></th>
        </tr>
        <?php echo $table_data; ?>
    </table>
    <br>
</div>