From 379ee8bf0724b53091a40c2364192b0c9caff37a Mon Sep 17 00:00:00 2001 From: Shohrat Date: Wed, 27 Dec 2023 15:23:59 +0500 Subject: [PATCH] new database --- .../gokbakja/pages/actions/rulon-report.htm | 81 +++++++++++++++---- 1 file changed, 67 insertions(+), 14 deletions(-) diff --git a/themes/gokbakja/pages/actions/rulon-report.htm b/themes/gokbakja/pages/actions/rulon-report.htm index 09392a5..cd5dc17 100644 --- a/themes/gokbakja/pages/actions/rulon-report.htm +++ b/themes/gokbakja/pages/actions/rulon-report.htm @@ -21,8 +21,28 @@ function onStart() { 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) @@ -35,16 +55,25 @@ function onStart() { $action = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*') ->with('product') - ->whereHas('product', function($qq) use($rulonProds, $x){ - $qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $year)->whereMonth('date', $this["month"]); + ->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){ - $qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $year)->whereMonth('date', $this["month"]); + ->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'); @@ -52,14 +81,17 @@ function onStart() { $actionOut = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*') ->with('product') ->where('type', 'outbox') - ->whereHas('product', function($qq) use($rulonProds, $x){ - $qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $year)->whereMonth('date', $this["month"]); + ->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; @@ -67,11 +99,17 @@ function onStart() { $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('created_at', $this["month"]) - ->whereYear('created_at', $currentDate->year) + ->whereMonth('date', $this["month"]) + ->whereYear('date', $currentDate->year) ->groupBy('gram')->groupBy('width') ->orderBy('width', 'ASC') ->distinct() @@ -81,16 +119,25 @@ function onStart() { $action = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*') ->with('product') - ->whereHas('product', function($qq) use($rulonProds, $x, $currentDate){ - $qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $currentDate->year)->whereMonth('date', $this["month"]); + ->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, $currentDate){ - $qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $currentDate->year)->whereMonth('date', $this["month"]); + ->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'); @@ -98,14 +145,17 @@ function onStart() { $actionOut = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*') ->with('product') ->where('type', 'outbox') - ->whereHas('product', function($qq) use($rulonProds, $x, $currentDate){ - $qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $currentDate->year)->whereMonth('date', $this["month"]); + ->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; @@ -194,6 +244,7 @@ function onStart() { Aýyň Başyna Gelen Giden + Aýyň Soňuna @@ -207,6 +258,7 @@ function onStart() { {{report.start_month}} {{report.in}} {{report.out}} + {{report.end_month}} {% endfor %} @@ -222,6 +274,7 @@ function onStart() { Aýyň Başyna Gelen Giden + Aýyň Soňuna