title = "machine/rulon-bags"
url = "/machine/rulon-bags/:filter"
layout = "platform_main"
is_hidden = 0
==
<?php
function onStart(){
    $filter = $this->param('filter');

    $this["rulons"] = Romanah\Gokbakja\Models\BagAction::select('romanah_gokbakja_bag_actions.*')
                        ->with(['product.rulon_action.product.bag_type', 'product.rulon_action.product.color', 'product.pivot_sewer', 'product.pivot_sewer_lst'])
                        ->whereHas('product', function($q){
                            $q->where('is_sewed', 1);
                        })
                        ->groupBy('romanah_gokbakja_bag_actions.product_id')
                        ->orderBy('id', 'DESC')
                        ->get();

    if($filter == 'filter'){


        $start = Carbon\Carbon::parse(post("start"))->format('Y-m-d');
        $end = Carbon\Carbon::parse(post("end"))->format('Y-m-d');

        $this["rulons"] = Romanah\Gokbakja\Models\BagAction::select('romanah_gokbakja_bag_actions.*')
                        ->with(['product.rulon_action.product.bag_type', 'product.rulon_action.product.color', 'product.pivot_sewer', 'product.pivot_sewer_lst', 'product.rulon_action.product'])
                        ->whereHas('product', function($q){
                            $q->where('is_sewed', 1);
                        })
                        ->whereHas('product.rulon_action.product', function($qq) use ($start, $end){
                            $qq->whereBetween('date', [$start, $end]);
                        })
                        ->orderBy('id', 'DESC')
                        ->groupBy('romanah_gokbakja_bag_actions.product_id')
                        ->get();

    }


    //dd($this["rulons"]);
}
?>
==
{% set records = builderList.records %}
{% set displayColumn = builderList.displayColumn %}
{% set noRecordsMessage = builderList.noRecordsMessage %}
{% set detailsPage = builderList.detailsPage %}
{% set detailsKeyColumn = builderList.detailsKeyColumn %}
{% set detailsUrlParameter = builderList.detailsUrlParameter %}

{% set machines = builderList2.records %}
{% set types = builderList4.records %}
{% set sizes = builderList3.records %}

{% 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">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-body">
                    <form action="/machine/rulon-bags/filter" method="POST">
                        <div class="row">

                            <div class="col">
                                <div>
                                    <label class="form-label">Seneleri Saýlaň</label>

                                    <div class="input-daterange input-group" id="datepicker6"
                                        data-date-format="d.m.yyyy" data-date-autoclose="true" data-provide="datepicker"
                                        data-date-container='#datepicker6'>
                                        <input type="text" class="form-control" name="start"
                                            placeholder="Başlanýan sene" />
                                        <input type="text" class="form-control" name="end"
                                            placeholder="Gutarýan sene" />
                                    </div>
                                </div>
                            </div>


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

                        </div>
                    </form>

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

    </div>
    <div class="row">


    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-body">
                    <div class="row" id="all_amount">
                        <div class="col-md-6">
                            <h3 class="card-title" style="font-size: 22px;color: #1e2038;">Rulon Halta</h3>
                            <p class="card-title-desc" style="color: #6c6ff5;">Hasabat</p>
                        </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 colspan="7" style="background: #ccd9e3;">Gelen Rulon</th>
                                <th colspan="3" style="background: #c7e4fd;">Öndürlen Halta</th>
                                <th colspan="3" style="background: bisque;">Halta Sany</th>
                                <th colspan="2" style="background: #ffbbbb;">Jemi Öndürlen Halta</th>
                                <th>Turba agramy</th>
                                <th>Rulon Galyndysy</th>
                                <th rowspan="2">Brak %</th>
                            </tr>
                            <tr>

                                <th>NO</th>
                                <th>Sene</th>
                                <th>Stanok No</th>
                                <th>Reňki</th>
                                <th>Ini</th>
                                <th>Gram m2</th>
                                <th>Rulanyň agramy (kg)</th>

                                <th>Gramy</th>
                                <th>Ini</th>
                                <th>Boýy</th>

                                <th>Öndürlen Halta (arassa)</th>
                                <th>Öndürlen Halta (brak)</th>
                                <th>Sürülmedik</th>

                                <th>Sany</th>
                                <th>kg</th>

                                <th>kg</th>
                                <th>kg</th>

                                <!--  <th>Настройки</th> -->
                            </tr>
                        </thead>
                        <tbody>
                            {% set allCalc = 0 %}
                            {% set allCalcDefective = 0 %}
                            {% set allCalcDefectiveRep = 0 %}
                            {% set allCalcAmount = 0 %}
                            {% set allCalcKg = 0 %}
                            {% set pipeAllCalc = 0 %}
                            {% set allLeft = 0 %}
                            {% set allBrakPerc = 0 %}

                            {% for key, report in rulons %}

                                {% set sumOfBags = (report.amount + report.product.defective_bag_qty + report.product.defective_repair_qty) %}

                                {% set gramInkg = (report.product.bag_gram / 1000) %}

                                {% set allInKg = (sumOfBags * gramInkg) %}

                                {% set percentDefective = ((report.product.defective_bag_qty * 100) / sumOfBags) %}

                                {% set allCalc = (allCalc + report.amount) %}

                                {% set allCalcDefective = (allCalcDefective + report.product.defective_bag_qty) %}

                                {% set allCalcDefectiveRep = (allCalcDefectiveRep + report.product.defective_repair_qty) %}

                                {% set allCalcAmount = (allCalcAmount + sumOfBags) %}

                                {% set allCalcKg = (allCalcKg + allInKg) %}

                                {% set pipeAllCalc = (pipeAllCalc + report.product.pipe_weight) %}

                                {% set allLeft = (allLeft + report.product.pivot_sewer_lst.left_amount) %}

                                {% set allBrakPerc = (allBrakPerc + percentDefective) %}

                            <tr>
                                <td style="font-weight: bold;">{{key+1}}</td>
                                <td><a href="#" style="font-weight: bold;">{{report.product.rulon_action.product.date|date('d.m.Y')}}</a></td>
                                <td>{{report.product.rulon_action.product.machine.name}}</td>
                                <td>{{report.product.rulon_action.product.color.name}}</td>
                                <td>{{report.product.rulon_action.product.width}}</td>
                                <td>{{report.product.rulon_action.product.gram}}</td>
                                <td>{{report.product.rulon_action.product.brutto_kg}}</td>

                                <td>{{gramInkg}}</td>
                                <td>{{report.product.width|number_format}}</td>
                                <td>{{report.product.height|number_format}}</td>

                                <td><span class="badge badge-soft-success"
                                    style="font-size: 14px;">{{report.amount|number_format}}</span></td>
                                <td><span class="badge badge-soft-danger"
                                    style="font-size: 14px;">{{report.product.defective_bag_qty|number_format}}</span></td>
                                <td><span class="badge badge-soft-warning"
                                    style="font-size: 14px;">{{report.product.defective_repair_qty|number_format}}</span></td>

                                <td><span class="badge badge-soft-primary"
                                    style="font-size: 14px;">{{sumOfBags|number_format}}</span></td>
                                <td>{{allInKg|number_format}}</td>

                                <td>{{report.product.pipe_weight|number_format(2)}}</td>
                                <td>{{report.product.pivot_sewer_lst.left_amount|number_format(2)}}</td>

                                <td style="color: darkred;">{{percentDefective|number_format(2)}} %</td>
                            </tr>

                            {% endfor %}

                        </tbody>
                        <tfoot>
                            <tr>
                                <th colspan="10">JEMI</th>

                                <th>{{allCalc|number_format(2)}}</th>
                                <th>{{allCalcDefective|number_format(2)}}</th>
                                <th>{{allCalcDefectiveRep|number_format(2)}}</th>

                                <th>{{allCalcAmount|number_format(2)}}</th>
                                <th>{{allCalcKg|number_format(2)}}</th>

                                <th>{{pipeAllCalc|number_format(2)}}</th>
                                <th>{{allLeft|number_format(2)}}</th>

                                <th>{{allBrakPerc|number_format(2)}}</th>
                            </tr>
                        </tfoot>
                    </table>
                    <!-- <table class="table table-bordered dt-responsive nowrap">
                        <tfoot>
                            <tr>
                                <th>NO</th>
                                <th>Sene</th>
                                <th>Stanok No</th>
                                <th>Reňki</th>
                                <th>Ini</th>
                                <th>Gram m2</th>
                                <th>Rulanyň agramy (kg)</th>

                                <th>Gramy</th>
                                <th>Ini</th>
                                <th>Boýy</th>

                                <th>Öndürlen Halta (arassa)</th>
                                <th>Öndürlen Halta (brak)</th>
                                <th>Sürülmedik</th>

                                <th>Sany</th>
                                <th>kg</th>

                                <th>Turba Agramy</th>
                                <th>Rulon Galyndysy</th>

                                <th>Brak %</th>
                            </tr>
                        </tfoot>
                    </table> -->

                </div>

                <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog"
                    aria-labelledby="mySmallModalLabel" aria-hidden="true">
                    <div class="modal-dialog modal-lg" style="max-width: 1211px;">
                        <div class="modal-content" id="modal-form">



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

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


{% partial 'dataTableJs' %}
{% put scripts %}
<script src="{{'assets/libs/bootstrap-datepicker/js/bootstrap-datepicker.min.js'|theme}}"></script>
<script src="{{'assets/libs/select2/js/select2.min.js'|theme}}"></script>
<script src="{{'assets/js/pages/form-advanced.init.js'|theme}}"></script>
{% endput %}
