<?php

include "../../html.class.php";
include "../../classes/db.class.php";
$html = new html();

$client_id = new select();
$client_id->name('client_id');
$client_id->id('client_id');
$client_id->class('inputs');
$client_id->add_option("", "SELECT CLIENT");
$client_id->fill_from_db("clients", "record_id", "client_name", "company_id = {$_SESSION['company_id']}");


$user_id = new select();
$user_id->name('user_id');
$user_id->id('user_id');
$user_id->class('inputs');
$user_id->add_option("", "SELECT USER");
$user_id->fill_from_db("users", "record_id", "username", "company_id = {$_SESSION['company_id']}");


$site_id = new select();
$site_id->name('site_id');
$site_id->id('site_id');
$site_id->class('inputs');
$site_id->add_option("", "SELECT SITE");
$all_sites_res = $db->query("sites", "SELECT * FROM sites WHERE company_id = {$_SESSION['company_id']}");
while ($site = $all_sites_res->fetch_assoc()) {
    $site_id->add_option($site['record_id'], $site['name']);
}

$tank_id = new select();
$tank_id->name('tank_id');
$tank_id->id('tank_id');
$tank_id->class('inputs');
$tank_id->add_option("", "SELECT TANK");
$all_sites_res = $db->query("sites", "SELECT * FROM sites WHERE company_id = {$_SESSION['company_id']}");
while ($site = $all_sites_res->fetch_assoc()) {
    $tank_res = $db->query("tanks", "SELECT * FROM tanks WHERE site_id = {$site['record_id']}");
    while ($tank = $tank_res->fetch_assoc()) {
        $tank_id->add_option($tank['record_id'], $tank['name']);
    }

}

$type = new select();
$type->name('cash_type');
$type->id('cash_type');
$type->class('inputs');
$type->add_option("", "SELECT CASH TYPE");
$type->add_option(0, "N/A");
$type->add_option(1, "CASH");
$type->add_option(2, "CARD");
$type->add_option(3, "EFT");

$date_from = new input();
$date_from->name('date_from');
$date_from->id('date_from');
$date_from->class('inputs');
$date_from->type('date');

$date_to = new input();
$date_to->name('date_to');
$date_to->id('date_to');
$date_to->class('inputs');
$date_to->type('date');

$excluded = new select();
$excluded->name('exclude_from_reports');
$excluded->id('exclude_from_reports');
$excluded->class('inputs');
$excluded->add_option(0, "NO");
$excluded->add_option(1, "YES");

$submit = new button();
$submit->name('submit');
$submit->id('submit');
$submit->class('app_buttons');
$submit->value('Search');


?>

<form action="diesel_orders.php" method="post">
    <div class="tank_item_container">
        <h1>DIESEL USAGE REPORT FORM</h1>
        <?php
        $client_id->add();
        $user_id->add();
        echo "<label>DATE FROM</label>";
        $date_from->add();
        echo "<label>DATE TO</label>";
        $date_to->add();
        echo "<hr>";
        echo "<label>SITES</label>";
        $site_id->add();
        echo "<label>TANKS</label>";
        $tank_id->add();
        echo "<hr>";
        echo "<label>TYPE</label>";
        $type->add();
        echo "<label>INCLUDE EXCLUDED TAGS</label>";
        $excluded->add();
        $submit->add();
        ?>
    </div>
</form>