<?php include "../../root.class.php";
$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

$record_id = new input();
$record_id->type("hidden");
$record_id->name("record_id");
$record_id->id("record_id");
$record_id->value($_GET['record_id']);

$stock_id_label = new label();
$stock_id_label->for("stock_no");
$stock_id_label->value("STOCK NO");

$stock_id = new input();
$stock_id->type("text");
$stock_id->name("stock_no");
$stock_id->id("stock_no");
$stock_id->value_from_db('stock_control', 'stock_no', "record_id = {$_GET['record_id']}");
$stock_id->readonly();

$item_name_label = new label();
$item_name_label->for("item_name");
$item_name_label->value("ITEM NAME");

$item_name = new input();
$item_name->type("text");
$item_name->name("item_name");
$item_name->id("item_name");
$item_name->style("width:30vw;");
$item_name->value_from_db('stock_control', 'item_name', "record_id = {$_GET['record_id']}");
$item_name->style("width:30vw;");

$description_label = new label();
$description_label->for("description");
$description_label->value("DESCRIPTION");

$description = new input();
$description->type("text");
$description->name("description");
$description->id("description");
$description->style("width:30vw;");
$description->value_from_db('stock_control', 'description', "record_id = {$_GET['record_id']}");
$description->style("width:40vw;");

$quantity_label = new label();
$quantity_label->for("quantity");
$quantity_label->value("QUANTITY");

$quantity = new input();
$quantity->type("number");
$quantity->name("quantity");
$quantity->id("quantity");
$quantity->style("width:30vw;");
$quantity->value_from_db('stock_control', 'quantity', "record_id = {$_GET['record_id']}");

$status_label = new label();
$status_label->for("status");
$status_label->value("STATUS");

$status = new select();
$status->name("status");
$status->id("status");
$status->add_option("0","AVAILABLE");
$status->add_option("1","BOOKED");

$submit_btn = new button();
$submit_btn->value("UPDATE");
$submit_btn->onclick("update_stock()");

?>

<div class="form_down">
    <h1>UPDATE STOCK</h1>
    <?php
    $record_id->add();
    $stock_id_label->add();
    $stock_id->add();
    $item_name_label->add();
    $item_name->add();
    $description_label->add();
    $description->add();
    $quantity_label->add();
    $quantity->add();
    $status_label->add();
    $status->add();
    $submit_btn->add();
    ?>
</div>

<?php
$ajax = new js_ajax();
$ajax->function_name("update_stock");
$ajax->update("stock_control");
$ajax->on_success("STOCK UPDATED");
$ajax->redirect("../stock_control/home.php");