g_sto/themes/gokbakja/pages/actions/rulon-report.htm

295 lines
12 KiB
HTML

title = "actions/rulon-report"
url = "/actions/rulon-report/:month/:year?"
layout = "platform_main"
is_hidden = 0
==
<?php
function onStart() {
$currentDate = Carbon\Carbon::now();
$this["month"] = $this->param("month");
$year = $this->param("year");
if($this["month"] == 'default'){
$this["month"] = $currentDate->month;
}
//dd($reportDatas);
if($year){
$startDate = Carbon\Carbon::create($year, $this["month"], 1);
$endDate = $startDate->endOfMonth();
$formattedStartDate = $startDate->format('Y-m-d');
$formattedEndDate = $endDate->format('Y-m-d');
$reportDatas = [];
//dd($action);
//$action = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
//->join('romanah_gokbakja_production_machine', 'romanah_gokbakja_rulon_action.product_id', 'romanah_gokbakja_production_machine.id')
//->where('romanah_gokbakja_production_machine.date', '<', $formattedStartDate)
//->addSelect('romanah_gokbakja_production_machine.width', 'romanah_gokbakja_production_machine.gram')
//->groupBy('romanah_gokbakja_production_machine.width')
//->groupBy('romanah_gokbakja_production_machine.gram')
//->addSelect(DB::raw('SUM(romanah_gokbakja_rulon_action.amount) as startDateSum'))
//->orderBy('romanah_gokbakja_production_machine.width', 'ASC')
//->get()->toArray();
$rulonProds = Romanah\Gokbakja\Models\ProductionMachine::select('gram', 'width')
->whereMonth('date', $this["month"])
->whereYear('date', $year)
->groupBy('gram')->groupBy('width')
->orderBy('width', 'ASC')
->distinct()
->get();
for ($x = 0; $x < count($rulonProds); $x++) {
$action = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->whereHas('product', function($qq) use($rulonProds, $x, $formattedStartDate, $formattedEndDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->where('date', '<', $formattedStartDate);
})
->sum('amount');
$endAction = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->whereHas('product', function($qq) use($rulonProds, $x, $formattedStartDate, $formattedEndDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->where('date', '<', $formattedStartDate);
})
->sum('amount');
$actionIn = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->where('type', 'inbox')
->whereHas('product', function($qq) use($rulonProds, $x, $year, $formattedStartDate, $formattedEndDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->where('date', '<', $formattedStartDate);
})
->sum('amount');
$actionOut = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->where('type', 'outbox')
->whereHas('product', function($qq) use($rulonProds, $x, $year, $formattedStartDate, $formattedEndDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->where('date', '>', $formattedEndDate);
})
->sum('amount');
$reportDatas[$x]["gram"] = $rulonProds[$x]->gram;
$reportDatas[$x]["width"] = $rulonProds[$x]->width;
$reportDatas[$x]["start_month"] = $action;
$reportDatas[$x]["end_month"] = $endAction;
$reportDatas[$x]["in"] = $actionIn;
$reportDatas[$x]["out"] = $actionOut;
}
$this['reportDatas'] = $reportDatas;
}else{
$startDate = Carbon\Carbon::create($year, $this["month"], 1);
$endDate = $startDate->endOfMonth();
$formattedStartDate = $startDate->format('Y-m-d');
$formattedEndDate = $endDate->format('Y-m-d');
$reportDatas = [];
$rulonProds = Romanah\Gokbakja\Models\ProductionMachine::select('gram', 'width')
->whereMonth('date', $this["month"])
->whereYear('date', $currentDate->year)
->groupBy('gram')->groupBy('width')
->orderBy('width', 'ASC')
->distinct()
->get();
for ($x = 0; $x < count($rulonProds); $x++) {
$action = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->whereHas('product', function($qq) use($rulonProds, $x, $formattedStartDate, $formattedEndDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->where('date', '<', $formattedStartDate);
})
->sum('amount');
$endAction = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->whereHas('product', function($qq) use($rulonProds, $x, $formattedStartDate, $formattedEndDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->where('date', '>', $formattedEndDate);
})
->sum('amount');
$actionIn = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->where('type', 'inbox')
->whereHas('product', function($qq) use($rulonProds, $x, $year, $formattedStartDate, $formattedEndDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->where('date', '<', $formattedStartDate);
})
->sum('amount');
$actionOut = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->where('type', 'outbox')
->whereHas('product', function($qq) use($rulonProds, $x, $year, $formattedStartDate, $formattedEndDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->where('date', '>', $formattedEndDate);
})
->sum('amount');
$reportDatas[$x]["gram"] = $rulonProds[$x]->gram;
$reportDatas[$x]["width"] = $rulonProds[$x]->width;
$reportDatas[$x]["start_month"] = $action;
$reportDatas[$x]["end_month"] = $endAction;
$reportDatas[$x]["in"] = $actionIn;
$reportDatas[$x]["out"] = $actionOut;
}
$this['reportDatas'] = $reportDatas;
}
}
?>
==
{% 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">
<div class="mail-list mt-4">
<a href="/actions/rulon-report/1" class="{{ month == 1 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Ýanwar</a>
<a href="/actions/rulon-report/2" class="{{ month == 2 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Fewral</a>
<a href="/actions/rulon-report/3" class="{{ month == 3 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Mart</a>
<a href="/actions/rulon-report/4" class="{{ month == 4 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Aprel</a>
<a href="/actions/rulon-report/5" class="{{ month == 5 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Maý</a>
<a href="/actions/rulon-report/6" class="{{ month == 6 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Iýun</a>
<a href="/actions/rulon-report/7" class="{{ month == 7 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Iýul</a>
<a href="/actions/rulon-report/8" class="{{ month == 8 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Awgust</a>
<a href="/actions/rulon-report/9" class="{{ month == 9 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Sentýabr</a>
<a href="/actions/rulon-report/10" class="{{ month == 10 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Oktýabr</a>
<a href="/actions/rulon-report/11" class="{{ month == 11 ? 'active' : '' }}"><i
class="mdi mdi-archive me-2 font-size-16"></i> Noýabr</a>
<a href="/actions/rulon-report/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>Gram</th>
<th>Ini</th>
<th>Aýyň Başyna</th>
<th>Gelen</th>
<th>Giden</th>
<th>Aýyň Soňuna</th>
<!-- <th>Настройки</th> -->
</tr>
</thead>
<tbody>
{% for key, report in reportDatas %}
<tr>
<td style="font-weight: bold;">{{key + 1}}</td>
<td><a href="#" style="font-weight: bold;">{{report.gram}}</a></td>
<td>{{report.width}}</td>
<td>{{report.start_month}}</td>
<td style="color: darkgreen;">{{report.in}}</td>
<td style="color: darkred;">{{report.out}}</td>
<td>{{report.end_month}}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th style="width: 5%;"></th>
<th>Gram</th>
<th>Ini</th>
<th>Aýyň Başyna</th>
<th>Gelen</th>
<th>Giden</th>
<th>Aýyň Soňuna</th>
</tr>
</tfoot>
</table>
</div>
</div> <!-- card -->
</div>
</div>
</div>
<!-- End row -->
</div>
{% partial 'dataTableJs' %}