diff --git a/plugins/romanah/gokbakja/components/Production.php b/plugins/romanah/gokbakja/components/Production.php index c9d718c..15bded0 100644 --- a/plugins/romanah/gokbakja/components/Production.php +++ b/plugins/romanah/gokbakja/components/Production.php @@ -5,12 +5,14 @@ namespace Romanah\Gokbakja\Components; use Cms\Classes\ComponentBase; use Romanah\Gokbakja\Models\Product as ProductModel; use Romanah\Gokbakja\Models\Production as ProductionModel; +use Romanah\Gokbakja\Models\Excruiter as ExcruiterModel; use Romanah\Gokbakja\Models\ProductionMachine as ProductionMachineModel; use Romanah\Gokbakja\Models\PivotProduction as PivotProductionModel; use Redirect; use Carbon\Carbon; use Flash; use DB; +use October\Rain\Support\Facades\Flash as FacadesFlash; class Production extends ComponentBase { @@ -25,6 +27,76 @@ class Production extends ComponentBase } + public function onReportProduction() + { + + $currentDate = Carbon::now()->timezone('UTC +05:00'); + $currentDateFormat = $currentDate->format('Y-m-d'); + + $data = post(); + + + $productions = ProductionModel::with(['pivot_production', 'excruiter', 'shift'])->orderBy('id', 'DESC'); + + $start = Carbon::parse($data["start"])->format('Y-m-d'); + $end = Carbon::parse($data["end"])->format('Y-m-d'); + + $startView = Carbon::parse($data["start"])->format('d.m.Y'); + $endView = Carbon::parse($data["end"])->format('d.m.Y'); + + $excruiter = $data["excruiter_id"]; + $shiftId = $data["shift_id"]; + + + if ($excruiter) { + $productions->where("excruiter_id", $excruiter); + } + + if ($shiftId) { + $productions->where("shift_id", $shiftId); + } + + if ($start != $currentDateFormat) { + $productions->whereBetween('created_at', [$start, $end]); + } + + $productionsFiltered = $productions->get(); + + $html_data = ''; + for ($x = 0; $x < count($productionsFiltered); $x++) { + // dd($productionsFiltered[0]->shift->desc); + $html_data .= ' + ' . ($x + 1) . ' + ' . $productionsFiltered[$x]->created_at->format("d.m.Y | H:i") . ' + ' . $productionsFiltered[$x]->shift->desc . ' + + ' . $productionsFiltered[$x]->excruiter->name . ' + + + ' . number_format($productionsFiltered[$x]->all_amount) . ' kg + '; + + + for ($i = 0; $i < count($productionsFiltered[$x]->pivot_production); $i++) { + $html_data .= ' '.number_format($productionsFiltered[$x]->pivot_production[$i]->amount_percentage).'%'; + } + + $html_data .= '' . $productionsFiltered[$x]->note . ' + '; + } + + if ($productionsFiltered) { + return [ + '#production_report_datas' => $html_data, + '#exampleModalFullscreenLabel' => ''. $startView .' - '. $endView .' seneleri aralygynda güni jemi', + ]; + } else { + Flash::error("Yalnyshlyk bar!!"); + } + } + public function onCalculateReportDaily() { @@ -37,7 +109,7 @@ class Production extends ComponentBase $excruiter = $this->param("excruiter"); - $currentDateLast = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $excruiter)->orderBy('id', 'DESC')->first(); + $currentDateLast = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $excruiter)->with("excruiter")->orderBy('id', 'DESC')->first(); $currentDateFirst = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $excruiter)->orderBy('id', 'ASC')->first(); $diffMinutes = Carbon::parse($currentDateLast->time)->diffInMinutes($currentDateFirst->time); @@ -58,48 +130,233 @@ class Production extends ComponentBase $allData = array( "all" => array( - "hours" => floor($diffMinutes / 60).' sagat '.($diffMinutes - floor($diffMinutes / 60) * 60).' minut', + "hours" => floor($diffMinutes / 60) . ' sagat ' . ($diffMinutes - floor($diffMinutes / 60) * 60) . ' minut', "avg_all_amount" => number_format($currentDateProductionAll, 2), ) ); $producedAll = $currentDateLast->all_amount - $currentDateFirst->all_amount; - $html_data = '
'; - $html_data .= '

IŞLENEN ÇIG MAL

'; + $countDailyChanges = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $excruiter)->get(); - $html_data .= '
+ // dd(count($countDailyChanges)); + + if (count($countDailyChanges) > 1) { + // gunluk hasabat + $html_data = '
'; + $html_data .= '

JEMI IŞLENEN ÇIG MAL (ekskruiter: ' . $currentDateLast->excruiter->name . ')

'; + + $html_data .= ''; - for ($x = 0; $x < count($pivotLasts); $x++) { - $diff = $pivotLasts[$x]->amount - $pivotFirsts[$x]->amount; - $diffPerc = ($diff * 100) / $producedAll; + for ($x = 0; $x < count($pivotLasts); $x++) { + // $diff = $pivotLasts[$x]->amount - $pivotFirsts[$x]->amount; + // $diffPerc = ($diff * 100) / $producedAll; + $calculatedPercentage = (float) ($pivotLasts[$x]->amount_percentage / 100) * (float) $producedAll; - $html_data .= ''; + + $hourCount = floor($diffMinutes / 60) . '.' . ($diffMinutes - floor($diffMinutes / 60) * 60); + $avgProducedHour = $producedAll / $hourCount; + + + + // sagatda ortacha hasbat + $html_data2 = '
'; + $html_data2 .= '

SAGATDA ORTAÇA SARP EDIŞ HASABATY (ekskruiter: ' . $currentDateLast->excruiter->name . ')

'; + + $html_data2 .= ''; + + for ($x = 0; $x < count($pivotLasts); $x++) { + // $diff = $pivotLasts[$x]->amount - $pivotFirsts[$x]->amount; + // $diffPerc = ($diff * 100) / $producedAll; + $calculatedPercentage = (float) ($pivotLasts[$x]->amount_percentage / 100) * (float) $producedAll; + $calculatePercentageHour = (float) (($calculatedPercentage / $hourCount) * 100) / (float) $producedAll; + + $html_data2 .= ''; + } + + $html_data2 .= '
'; + + + $html_data3 = ''; + + $currentDateExcruiters = ProductionModel::whereDate('created_at', date($currentDateFormat))->groupBy("excruiter_id")->orderBy('id', 'DESC')->with("excruiter")->get(); + + + for ($i = 0; $i < count($currentDateExcruiters); $i++) { + + $currentDateLastExc = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $currentDateExcruiters[$i]->excruiter_id)->orderBy('id', 'DESC')->first(); + + $currentDateFirstExc = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('excruiter_id', $currentDateExcruiters[$i]->excruiter_id)->orderBy('id', 'ASC')->first(); + + $diffMinutesExc = Carbon::parse($currentDateLastExc->time)->diffInMinutes($currentDateFirstExc->time); + + $hourCountExc = floor($diffMinutesExc / 60) . ' sagat ' . ($diffMinutesExc - floor($diffMinutesExc / 60) * 60) . ' minut'; + + $allAmountExc = $currentDateLastExc->all_amount - $currentDateFirstExc->all_amount; + + // dd($currentDateFirstExc); + $html_data3 .= '
'; + $html_data3 .= '

' . $currentDateExcruiters[$i]->excruiter->name . ' - işlenen çig mallar boýunça.

'; + + + $html_data3 .= ''; + + $excruiterDatas = PivotProductionModel::where('production_id', $currentDateLastExc->id)->get(); + // $pivotLasts = PivotProductionModel::where('production_id', $currentDateLast->id)->get(); + + // \Log::info($excruiterDatas); + for ($ii = 0; $ii < count($excruiterDatas); $ii++) { + // $diff = $pivotLasts[$x]->amount - $pivotFirsts[$x]->amount; + // $diffPerc = ($diff * 100) / $producedAll; + $calculatedPercentage = (float) ($excruiterDatas[$ii]->amount_percentage / 100) * (float) $allAmountExc; + + $html_data3 .= ''; + } + $html_data3 .= '

'; + } + + // } + + $currentDateShifts = ProductionModel::whereDate('created_at', date($currentDateFormat)) + ->where("excruiter_id", $excruiter) + ->with(["shift", "excruiter", "pivot_production"]) + ->orderBy('id', 'ASC') + ->groupBy("shift_id") + ->get(); + + // $products = ProductModel::where("report", "simple")->get(); + + + $html_data4 = '

SMENLAR BOÝUNÇA

'; + $html_data4 .= '
'; + + $html_data4 .= ' + + + + + + + + + '; + for ($ii = 0; $ii < count($currentDateShifts[0]->pivot_production); $ii++) { + $html_data4 .= ''; + } + $html_data4 .= ' + '; + + + + for ($i = 0; $i < count($currentDateShifts); $i++) { + + $pivotShiftLasts = PivotProductionModel::where('production_id', $currentDateShifts[$i]->id)->get(); + + $currentDateLastShift = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('shift_id', $currentDateShifts[$i]->shift_id)->where('excruiter_id', $currentDateShifts[$i]->excruiter_id)->with('excruiter')->orderBy('id', 'DESC')->first(); + + $currentDateFirstShift = ProductionModel::whereDate('created_at', date($currentDateFormat))->where('shift_id', $currentDateShifts[$i]->shift_id)->where('excruiter_id', $currentDateShifts[$i]->excruiter_id)->orderBy('id', 'ASC')->first(); + + $diffMinutesShift = Carbon::parse($currentDateLastShift->time)->diffInMinutes($currentDateFirstShift->time); + + $hourCountShift = floor($diffMinutesShift / 60) . ' sagat ' . ($diffMinutesShift - floor($diffMinutesShift / 60) * 60) . ' minut'; + + $hourCountShiftCalc = floor($diffMinutesShift / 60) . '.' . ($diffMinutesShift - floor($diffMinutesShift / 60) * 60); + + $allAmountShift = $currentDateLastShift->all_amount - $currentDateFirstShift->all_amount; + + $html_data4 .= ' + + + + + '; + + + for ($x = 0; $x < count($pivotShiftLasts); $x++) { + + $calculatedPercentageShift = (float) ($pivotShiftLasts[$x]->amount_percentage / 100) * (float) $allAmountShift; + + $html_data4 .= ''; + } + + + $html_data4 .= ''; + } + + $html_data4 .= ' +
#SmenEkskruiterWagtyJemi' . $currentDateShifts[0]->pivot_production[$ii]->product_name . '
' . ($i + 1) . '' . $currentDateShifts[$i]->shift->desc . '(' . $currentDateShifts[$i]->shift->start . ' - ' . $currentDateShifts[$i]->shift->end . ')' . $currentDateLastShift->excruiter->name . '' . $hourCountShift . '' . $allAmountShift . ' kg' . ($calculatedPercentageShift) . ' kg
'; + + return [ + '#calculation_of_day' => $html_data, + '#avg_of_day' => $html_data2, + '#excruiter_daily_report' => $html_data3, + '#shift_daily_report' => $html_data4 + ]; + } else { + + return [ + '#calculation_of_day' => 'Gunluk Hasabat üçin 2-nji üýtgeşmeleri girizmeli!', + '#excruiter_daily_report' => 'Gunluk Hasabat üçin 2-nji üýtgeşmeleri girizmeli!', + '#shift_daily_report' => 'Gunluk Hasabat üçin 2-nji üýtgeşmeleri girizmeli!' + ]; } - - $html_data .= '
'; - - return [ - '#calculation_of_day' => $html_data - ]; - } @@ -180,7 +437,6 @@ class Production extends ComponentBase Flash::success("Hasabat Ustunlikli Üýtgedildi"); return Redirect::refresh(); } - } public function onCreateProduction() diff --git a/themes/gokbakja/pages/production/production.htm b/themes/gokbakja/pages/production/production.htm index d6b4091..e0e351d 100644 --- a/themes/gokbakja/pages/production/production.htm +++ b/themes/gokbakja/pages/production/production.htm @@ -202,7 +202,7 @@ function onStart(){ {% for product in report.pivot_production %} {{product.amount_percentage|number_format(2)}} - % {{product.amount}} + % @@ -240,8 +240,8 @@ function onStart(){ {% endfor %} - - + + @@ -358,4 +358,4 @@ function onStart(){ -{% endput %} \ No newline at end of file +{% endput %} diff --git a/themes/gokbakja/pages/production/report-dynamic.htm b/themes/gokbakja/pages/production/report-dynamic.htm index 800cdf9..a05a411 100644 --- a/themes/gokbakja/pages/production/report-dynamic.htm +++ b/themes/gokbakja/pages/production/report-dynamic.htm @@ -2,6 +2,18 @@ title = "production/report-dynamic" url = "/production/report-dynamic" layout = "platform_main" is_hidden = 0 + +[builderList] +modelClass = "Romanah\Gokbakja\Models\Product" +scope = "scopeGetReport" +scopeValue = "{{ :scope }}" +displayColumn = "id" +noRecordsMessage = "No records found" +detailsPage = "-" +detailsUrlParameter = "id" +pageNumber = "{{ :page }}" + +[production] == == + +{% set records = builderList.records %} +{% set displayColumn = builderList.displayColumn %} +{% set noRecordsMessage = builderList.noRecordsMessage %} +{% set detailsPage = builderList.detailsPage %} +{% set detailsKeyColumn = builderList.detailsKeyColumn %} +{% set detailsUrlParameter = builderList.detailsUrlParameter %} + + {% put styles %} @@ -17,7 +38,7 @@ function onStart(){ type="text/css" /> - + {% endput %} @@ -27,43 +48,48 @@ function onStart(){
-
-
-
- +
+
+
+
+ -
- - +
+ + +
-
-
- - -
-
- - -
-
- -
+
+ + +
+
+ + +
+
+ +
-
+
+
@@ -75,38 +101,39 @@ function onStart(){
-

Çig Mallar Boýunça Umumy - ({{year}} ýyl)

+

Çig Mallar Boýunça Umumy

Hasabat

- +
+ {% partial "production/modal-report" %} - - - {% for key, record in reportProducts %} + + + + + {% for key, record in records %} {% endfor %} - + + - {% partial 'report/row' products=reportProducts title="Ýanwar" no=1 %} @@ -114,11 +141,14 @@ function onStart(){ + + - {% for key, record in reportProducts %} + {% for key, record in records %} {% endfor %} +
AýlarOrtaça IşlenenSenesiSmenEkskruiterHemmesi{{record.name}}Bellik
SenesiSmenEkskruiter Hemmesi{{record.name}}Bellik
@@ -138,4 +168,4 @@ function onStart(){ -{% endput %} \ No newline at end of file +{% endput %} diff --git a/themes/gokbakja/partials/production/modal-report.htm b/themes/gokbakja/partials/production/modal-report.htm new file mode 100644 index 0000000..a6963f4 --- /dev/null +++ b/themes/gokbakja/partials/production/modal-report.htm @@ -0,0 +1,81 @@ +[viewBag] +== + + diff --git a/themes/gokbakja/partials/production/modal.htm b/themes/gokbakja/partials/production/modal.htm index 043bc0d..f71485a 100644 --- a/themes/gokbakja/partials/production/modal.htm +++ b/themes/gokbakja/partials/production/modal.htm @@ -1,16 +1,16 @@ [viewBag] == -