From 050952e1a9beebc1172eb7fa663c896ed1984901 Mon Sep 17 00:00:00 2001
From: Russ Long <rl@tfmm.co>
Date: Wed, 8 Jun 2022 20:21:59 -0400
Subject: [PATCH] Add new judging categories

---
 app/Console/Commands/TabulateWinners.php | 78 ++++++++++++++++++++----
 1 file changed, 66 insertions(+), 12 deletions(-)

diff --git a/app/Console/Commands/TabulateWinners.php b/app/Console/Commands/TabulateWinners.php
index 10aff41..bf8861d 100644
--- a/app/Console/Commands/TabulateWinners.php
+++ b/app/Console/Commands/TabulateWinners.php
@@ -134,38 +134,71 @@ class TabulateWinners extends Command
             return $zeroTo432ndQuery->vehicle;
         }
 
-        function fortyFourToCurrentWinner()
+        function fortyFourToNinetySevenWinner()
         {
-            $fortyFourToCurrentQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
+            $fortyFourToNinetySevenQuery = 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.year', '>=', 1944)
-                //->where('vehicles.year', '<=', 1959)
+                ->where('vehicles.year', '<=', 1997)
                 ->where('vehicles.doNotJudge', '=', 0)
                 ->orderBy('totalscore','desc')
                 ->first();
-            return $fortyFourToCurrentQuery->vehicle;
+            return $fortyFourToNinetySevenQuery->vehicle;
         }
 
-        function fortyFourToCurrent2ndWinner()
+        function fortyFourToNinetySeven2ndWinner()
         {
-            $fortyFourToCurrent2ndQuery = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
+            $fortyFourToNinetySeven2ndQuery = 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.year', '>=', 1944)
-                //->where('vehicles.year', '<=', 1959)
+                ->where('vehicles.year', '<=', 1997)
                 ->where('vehicles.doNotJudge', '=', 0)
                 ->orderBy('totalscore','desc')
                 ->first();
-            return $fortyFourToCurrent2ndQuery->vehicle;
+            return $fortyFourToNinetySeven2ndQuery->vehicle;
         }
 
+        function NinetyEightToCurrentWinner()
+        {
+            $NinetyEightToCurrentQuery = 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.year', '>=', 1998)
+                //->where('vehicles.year', '<=', 1997)
+                ->where('vehicles.doNotJudge', '=', 0)
+                ->orderBy('totalscore','desc')
+                ->first();
+            return $NinetyEightToCurrentQuery->vehicle;
+        }
+
+        function NinetyEightToCurrent2ndWinner()
+        {
+            $NinetyEightToCurrent2ndQuery = 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.year', '>=', 1998)
+                //->where('vehicles.year', '<=', 1997)
+                ->where('vehicles.doNotJudge', '=', 0)
+                ->orderBy('totalscore','desc')
+                ->first();
+            return $NinetyEightToCurrent2ndQuery->vehicle;
+        }
+
+
         //Insert Best In Show Winner
         CarShowWinner::updateOrCreate(
             [
@@ -230,14 +263,14 @@ class TabulateWinners extends Command
                     'vehicle' => zeroTo432ndWinner()
                 ]
             );
-        //1944-Current
+        //1944-1997
         CarShowWinner::updateOrCreate(
                 [
                     'category' => '18',
                     'place' => 'first'
                 ],
                 [
-                    'vehicle' => fortyFourToCurrentWinner()
+                    'vehicle' => fortyFourToNinetySevenWinner()
                 ]
             );
 
@@ -247,8 +280,29 @@ class TabulateWinners extends Command
                     'place' => 'second'
                 ],
                 [
-                    'vehicle' => fortyFourToCurrent2ndWinner()
+                    'vehicle' => fortyFourToNinetySeven2ndWinner()
                 ]
-            );       
+            );  
+            
+        //1998-Current
+        CarShowWinner::updateOrCreate(
+            [
+                'category' => '19',
+                'place' => 'first'
+            ],
+            [
+                'vehicle' => NinetyEightToCurrentWinner()
+            ]
+        );
+
+        CarShowWinner::updateOrCreate(
+            [
+                'category' => '19',
+                'place' => 'second'
+            ],
+            [
+                'vehicle' => NinetyEightToCurrent2ndWinner()
+            ]
+        );  
     }
 }