<?php

include "../../classes/app.class.php";

$app = new app();
$db = new DBMain();
?>


<div class='container flex_container'>
    <h1>SEARCH JOBCARD BY:</h1>
    <div class="container flex_container" style='border: 1px solid black; width:80%;padding: 10px;border-radius: 10px;'>

        <div class='flex_container_content'>
            <input type='number' id='jobcard_number' placeholder='Enter Jobcard Number'>
            <select id='status' style='font-size:1vw;'>
                <option>STATUS</option>
                <option value=0>OPEN</option>
                <option value=1>ACTIVE</option>
                <option value=2>HOLD</option>
            </select>
            <select id='client_id' style='font-size:1vw;'>
                <option value='-1'>CLIENT</option>
                <?php echo $db->get_clients_in_dropdown() ?>
            </select>
        </div>
        <br>
        <div class='flex_container_content'>
            <label> DESCRIPTION </label>
            <textarea style='width:100%;' id='description'></textarea>
        </div>
        <br>
        <div class='flex_container_content'>
            <label> DATE FROM </label>
            <input type='date' id='date_from' placeholder='DATE FROM'>
            <label> DATE TO </label>
            <input type='date' id='date_to' placeholder='DATE FTO'>
        </div>
        <button onclick="search_client()" class='font_size_2vw'>SEARCH</button>
    </div>
</div>

<div class='flex_container' id='content'>

</div>

<script>
    function search_client() {

        var jobcard_number = document.getElementById('jobcard_number').value;
        var status = document.getElementById('status').value;
        var client_id = document.getElementById('client_id').value;
        var description = document.getElementById('description').value;
        var date_from = document.getElementById('date_from').value;
        var date_to = document.getElementById('date_to').value;

        var xhttp = new XMLHttpRequest();
        xhttp.onload = function() {

            document.getElementById('content').innerHTML = this.responseText;

        }
        xhttp.open("GET", '../../ajax/jobcards/search_jobcard.php?jobcard_number= ' + jobcard_number + '&status=' + status + '&client_id=' + client_id + '&description=' + description + '&date_from=' + date_from + '&date_to=' + date_to);
        xhttp.send();

    }

    function edit_jobcard($id) {
        window.location.href = 'edit_jobcard.php?record_id=' + $id;
    }
</script>