From e3bce1cd6926a362b25c922d9b2f887306508b9b Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 11 Jan 2018 22:00:39 -0600 Subject: [PATCH] Track hours on aircraft #73 --- .../2017_06_09_010621_create_aircrafts_table.php | 1 + app/Services/PIREPService.php | 4 ++++ resources/views/admin/aircraft/table.blade.php | 8 ++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php b/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php index a25e13cc..9e5b341c 100644 --- a/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php +++ b/app/Database/migrations/2017_06_09_010621_create_aircrafts_table.php @@ -19,6 +19,7 @@ class CreateAircraftsTable extends Migration $table->string('name', 50); $table->string('registration', 10)->nullable(); $table->string('tail_number', 10)->nullable(); + $table->unsignedBigInteger('flight_time')->default(0); $table->boolean('active')->default(true); $table->unsignedTinyInteger('state')->default(AircraftState::PARKED); $table->timestamps(); diff --git a/app/Services/PIREPService.php b/app/Services/PIREPService.php index fb0aaea1..e23e6191 100644 --- a/app/Services/PIREPService.php +++ b/app/Services/PIREPService.php @@ -268,6 +268,7 @@ class PIREPService extends BaseService Log::info('PIREP ' . $pirep->id . ' state change to ACCEPTED'); # Update the aircraft + $pirep->aircraft->flight_time += $pirep->flight_time; $pirep->aircraft->airport_id = $pirep->arr_airport_id; $pirep->aircraft->landing_time = $pirep->updated_at; $pirep->aircraft->save(); @@ -300,6 +301,9 @@ class PIREPService extends BaseService $pirep->save(); $pirep->refresh(); + $pirep->aircraft->flight_time -= $pirep->flight_time; + $pirep->aircraft->save(); + Log::info('PIREP ' . $pirep->id . ' state change to REJECTED'); event(new PirepRejected($pirep)); diff --git a/resources/views/admin/aircraft/table.blade.php b/resources/views/admin/aircraft/table.blade.php index 7904aaea..d838e224 100644 --- a/resources/views/admin/aircraft/table.blade.php +++ b/resources/views/admin/aircraft/table.blade.php @@ -2,8 +2,9 @@ Subfleet Name - ICAO + {{--ICAO--}} Registration + Hours Active @@ -21,7 +22,10 @@ {!! $ac->name !!} {!! $ac->icao !!} - {!! $ac->registration !!} + {{--{!! $ac->registration !!}--}} + + {!! Utils::minutesToTimeString($ac->flight_hours) !!} + @if($ac->active == GenericState::ACTIVE) {!! GenericState::label($ac->active); !!}