From 1ce40b0eb0a7f1b4c083a20741bdfde80cbc91ac Mon Sep 17 00:00:00 2001 From: Russ Long Date: Sat, 8 Feb 2020 15:02:53 -0500 Subject: [PATCH] fix winner tabultation --- app/Console/Commands/TabulateWinners.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/TabulateWinners.php b/app/Console/Commands/TabulateWinners.php index 514e622..23ed444 100644 --- a/app/Console/Commands/TabulateWinners.php +++ b/app/Console/Commands/TabulateWinners.php @@ -58,7 +58,20 @@ class TabulateWinners extends Command ->first(); return $mainWinnerQuery->vehicle; } - + function categoryWinner($category) + { + $categoryWinnerQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id') + ->groupBy('vehicles.id') + ->selectRaw('*, sum(vehicle_scores.overall_score) as totalscore') + ->whereNotIn('vehicle_scores.vehicle', function ($query) { + $query->select('vehicle')->from('car_show_winners'); + }) + ->where('vehicles.doNotJudge', '=', '0') + ->where('vehicles.type', '=', "$category") + ->orderBy('totalscore', 'desc') + ->first(); + return $categoryWinnerQuery->vehicle; + } function pcWinner() @@ -238,7 +251,7 @@ class TabulateWinners extends Command 'place' => 'first' ], [ - 'vehicle' => mainWinner() + 'vehicle' => categoryWinner($category) ] ); }