title = "Machine production by mechanic"
url = "/machine-production-mechanic/:month"
layout = "platform_main"
is_hidden = 0
==
<?php
function onStart() {
    $currentDate = Carbon\Carbon::now()->timezone('UTC +05:00');
    $this["month"] = $this->param("month");
    $year = $this->param("year");


    if($this["month"] == 'default'){
        $this["month"] = $currentDate->month;
    }

    if($year){
        $this["machineProductions"] = Romanah\Gokbakja\Models\ProductionMachine::whereMonth('created_at', $this["month"])->whereYear('created_at', $year)->groupBy("mechanic_id")->get();

        $this["month_all_amount"] = Romanah\Gokbakja\Models\ProductionMachine::whereMonth('created_at', $this["month"])
                                ->whereYear('created_at', $year)
                                ->sum('produced_weight');
    }else{
        $this["machineProductions"] = Romanah\Gokbakja\Models\ProductionMachine::whereMonth('created_at', $this["month"])->whereYear('created_at', $currentDate->year)->groupBy("mechanic_id")->addSelect(DB::raw("*, SUM(produced_weight) as produced_weight"))->get();

        $this["month_all_amount"] = Romanah\Gokbakja\Models\ProductionMachine::whereMonth('created_at', $this["month"])
                                ->whereYear('created_at', $currentDate->year)
                                ->sum('produced_weight');
    }
}
?>
==
{% 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" />
{% 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">Aýlar Boýunça {{year}}</h4>

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

    <div class="row">
        <div class="col-12">
            <!-- Left sidebar -->
            <div class="email-leftbar card">
                <a href="/machine" type="button" class="btn btn-danger waves-effect waves-light">
                    Täze Hasabat
                </a>
                <div class="mail-list mt-4">
                    <a href="/machine-production-mechanic/1" class="{{ month == 1 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Ýanwar</a>
                    <a href="/machine-production-mechanic/2" class="{{ month == 2 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Fewral</a>
                    <a href="/machine-production-mechanic/3" class="{{ month == 3 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Mart</a>
                    <a href="/machine-production-mechanic/4" class="{{ month == 4 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Aprel</a>
                    <a href="/machine-production-mechanic/5" class="{{ month == 5 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Maý</a>
                    <a href="/machine-production-mechanic/6" class="{{ month == 6 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Iýun</a>
                    <a href="/machine-production-mechanic/7" class="{{ month == 7 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Iýul</a>
                    <a href="/machine-production-mechanic/8" class="{{ month == 8 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Awgust</a>
                    <a href="/machine-production-mechanic/9" class="{{ month == 9 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Sentýabr</a>
                    <a href="/machine-production-mechanic/10" class="{{ month == 10 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Oktýabr</a>
                    <a href="/machine-production-mechanic/11" class="{{ month == 11 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Noýabr</a>
                    <a href="/machine-production-mechanic/12" class="{{ month == 12 ? 'active' : '' }}"><i
                            class="mdi mdi-archive me-2 font-size-16"></i> Dekabr</a>

                </div>



            </div>
            <!-- End Left sidebar -->


            <!-- Right Sidebar -->
            <div class="email-rightbar mb-3">

                <div class="card">




                    <div class="card-body">
                        <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='80'>
                            <thead>
                                <tr>
                                    <th style="width: 5%;">№</th>
                                    <th>Mehanik</th>
                                    <th>Önen Önüm</th>
                                    <!--  <th>Настройки</th> -->
                                </tr>
                            </thead>
                            <tbody>

                                {% for key, machine in machineProductions %}
                                <tr>
                                    <td style="font-weight: bold;">{{key + 1}}</td>
                                    <td><a href="/get-mechanic/{{machine.mechanic.id}}/{{month}}" style="font-weight: bold;">{{machine.mechanic.name}}</a></td>
                                    <td>{{machine.produced_weight|number_format}} kg</td>
                                </tr>
                                {% endfor %}




                            </tbody>
                            <tfoot>
                                <tr>
                                    <th style="width: 5%;">№</th>
                                    <th>Mehanik</th>
                                    <th>Önen Önüm</th>
                                </tr>
                            </tfoot>
                        </table>

                    </div>

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

            </div>

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


{% partial 'dataTableJs' %}