<?php
//$products = $auth->getApiData("get/product");
//print_r($_POST);
if (isset($_POST) && $_POST != []) {
    $data = $_POST;
    //$filter = ['productName' => $data['productName']];
    //$test = $auth->getApiDataFilter("get/product",['companyName'=>2]);
    //print_r($test);
    $response = $auth->getApiDataFilter('get/order/exists', $filter);
    if (isset($response->status)) {
        $response = $auth->getApiData("get/order/lastid");
        $response = $response[0];
        $data['id'] = $response->id + 1;
        $data['postedBy'] = $user->id;
        //print_r(json_encode($data));
        $response = $auth->sendApiData("set/order/new", $data);
        //print_r($response);
    }
}
?>
<div class="row">
    <div class="col-12 text-center">
        <div class="card">
            <button type="button" class="btn btn-block bg-gradient-success btn-lg savedata">Mentés</button>
        </div>
    </div>
</div>
<form id="sendForm" class="row w-100" method="POST">
    <div class="col-lg-4 col-sm-12">
        <div class="card">
            <div class="card-header">
                <h4>Partner kiválasztása</h4>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-lg-4 div-sm-6">
                        <h6>Megrendelő</h6>
                    </div>
                    <div class="col-lg-8 div-sm-6 form-group">
                        <select class="select2 w-100 selectPartner form-control" data-placeholder="Válassza ki a partnert"></select>
                    </div>
                </div>
                <hr>
                <div class="row">
                    <div class="col-lg-4 div-sm-6">
                        <h6>Megjegyzés</h6>
                    </div>
                    <div class="col-lg-8 div-sm-6">
                        <textarea class="orderComment form-control"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-4 col-sm-12">
        <div class="card customerParameters">
            <div class="card-header">
                <h4>Megrendelés paraméterei</h4>
            </div>
            <div class="card-body">
            </div>
        </div>
    </div>
    <div class="col-lg-4 col-sm-12">
        <div class="card">
            <div class="card-header">
                <h4>Megrendelés egyéb</h4>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-4">
                        Fizetési határidő:</br>
                    </div>
                    <div class="col-8">
                        <input class="paymentDueDate datepicker form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-12 orderbody" style="display:none">
        <div class="card">
            <div class="card-header">
                Termékek
            </div>
            <div class="card-body productList">
                Hozzáadott termékek listája
            </div>
            <div class="card-footer row">
                <div class="col-lg-2  col-sm-12">
                    <button type="button" class="btn btn-block bg-gradient-primary btn-md addToOrder"><i class="fas fa-plus"></i>Hozzáadás</button>
                </div>
                <div class="col-lg-3 col-sm-11 form-group">
                    <select class="select2 selectProduct form-control" data-placeholder="Válassza ki a terméket"></select>
                </div>
                <div class="col-lg-2 col-sm-6 form-group">
                    <input class="quantitity form-control" type="number" placeholder="mennyiség">
                </div>
            </div>
        </div>
    </div>
</form>
<div class="shadow" style="background-color: rgba(0,0,0,0.7);cursor:pointer;display:none;z-index:9999999;position:fixed;width:100%;height:100%;top:0;left:0;">
    <div class="card popup" style="position:fixed;top:10%;left:10%;width:80%;height:80%">
        <div class="card-header bg-gradient-success">
            <h3></h3>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-3"><strong>Termék leírás</strong></div>
                <div class="productDesc col-9"></div>
            </div>
            <div class="row">
                <div class="col-3"><strong>Termék egység ára:</strong></div>
                <div class="productPrice col-9"></div>
            </div>
        </div>
        <div class="card-footer">
            <button class="btn btn-block bg-gradient-danger closeWindow">Ablak bezárása</button>
        </div>
    </div>
</div>
<script>
    let productList = [];
    let currentPriceRange = null;
    let user = <?php echo $user->id ?>;
</script>
<?php
addJS("order.js?1.04");
?>
