title = "Order detail"
url = "/order-detail/:orderId"
layout = "platform_main"
is_hidden = 0

[orderItem]
==
<?php
function onStart(){

    $this["orderId"] = $this->param("orderId");

    $orderId = $this->param("orderId");

    $count = Romanah\Gokbakja\Models\OrderItem::where("order_id", $orderId)->count();

    $this["order"] = Romanah\Gokbakja\Models\Order::where("id", $orderId)
                    ->withCount(['order_items as order_all_amount' => function($query) {
                        $query->select(DB::raw('sum(amount)'));
                    }])
                    ->withCount(['order_items as order_all_price' => function($query) {
                        $query->select(DB::raw('sum(price)'));
                    }])
                    ->first();

    if($count > 0){
        $this["all"] = ($this["order"]->order_all_amount * $this["order"]->order_all_price) / $count;
    }

    $orderItems = Romanah\Gokbakja\Models\OrderItem::where("order_id", $orderId)->orderBy("id", "DESC")->with(["type", "size", "color"])->get();

    $sumOfPrice = 0;

    for ($x = 0; $x < count($orderItems); $x++) {
        $sumOfPrice = (float)((float)$sumOfPrice + (float)($orderItems[$x]->amount * (float)$orderItems[$x]->price));
    }

    $this["sumOfPrice"] = (float)$sumOfPrice;

    $this["sizes"] = Romanah\Gokbakja\Models\BagSize::get();
    $this["types"] = Romanah\Gokbakja\Models\BagType::get();
    $this["colors"] = Romanah\Gokbakja\Models\BagColor::get();

}
?>
==
{% put styles %}
<link href="{{'assets/libs/datatables.net-bs4/css/dataTables.bootstrap4.min.css'|theme}}" rel="stylesheet"
    type="text/css" />
<link href="{{'assets/libs/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css'|theme}}" rel="stylesheet"
    type="text/css" />
<link href="{{'assets/libs/datatables.net-select-bs4/css/select.bootstrap4.min.css'|theme}}" rel="stylesheet"
    type="text/css" />

<link href="{{'assets/libs/select2/css/select2.min.css'|theme}}" rel="stylesheet" type="text/css">
{% endput %}

<div class="container-fluid">

    <!-- start page title -->
    <div class="row">
        <div class="col-12">
            <div class="page-title-box d-flex align-items-center justify-content-between">
                <h4 class="mb-0">Sargyt Maglumatlary</h4>

            </div>
        </div>
    </div>
    <!-- end page title -->

    <div class="row">
        <div class="col-12">
            <!-- Left sidebar -->
            <div class="email-leftbar card">
                {% partial "order/aside" active=1 orderId=orderId %}
            </div>
            <!-- End Left sidebar -->


            <!-- Right Sidebar -->
            <div class="email-rightbar mb-3">
                <div class="row">
                    <div class="col-md-12">
                        <div class="collapse multi-collapse" id="multiCollapseExample1">
                            <form data-request="onCreateOrderItem" data-request-flash data-request-validate>
                                <div class="card">
                                    <div class="card-body">
                                        <div class="row">
                                            <div class="col">
                                                <label class="form-label">Haryt Görnüşi</label>
                                                <select class="form-control select2" name="order_item_type" id="order_item_type" onchange="setFields(this.value);">
                                                    <option value="rulon" selected>Rulon</option>
                                                    <option value="bag">Halta</option>
                                                </select>
                                            </div>

                                            <div class="col" id="bag_gram">
                                                <label class="form-label">Halta Gramy (gr)</label>
                                                <input type="number" name="bag_gram" step="0.01" class="form-control"
                                                placeholder="Halta Gramy" value="0">
                                            </div>

                                            <div class="col" id="bag_width">
                                                <label class="form-label">Halta Ini</label>
                                                <input type="number" name="bag_width" step="0.01" class="form-control"
                                                placeholder="Halta Ini" value="0">
                                            </div>

                                            <div class="col" id="bag_height">
                                                <label class="form-label">Halta Boýy</label>
                                                <input type="number" name="bag_height" step="0.01" class="form-control"
                                                placeholder="Halta Boýy" value="0">
                                            </div>


                                            <div class="col" id="rulon_size">
                                                <label class="form-label">Rulon Ölçegi</label>
                                                <input type="number" name="width" class="form-control"
                                                placeholder="Rulon Ölçegi" value="0">
                                            </div>

                                            <div class="col" id="rulon_gram">
                                                <label class="form-label">Rulon Gram m2</label>
                                                <input type="number" name="rulon_gram" class="form-control"
                                                placeholder="Rulon Ölçegi" value="0">
                                            </div>

                                            <div class="col" id="rulon_layer">
                                                <label class="form-label">Rulon gaty</label>
                                                <select class="form-control select2" name="rulon_layer">
                                                    <option value="1" selected>1 gat</option>
                                                    <option value="2">2 gat</option>
                                                </select>
                                            </div>

                                            <div class="col" id="rulon_type">
                                                <label class="form-label">Görnüş Saýlaň</label>
                                                <select class="form-control select2" name="type_id">
                                                    <option value="0">Saýla</option>
                                                    {% for type in types %}
                                                    <option value="{{type.id}}">{{type.name}}</option>
                                                    {% endfor %}
                                                </select>
                                            </div>

                                            <div class="col">
                                                <label class="form-label">Reňk Saýlaň</label>
                                                <select class="form-control select2" name="color_id">
                                                    <option value="0">Saýla</option>
                                                    {% for color in colors %}
                                                    <option value="{{color.id}}">{{color.name}}</option>
                                                    {% endfor %}
                                                </select>
                                            </div>

                                            <div class="col">
                                                <div>
                                                    <label class="form-label">Bahasy</label>
                                                    <input type="number" name="price" step="0.0001" class="form-control"
                                                        placeholder="Bahasy">
                                                </div>
                                            </div>

                                            <div class="col">
                                                <div>
                                                    <label class="form-label">Mukdary</label>
                                                    <input type="number" name="amount" step="0.01" class="form-control"
                                                        placeholder="Mukdary">
                                                </div>
                                            </div>

                                            <div class="col">
                                                <div>
                                                    <label class="form-label">Bellik</label>
                                                    <input type="text" name="note" class="form-control"
                                                        placeholder="Bellik">
                                                </div>
                                            </div>


                                            <div class="col">
                                                <button type="submit" class="btn btn-primary waves-effect waves-light"
                                                    style="margin-top: 30px;width: 100%;">Goş</button>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

                </div>

                {% partial "order/item_header" contract_no=order.contract_no orderId=order.id clientName=order.client.name
                allAmount=order.order_all_amount allPrice=order.order_all_price all=sumOfPrice %}

                <div class="card">

                    <div class="card-body">

                        <div class="row">
                            <div class="col-md-6">
                                <h3 class="card-title" style="font-size: 22px;color: #1e2038;">Sargytlar</h3>
                                <p class="card-title-desc" style="color: #6c6ff5;">Hasabat</p>
                            </div>
                            <div class="col-md-6" style="text-align: right;">
                                {% if order.user_id == user.id %}
                                <a class="btn btn-primary" data-bs-toggle="collapse" href="#multiCollapseExample1"
                                    role="button" aria-expanded="false" aria-controls="multiCollapseExample1">Haryt
                                    Goş</a>
                                {% endif %}
                            </div>
                        </div>


                        <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap"
                            style="border-collapse: collapse; border-spacing: 0; width: 100%;" data-page-length='13'>
                            <thead>
                                <tr>
                                    <th rowspan="2" style="width: 5%;">№</th>
                                    <th colspan="2" style="background: #ccd9e3;">Haryt Maglumatlary</th>
                                    <th colspan="3" style="background: #c7e4fd;">Haryt Bahasy</th>
                                    <th colspan="2" style="background: #ffbbbb;">Sklad Hasaplamasy</th>
                                    <th colspan="2" style="background: peachpuff !important;">Logistika</th>
                                    <th rowspan="2">Bellik</th>
                                    <th rowspan="2">POZ</th>
                                </tr>
                                <tr>
                                    <th>Görnüş</th>
                                    <th>Razmer</th>
                                    <th>Bahasy</th>
                                    <th>Mukdary</th>
                                    <th>Jemi</th>
                                    <th>SKLATDA</th>
                                    <th>Sklatda Ýetmezçilik</th>
                                    <th>ÝÜKLENEN</th>
                                    <th>Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% component 'orderItem' %}
                            </tbody>
                            <tfoot>
                                <tr>
                                    <th style="width: 5%;">№</th>
                                    <th style="background: #ccd9e3;">Görnüş</th>
                                    <th style="background: #ccd9e3;">Razmer</th>
                                    <th style="background: #c7e4fd;">Bahasy</th>
                                    <th style="background: #c7e4fd;">Mukdary</th>
                                    <th style="background: #c7e4fd;">Jemi</th>
                                    <th style="background: #ffbbbb;">SKLATDA</th>
                                    <th style="background: #ffbbbb;">Sklatda Ýetmezçilik</th>
                                    <th style="background: peachpuff !important;">ÝÜKLENEN</th>
                                    <th style="background: peachpuff !important;">Status</th>
                                    <th>Bellik</th>
                                    <th>POZ</th>
                                </tr>
                            </tfoot>
                        </table>
                    </div>

                    <div class="modal fade bs-example-modal-sm-1" tabindex="-1" role="dialog"
                        aria-labelledby="mySmallModalLabel" aria-hidden="true">
                        <div class="modal-dialog modal-sm">
                            <div class="modal-content" id="modal-form">



                            </div>
                        </div>
                    </div>

                </div> <!-- card -->

            </div>

        </div>
    </div>
    <!-- End row -->
</div>


{% put scripts %}

<script>

    var typeq = $('#order_item_type').val();
    setFields(typeq);

    function setFields(orderType){

        if(orderType == 'rulon'){
            $("#rulon_type").show();
            $("#rulon_size").show();
            $("#rulon_gram").show();
            $("#rulon_layer").show();

            $("#bag_width").hide();
            $("#bag_height").hide();
            $("#bag_gram").hide();
        }else{
            $("#bag_width").show();
            $("#bag_height").show();
            $("#bag_gram").show();

            $("#rulon_size").hide();
            $("#rulon_gram").hide();
            $("#rulon_layer").hide();

        }
    }
</script>

<script src="{{'assets/libs/select2/js/select2.min.js'|theme}}"></script>
<script src="{{'assets/js/pages/form-advanced.init.js'|theme}}"></script>

{% endput %}
{% partial 'dataTableJs' %}
