diff --git a/app/Cron/Nightly/PilotLeave.php b/app/Cron/Nightly/PilotLeave.php index 7417b4b1..8128c69c 100644 --- a/app/Cron/Nightly/PilotLeave.php +++ b/app/Cron/Nightly/PilotLeave.php @@ -42,6 +42,7 @@ class PilotLeave extends Listener ->whereDate('updated_at', '<', $date); foreach($users as $user) { + Log::info('Setting user '.$user->ident.' to ON LEAVE status'); $this->userSvc->setStatusOnLeave($user); } } diff --git a/app/Cron/Nightly/SetActiveFlights.php b/app/Cron/Nightly/SetActiveFlights.php index e63906d9..c3387844 100644 --- a/app/Cron/Nightly/SetActiveFlights.php +++ b/app/Cron/Nightly/SetActiveFlights.php @@ -7,6 +7,8 @@ use App\Interfaces\Listener; use App\Models\Enums\Days; use App\Models\Flight; use Carbon\Carbon; +use Illuminate\Support\Facades\Log; +use Log; /** * Figure out what flights need to be active for today @@ -39,11 +41,19 @@ class SetActiveFlights extends Listener */ foreach($flights as $flight) { + if (!$flight->active) { + continue; + } + // dates aren't set, so just save if there were any changes above // and move onto the next one if ($flight->start_date === null || $flight->end_date === null) { if ($flight->days > 0) { - $flight->active = Days::isToday($flight->days); + $visible = Days::isToday($flight->days); + if($flight->visible !== $visible) { + Log::info('Marking flight '.$flight->ident.' to '.($visible ? 'visible' : 'invisible')); + $flight->visible = $visible; + } } $flight->save(); @@ -55,13 +65,17 @@ class SetActiveFlights extends Listener // Start/end date is set, so make sure today is valid for it to be alive // and then make sure if days of the week are specified, check that too if ($today->gte($flight->start_date) && $today->lte($flight->end_date)) { - if ($flight->days > 0) { - $flight->active = Days::isToday($flight->days); + if ($flight->days === null || $flight->days > 0) { + $visible = Days::isToday($flight->days); + if($flight->visible !== $visible) { + Log::info('Toggling flight '.$flight->ident.' to '.($visible?'visible':'invisible')); + $flight->visible = true; + } } else { - $flight->active = true; + $flight->visible = true; } } else { - $flight->active = false; + $flight->visible = false; } $flight->save(); diff --git a/app/Database/migrations/2017_06_11_135707_create_airports_table.php b/app/Database/migrations/2017_06_11_135707_create_airports_table.php index 6670f4ac..cfa96a2d 100644 --- a/app/Database/migrations/2017_06_11_135707_create_airports_table.php +++ b/app/Database/migrations/2017_06_11_135707_create_airports_table.php @@ -16,12 +16,12 @@ class CreateAirportsTable extends Migration $table->string('country', 64)->nullable(); $table->string('timezone', 64)->nullable(); $table->boolean('hub')->default(false); + $table->float('lat', 7, 4)->nullable()->default(0.0); + $table->float('lon', 7, 4)->nullable()->default(0.0); $table->unsignedDecimal('ground_handling_cost')->nullable()->default(0); $table->unsignedDecimal('fuel_100ll_cost')->nullable()->default(0); $table->unsignedDecimal('fuel_jeta_cost')->nullable()->default(0); $table->unsignedDecimal('fuel_mogas_cost')->nullable()->default(0); - $table->float('lat', 7, 4)->nullable()->default(0.0); - $table->float('lon', 7, 4)->nullable()->default(0.0); $table->index('icao'); $table->index('iata'); diff --git a/app/Database/migrations/2017_06_17_214650_create_flight_tables.php b/app/Database/migrations/2017_06_17_214650_create_flight_tables.php index 1b5f3564..a3f8b7b1 100644 --- a/app/Database/migrations/2017_06_17_214650_create_flight_tables.php +++ b/app/Database/migrations/2017_06_17_214650_create_flight_tables.php @@ -36,7 +36,7 @@ class CreateFlightTables extends Migration $table->date('end_date')->nullable(); $table->boolean('has_bid')->default(false); $table->boolean('active')->default(true); - $table->boolean('flight_active')->default(true); // used by the cron + $table->boolean('visible')->default(true); // used by the cron $table->timestamps(); $table->primary('id'); diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index da461527..556fc30a 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -118,7 +118,6 @@ class AircraftController extends Controller if (empty($aircraft)) { Flash::error('Aircraft not found'); - return redirect(route('admin.aircraft.index')); } diff --git a/app/Models/Flight.php b/app/Models/Flight.php index 91699388..46bcaa3b 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -64,6 +64,7 @@ class Flight extends Model 'end_date', 'has_bid', 'active', + 'visible', ]; protected $casts = [ @@ -75,8 +76,9 @@ class Flight extends Model 'start_date' => 'date', 'end_date' => 'date', 'has_bid' => 'boolean', + 'route_leg' => 'integer', 'active' => 'boolean', - 'route_leg' => 'integer' + 'visible' => 'boolean', ]; public static $rules = [