<?php
include "../../root.class.php";
$html = new html();
$html->add_styles_page();

// $html->check_user_type("ADMIN");
$po_number = new input();
$po_number->name("po_number");
$po_number->id("po_number");
$po_number->type("text");
$po_number->placeholder("PO Number");
$po_number->class("search_inputs");
$po_number->onkeyup("search_orders()");

$jc_number = new input();
$jc_number->name("jc_number");
$jc_number->id("jc_number");
$jc_number->type("text");
$jc_number->placeholder("JC Number");
$jc_number->class("search_inputs");
$jc_number->onkeyup("search_orders()");

$jc_account = new select();
$jc_account->name("job_card_account_id");
$jc_account->id("job_card_account_id");
$jc_account->class("search_inputs");
$jc_account->add_option("", "JC Account");
$jc_account->fill_from_db("job_card_accounts", "record_id", "name");
$jc_account->class("search_inputs");
$jc_account->onchange("search_orders()");

$suppliers = new select();
$suppliers->name("supplier_id");
$suppliers->id("supplier_id");
$suppliers->class("search_inputs");
$suppliers->add_option("", "Supplier");
$suppliers->fill_from_db("suppliers", "record_id", "name");
$suppliers->onchange("search_orders()");

if (isset($_GET['open'])) {
    $status = new input();
    $status->name('status');
    $status->id('status');
    $status->value(0);
    $status->type('hidden');
    echo "<h1>OPEN ORDERS</h1>";

}

if (isset($_GET['closed'])) {
    $status = new input();
    $status->name('status');
    $status->id('status');
    $status->value(1);
    $status->type('hidden');
    echo "<h1>CLOSED ORDERS</h1>";
}
?>

<div class="search_form">
    <?php
    // echo $html->input_html("PO NUMBER", "", "po_number", "po_number");
    // echo $html->input_html("JOBCARD NO", "", "jc_number", "jc_number");
    // echo $html->select_html_from_db("suppliers", "record_id", "name", "", "supplier_id", "supplier_id");
    // echo $html->submit_btn('submit', 'SEARCH', 'search_orders()'); ?>
    <?php
    if (isset($_GET['open'])) {
        $status->add();
    }
    if (isset($_GET['closed'])) {
        $status->add();
    }
    $po_number->add();
    $jc_number->add();
    $jc_account->add();


    ?>
</div>

<?php
$ajax = new js_ajax();
$ajax->function_name("search_orders");
$ajax->select("orders");
$ajax->return_columns(['po_number', 'jc_number', 'job_card_account_id', 'supplier_id']);
$ajax->run_on_load();
$ajax->redirect("edit_order.php");
?>