<?php
include "../../classes/db.class.php";

$db = new DBMain();

$where_data = [];

$stock_verified = $_GET["stock_verified"];
if (strlen($stock_verified) > 1) {
    $where_data[""] = " `stock_user_verified` = 0 ";
}

$admin_verified = $_GET["admin_verified"];
if (strlen($admin_verified) > 1) {
    $where_data[""] = "`stock_user_verified` = 1 AND `admin_verified` = 0 ";
}

$approvals = $_GET["approvals"];
if (strlen($approvals) > 1) {
    $where_data[""] = "`stock_user_verified` = 1 AND `admin_verified` = 1 AND `approved` = 0";
}

$client_id = $_GET['client_id'];
if ($client_id >= 1) {
    $where_data[] = "client_id = " . $client_id . "";
}

$quote_number = $_GET['quote_number'];
if ($quote_number >= 1) {
    $where_data[] = "quote_number = " . $quote_number . "";
}

$description = $_GET['description'];
if (strlen($description) >= 1) {
    $where_data[] = "description LIKE '%" . $description . "%'";
}

$start_date = $_GET['start_date'];
if ($start_date >= 1) {
    $where_data[] = "date_time_created >= '" . $start_date . "'";
}

$end_date = $_GET['end_date'];
if ($end_date >= 1) {
    $where_data[] = "date_time_created <= '" . $end_date . "'";
}

if (count($where_data) > 0) {
    $where = " WHERE " . implode(" AND ", $where_data);
} else {
    $where = " WHERE 1";
}
// echo "SELECT * FROM `stock_items` $where ORDER BY record_id DESC";
$result = $db->conn->query("SELECT * FROM `quotes` $where ORDER BY record_id DESC");
if ($result->num_rows > 0) {
    $index = 0;
    while ($data = $result->fetch_assoc()) {
        $client_info = $db->get_client_info($data["client_id"]);
        echo "

        <div class='flex_container_content' style='box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19) ;background-color: #145593; width:80%;padding: 10px;border-radius: 10px; margin-bottom: 10px; margin-left:auto; margin-right:auto; margin-top:2vw;'>
        <div style='width:100%; text-align: center;'>
        <span style='color:white; font-size:1.5vw;'>DESCRIPTION</span>
           <textarea style='width:100%; height: 10vw; resize: none;' id='quote_description_$index'
                oninput=\"this.style.height = 'auto'; this.style.height = this.scrollHeight + 'px';\">$data[description]</textarea>
            <script>
                auto_adjust($index);
            </script>
            </div>
            <div class='flex_container'>
            
                <div class='flex_container_content'>
                    <div style='width:100%; text-align: center;'>
                        <span style='color:white; font-size:1.5vw;'>QUOTE</span>
                    <input type='text' style='height:3vw;' readonly value=' $data[quote_number]' />
                    </div>
                
                         <div style='width:100%; text-align: center;'>
                        <span style='color:white; font-size:1.5vw;'>DATE</span>

                    <input type='text' style='height:3vw;' readonly value='$data[date_time_created]' />
                    </div>
                     
                </div>
                <div class='flex_container_content'>
                     <div style='width:100%; text-align: center;'>
                        <span style='color:white; font-size:1.5vw;'>CLIENT</span>
                    <input type='text' style='height:3vw; width:100%;' readonly value='$client_info[name]' />
  </div>
                </div>
                <div class='flex_container_content'>
                </div>

            </div>
            <button onclick='edit_quote($data[record_id])' style='width:100%;color:black; background-color: white;' class='font_size_2vw'>SELECT</button>
        </div>
        
        ";
        $index++;
    }
} else {

    echo "        <div class='flex_container_content' style='box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19) ;background-color: #145593; width:80%;padding: 10px;border-radius: 10px; margin-bottom: 10px; margin-left:auto; margin-right:auto; margin-top:2vw;'>
        <h1> NO RESULTS </h1>
        </div>";
}

