From c370c735e81e253c2faf2441d57aed831c86c3f8 Mon Sep 17 00:00:00 2001 From: Shohrat Date: Wed, 27 Dec 2023 17:33:49 +0500 Subject: [PATCH] rulon report --- .../gokbakja/pages/actions/rulon-report.htm | 97 +++++++++++-------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/themes/gokbakja/pages/actions/rulon-report.htm b/themes/gokbakja/pages/actions/rulon-report.htm index cd5dc17..48bce63 100644 --- a/themes/gokbakja/pages/actions/rulon-report.htm +++ b/themes/gokbakja/pages/actions/rulon-report.htm @@ -21,32 +21,23 @@ function onStart() { if($year){ - + $startDateOfYear = Carbon\Carbon::now()->startOfYear(); + $formattedStartDateYear = $startDateOfYear->format('Y-m-d'); $startDate = Carbon\Carbon::create($year, $this["month"], 1); - $endDate = $startDate->endOfMonth(); - $formattedStartDate = $startDate->format('Y-m-d'); - $formattedEndDate = $endDate->format('Y-m-d'); + + $endMonthDate = $startDate->endOfMonth(); + $formattedEndDate = $endMonthDate->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('gram', 'ASC') ->orderBy('width', 'ASC') ->distinct() ->get(); @@ -54,17 +45,23 @@ function onStart() { 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'); + ->with('product') + ->whereHas('product', function($qq) use($rulonProds, $x, $formattedStartDateYear, $formattedStartDate){ + $qq->where('gram', $rulonProds[$x]->gram) + ->where('width', $rulonProds[$x]->width) + ->whereBetween('date', [$formattedStartDateYear, $formattedStartDate]); + }) + ->sum('amount'); + //dd($rulonProds[$x]->width); + $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); + ->whereHas('product', function($qq) use($rulonProds, $x, $formattedStartDateYear, $formattedEndDate){ + $qq->where('gram', $rulonProds[$x]->gram) + ->where('width', $rulonProds[$x]->width) + ->whereBetween('date', [$formattedStartDateYear, $formattedEndDate]); }) ->sum('amount'); @@ -73,7 +70,9 @@ function onStart() { ->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); + $qq->where('gram', $rulonProds[$x]->gram) + ->where('width', $rulonProds[$x]->width) + ->whereBetween('date', [$formattedStartDate, $formattedEndDate]); }) ->sum('amount'); @@ -82,7 +81,9 @@ function onStart() { ->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); + $qq->where('gram', $rulonProds[$x]->gram) + ->where('width', $rulonProds[$x]->width) + ->whereBetween('date', [$formattedStartDate, $formattedEndDate]); }) ->sum('amount'); @@ -99,11 +100,14 @@ function onStart() { $this['reportDatas'] = $reportDatas; }else{ - $startDate = Carbon\Carbon::create($year, $this["month"], 1); - $endDate = $startDate->endOfMonth(); + $startDateOfYear = Carbon\Carbon::now()->startOfYear(); + $formattedStartDateYear = $startDateOfYear->format('Y-m-d'); + $startDate = Carbon\Carbon::create($currentDate->year, $this["month"], 1); $formattedStartDate = $startDate->format('Y-m-d'); - $formattedEndDate = $endDate->format('Y-m-d'); + + $endMonthDate = $startDate->endOfMonth(); + $formattedEndDate = $endMonthDate->format('Y-m-d'); $reportDatas = []; @@ -111,24 +115,33 @@ function onStart() { ->whereMonth('date', $this["month"]) ->whereYear('date', $currentDate->year) ->groupBy('gram')->groupBy('width') + ->orderBy('gram', 'ASC') ->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'); + ->with('product') + ->whereHas('product', function($qq) use($rulonProds, $x, $formattedStartDateYear, $formattedStartDate){ + $qq->where('gram', $rulonProds[$x]->gram) + ->where('width', $rulonProds[$x]->width) + ->whereBetween('date', [$formattedStartDateYear, $formattedStartDate]); + }) + ->sum('amount'); + //dd($rulonProds[$x]->width); + $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); + ->whereHas('product', function($qq) use($rulonProds, $x, $formattedStartDateYear, $formattedEndDate){ + $qq->where('gram', $rulonProds[$x]->gram) + ->where('width', $rulonProds[$x]->width) + ->whereBetween('date', [$formattedStartDateYear, $formattedEndDate]); }) ->sum('amount'); @@ -137,7 +150,9 @@ function onStart() { ->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); + $qq->where('gram', $rulonProds[$x]->gram) + ->where('width', $rulonProds[$x]->width) + ->whereBetween('date', [$formattedStartDate, $formattedEndDate]); }) ->sum('amount'); @@ -146,7 +161,9 @@ function onStart() { ->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); + $qq->where('gram', $rulonProds[$x]->gram) + ->where('width', $rulonProds[$x]->width) + ->whereBetween('date', [$formattedStartDate, $formattedEndDate]); }) ->sum('amount'); @@ -255,10 +272,10 @@ function onStart() { {{key + 1}} {{report.gram}} {{report.width}} - {{report.start_month}} - {{report.in}} - {{report.out}} - {{report.end_month}} + {{report.start_month|number_format(2)}} + {{report.in|number_format(2)}} + {{report.out == 0 ? '' : report.out|number_format(2)}} + {{report.end_month|number_format(2)}} {% endfor %}