diff --git a/app/Cron/Nightly/RecalculateStats.php b/app/Cron/Nightly/RecalculateStats.php index cb761372..e4eb2320 100644 --- a/app/Cron/Nightly/RecalculateStats.php +++ b/app/Cron/Nightly/RecalculateStats.php @@ -4,6 +4,7 @@ namespace App\Cron\Nightly; use App\Contracts\Listener; use App\Events\CronNightly; +use App\Services\AircraftService; use App\Services\UserService; use Illuminate\Support\Facades\Log; @@ -12,11 +13,13 @@ use Illuminate\Support\Facades\Log; */ class RecalculateStats extends Listener { + private $aircraftSvc; private $userSvc; - public function __construct(UserService $userService) + public function __construct(AircraftService $aircraftSvc, UserService $userSvc) { - $this->userSvc = $userService; + $this->aircraftSvc = $aircraftSvc; + $this->userSvc = $userSvc; } /** @@ -29,10 +32,10 @@ class RecalculateStats extends Listener */ public function handle(CronNightly $event): void { - Log::info('Recalculating balances'); - + Log::info('Recalculating user stats'); $this->userSvc->recalculateAllUserStats(); - Log::info('Done recalculating stats'); + Log::info('Recalcuating aircraft status'); + $this->aircraftSvc->recalculateStats(); } } diff --git a/app/Services/AircraftService.php b/app/Services/AircraftService.php new file mode 100644 index 00000000..047c7757 --- /dev/null +++ b/app/Services/AircraftService.php @@ -0,0 +1,32 @@ +pirepRepo = $pirepRepo; + } + + /** + * Recalculate all aircraft stats and hours + */ + public function recalculateStats() + { + $allAircraft = Aircraft::all(); // TODO: Soft delete + foreach ($allAircraft as $aircraft) { + $pirep_time_total = Pirep::where('aircraft_id', $aircraft->id) + ->sum('flight_time'); + $aircraft->flight_time = $pirep_time_total; + $aircraft->save(); + } + } +} diff --git a/modules/Importer/Resources/views/step1-configure.blade.php b/modules/Importer/Resources/views/step1-configure.blade.php index 41f01ce3..226fda1d 100644 --- a/modules/Importer/Resources/views/step1-configure.blade.php +++ b/modules/Importer/Resources/views/step1-configure.blade.php @@ -24,7 +24,9 @@
Enter the database information for your legacy (v2 or v5) database
+