From e3b4a0ed2eca30a80c20bbb1991039529c9fa50d Mon Sep 17 00:00:00 2001 From: "B.Fatih KOZ" <74361521+FatihKoz@users.noreply.github.com> Date: Wed, 24 Feb 2021 17:32:29 +0300 Subject: [PATCH] SimBrief integration enhancements (#1045) * SimBrief Integration Update * Added SimBrief Type field to subfleets, can be used to assign simbrief airframes to subfleets and fix non existing or wrong types. If not used simbrief form will use aircraft's icao type code * Added Passenger and Baggage weights to settings * Added setting for using PhpVms Pilot/User Ident as simbrief atc callsign * SimBrief form code cleaned up a bit and improved. Now form supports both cargo and passenger fares to be used at the same time. Generated passenger baggage weight will be reduced from aircraft's cargo capacity and remaining amount will be used for random cargo generation. Also multiple cargo fares or any mix is possible now (like only cargo, only passenger, multiple cargo and passenger fares) * StyleFix (SimBrief Controller) * Fix Callsign Setting Check * Code Cleanup Reduced loops and removed if's in loops, getting fares from aircraft instead of flight/subfleets. No need to go through getReconciledFaresForFlight anymore. Aircraft provides all fare info we need. Removed unnecessary html elements, added some comments. * Update Simbrief Controller Fixed setting checks. Removed non used $subfleet and from main form and $aircraft from aircraft selection form blade. Added/fixed comments. * StyleFix for Controller --- ...1_02_23_205630_add_sbtype_to_subfleets.php | 20 ++ app/Database/seeds/settings.yml | 35 ++ .../Frontend/SimBriefController.php | 53 ++-- app/Models/Subfleet.php | 2 + .../views/admin/subfleets/fields.blade.php | 10 +- .../default/flights/simbrief_form.blade.php | 299 +++++++++--------- 6 files changed, 246 insertions(+), 173 deletions(-) create mode 100644 app/Database/migrations/2021_02_23_205630_add_sbtype_to_subfleets.php diff --git a/app/Database/migrations/2021_02_23_205630_add_sbtype_to_subfleets.php b/app/Database/migrations/2021_02_23_205630_add_sbtype_to_subfleets.php new file mode 100644 index 00000000..42c6c975 --- /dev/null +++ b/app/Database/migrations/2021_02_23_205630_add_sbtype_to_subfleets.php @@ -0,0 +1,20 @@ +string('simbrief_type', 20) + ->nullable() + ->after('type'); + }); + } +} diff --git a/app/Database/seeds/settings.yml b/app/Database/seeds/settings.yml index b08241d6..f7b6489a 100644 --- a/app/Database/seeds/settings.yml +++ b/app/Database/seeds/settings.yml @@ -200,6 +200,41 @@ options: '' type: number description: 'Days after how long to remove unused briefs' +- key: simbrief.noncharter_pax_weight + name: 'SimBrief Passenger Weight for Non-Charter (Scheduled etc) Flights' + group: simbrief + value: 185 + options: '' + type: number + description: 'Passenger weight for Non-Charter flights excluding baggage (lbs)' +- key: simbrief.noncharter_baggage_weight + name: 'SimBrief Baggage Weight per Pax for Non-Charter (Scheduled etc) Flights' + group: simbrief + value: 35 + options: '' + type: number + description: 'Passenger baggage weight for Non-Charter flights (lbs)' +- key: simbrief.charter_pax_weight + name: 'SimBrief Passenger Weight for Charter Flights' + group: simbrief + value: 168 + options: '' + type: number + description: 'Passenger weight for Charter flights excluding baggage (lbs)' +- key: simbrief.charter_baggage_weight + name: 'SimBrief Baggage Weight per Pax for Charter Flights' + group: simbrief + value: 28 + options: '' + type: number + description: 'Passenger baggage weight for Charter flights (lbs)' +- key: simbrief.callsign + name: 'SimBrief ATC Callsign' + group: simbrief + value: false + options: '' + type: boolean + description: 'Use pilot ident as SimBrief ATC Callsign' - key: pireps.duplicate_check_time name: 'PIREP duplicate time check' group: pireps diff --git a/app/Http/Controllers/Frontend/SimBriefController.php b/app/Http/Controllers/Frontend/SimBriefController.php index f087f065..c7e93c4e 100644 --- a/app/Http/Controllers/Frontend/SimBriefController.php +++ b/app/Http/Controllers/Frontend/SimBriefController.php @@ -50,7 +50,7 @@ class SimBriefController $flight_id = $request->input('flight_id'); $aircraft_id = $request->input('aircraft_id'); $flight = $this->flightRepo->with(['subfleets'])->find($flight_id); - $flight = $this->fareSvc->getReconciledFaresForFlight($flight); + // $flight = $this->fareSvc->getReconciledFaresForFlight($flight); if (!$flight) { flash()->error('Unknown flight'); @@ -63,6 +63,21 @@ class SimBriefController return redirect(route('frontend.flights.index')); } + // If no subfleets defined for flight get them from user + if ($flight->subfleets->count() > 0) { + $subfleets = $flight->subfleets; + } else { + $subfleets = $this->userSvc->getAllowableSubfleets($user); + } + + // No aircraft selected, show selection form + if (!$aircraft_id) { + return view('flights.simbrief_aircraft', [ + 'flight' => $flight, + 'subfleets' => $subfleets, + ]); + } + // Check if a Simbrief profile already exists $simbrief = SimBrief::select('id')->where([ 'flight_id' => $flight_id, @@ -73,34 +88,20 @@ class SimBriefController return redirect(route('frontend.simbrief.briefing', [$simbrief->id])); } - // Simbrief Profile doesn't exist; prompt the user to create a new one - $aircraft = Aircraft::select('registration', 'name', 'icao', 'iata', 'subfleet_id') - ->where('id', $aircraft_id) - ->get(); - - if ($flight->subfleets->count() > 0) { - $subfleets = $flight->subfleets; - } else { - $subfleets = $this->userSvc->getAllowableSubfleets($user); - } + // SimBrief profile does not exists and everything else is ok + // Select aircraft which will be used for calculations and details + $aircraft = Aircraft::where('id', $aircraft_id)->first(); + // Get passenger and baggage weights with failsafe defaults if ($flight->flight_type === FlightType::CHARTER_PAX_ONLY) { - $pax_weight = 197; + $pax_weight = setting('simbrief.charter_pax_weight', 168); + $bag_weight = setting('simbrief.charter_baggage_weight', 28); } else { - $pax_weight = 208; + $pax_weight = setting('simbrief.noncharter_pax_weight', 185); + $bag_weight = setting('simbrief.noncharter_baggage_weight', 35); } - // No aircraft selected, show that form - if (!$aircraft_id) { - return view('flights.simbrief_aircraft', [ - 'flight' => $flight, - 'aircraft' => $aircraft, - 'subfleets' => $subfleets, - 'pax_weight' => $pax_weight, - ]); - } - - // Get the correct load factors + // Get the load factors with failsafe for loadmax if nothing is defined $lfactor = $flight->load_factor ?? setting('flights.default_load_factor'); $lfactorv = $flight->load_factor_variance ?? setting('flights.load_factor_variance'); @@ -110,8 +111,6 @@ class SimBriefController $loadmax = $lfactor + $lfactorv; $loadmax = $loadmax > 100 ? 100 : $loadmax; - // Failsafe for admins not defining load values for their flights - // and also leave the general settings empty, set loadmax to 100 if ($loadmax === 0) { $loadmax = 100; } @@ -120,8 +119,8 @@ class SimBriefController return view('flights.simbrief_form', [ 'flight' => $flight, 'aircraft' => $aircraft, - 'subfleets' => $subfleets, 'pax_weight' => $pax_weight, + 'bag_weight' => $bag_weight, 'loadmin' => $loadmin, 'loadmax' => $loadmax, ]); diff --git a/app/Models/Subfleet.php b/app/Models/Subfleet.php index 0bad6db1..0f10ad7f 100644 --- a/app/Models/Subfleet.php +++ b/app/Models/Subfleet.php @@ -10,6 +10,7 @@ use App\Models\Traits\FilesTrait; /** * @property int id * @property string type + * @property string simbrief_type * @property string name * @property int airline_id * @property int hub_id @@ -29,6 +30,7 @@ class Subfleet extends Model 'airline_id', 'hub_id', 'type', + 'simbrief_type', 'name', 'fuel_type', 'cost_block_hour', diff --git a/resources/views/admin/subfleets/fields.blade.php b/resources/views/admin/subfleets/fields.blade.php index 69ac6c4d..3880b49c 100644 --- a/resources/views/admin/subfleets/fields.blade.php +++ b/resources/views/admin/subfleets/fields.blade.php @@ -24,13 +24,19 @@
{{ $errors->first('hub_id') }}
-{{ $errors->first('type') }}
{{ $errors->first('simbrief_type') }}
+{{ $errors->first('name') }}
diff --git a/resources/views/layouts/default/flights/simbrief_form.blade.php b/resources/views/layouts/default/flights/simbrief_form.blade.php index 2c110fba..5f7337c4 100644 --- a/resources/views/layouts/default/flights/simbrief_form.blade.php +++ b/resources/views/layouts/default/flights/simbrief_form.blade.php @@ -2,17 +2,6 @@ @section('title', 'SimBrief Flight Planning') @section('content') - @foreach($aircraft as $acdetails) - @php - $simbrieftype = $acdetails->icao ; - $subflid = $acdetails->subfleet_id ; - if($acdetails->icao === 'A20N') { $simbrieftype = 'A320'; } - if($acdetails->icao === 'A21N') { $simbrieftype = 'A321'; } - if($acdetails->icao === 'B77L') { $simbrieftype = 'B77F'; } - if($acdetails->icao === 'B773') { $simbrieftype = 'B77W'; } - if($acdetails->icao === 'E35L') { $simbrieftype = 'E135'; } - @endphp - @endforeach