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') }}

-
+
{{ Form::label('type', 'Type:') }} {{ Form::text('type', null, ['class' => 'form-control']) }}

{{ $errors->first('type') }}

-
+
+ {{ Form::label('simbrief_type', 'SimBrief Type:') }} + {{ Form::text('simbrief_type', null, ['class' => 'form-control']) }} +

{{ $errors->first('simbrief_type') }}

+
+ +
{{ Form::label('name', 'Name:') }} {{ Form::text('name', null, ['class' => 'form-control']) }}

{{ $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
@@ -22,190 +11,228 @@
+
 Aircraft Details
- - + +
- - + +

-
 @lang('pireps.flightinformations') for - {{ $flight->airline->icao }} {{ $flight->flight_number }}
+
 @lang('pireps.flightinformations') For + {{ $flight->airline->icao }}{{ $flight->flight_number }} ({{ \App\Models\Enums\FlightType::label($flight->flight_type) }})
- - + +
- - + +
- +

- +
- +

- - + @if($flight->dpt_time) + + + @endif
- +
- +

- @foreach($subfleets as $subfleet) - @if($subfleet->id == $subflid) -
 Configuration And Load Information For - {{ $subfleet->name }} ; {{ $acdetails->registration }}
- {{-- Generate Load Figures --}} -
- {{-- Create and send some data to the $loadarray for MANUALRMK generation --}} - @php $loadarray = [] ; @endphp - @foreach($subfleet->fares as $fare) - @if($fare->capacity > 0) - @php - $randomloadperfare = ceil(($fare->capacity * (rand($loadmin, $loadmax))) /100); - $loadarray[] = ['SeatType' => $fare->code]; - $loadarray[] = ['SeatLoad' => $randomloadperfare]; - @endphp -
- - -
- @endif - @endforeach +
 Configuration And Load Information For + {{ $aircraft->registration }} ({{ $aircraft->subfleet->name }})
+
+ @php $loadarray = [] ; @endphp + {{-- Generate Load Figures For Pax Fares --}} + @foreach($aircraft->subfleet->fares->where('type', 0) as $fare) @php - $loadcollection = collect($loadarray) ; - $totalgenload = $loadcollection->sum('SeatLoad') ; + $randompaxperfare = floor(($fare->pivot->capacity * rand($loadmin, $loadmax)) /100); + $loadarray[] = ['LoadType' => $fare->code]; + $loadarray[] = ['LoadFigure' => $randompaxperfare]; @endphp -
- - @if($totalgenload > 0 && $totalgenload < 900) - -
-
-
- @if(setting('units.weight') === 'kg') - @php $estimatedpayload = number_format(round(($pax_weight * $totalgenload) / 2.2)) ; @endphp - @else - @php $estimatedpayload = number_format(round($pax_weight * $totalgenload)) ; @endphp - @endif - - -
+
+ + +
+ @endforeach + {{-- Calculate weights for Pax Loads Before moving to Cargo Fares --}} + @php + $paxcollection = collect($loadarray); + $tpaxfig = $paxcollection->sum('LoadFigure'); + + if(setting('units.weight') === 'kg') { + $tpaxload = round(($pax_weight * $tpaxfig) / 2.205); + $tbagload = round(($bag_weight * $tpaxfig) / 2.205); + } else { + $tpaxload = round($pax_weight * $tpaxfig); + $tbagload = round($bag_weight * $tpaxfig); + } + @endphp + {{-- Generate Load Figures For Cargo Fares --}} + @foreach($aircraft->subfleet->fares->where('type', 1) as $fare) + @php + $randomcargoperfare = ceil((($fare->pivot->capacity - $tbagload) * rand($loadmin, $loadmax)) /100); + $loadarray[] = ['LoadType' => $fare->code]; + $loadarray[] = ['CargoFigure' => $randomcargoperfare]; + @endphp +
+ + +
+ @endforeach + @php + $loadcollection = collect($loadarray); + $tcargoload = $loadcollection->sum('CargoFigure'); + $tpayload = $tpaxload + $tbagload + $tcargoload; + @endphp +
+ @if(isset($tpayload) && $tpayload > 0) + {{-- Display The Weights Generated --}} +
+
+ @if($tpaxload) +
+ + +
+
+ +
- - @elseif($totalgenload > 900) - - @endif - @endif - @endforeach + @if($tpaxload && $tcargoload) +
+ + +
+ @endif +
+ + +
+
+ @endif
-
- {{-- - Here we generate the MANUALRMK which is sent to SimBrief and displayed in the generated - ofp as Dispatch Remarks. $loadarray is created and filled with data during random load - generation, it holds each fare's code and the generated load then we are imploding that - array to get the fare codes and load counts. - Returned string will be like Load Distribution Y 132 C 12 F 4 - --}} - @if($totalgenload > 0) - @php - $loaddisttxt = "Load Distribution "; - $loaddist = implode(' ', array_map( - function ($v, $k) { + {{-- Prepare Form Fields For SimBrief --}} + + @if($tpaxfig) + + @elseif(!$tpaxfig && $tcargoload) + + @endif + @if($tcargoload) + + @endif + {{-- + Generate the MANUALRMK which is sent to SimBrief and displayed as Dispatch Remark. + $loadarray is created and filled with data during random load generation, + it holds each fare's code and the generated load. + Returned string will be "FixedText eachFareCode eachFareLoad" + Example Remark ; Load Distribution Y 132 J 12 F 4 C 2800 + --}} + @if(isset($tpayload) && $tpayload > 0) + @php + $loaddisttxt = "Load Distribution "; + $loaddist = implode(' ', array_map( + function ($v, $k) { if(is_array($v)){ return implode('&'.' '.':', $v); }else{ return $k.':'.$v; } - }, - $loadarray, array_keys($loadarray) - )); - @endphp - - @endif - - - - - - - - - - - - - - + }, + $loadarray, array_keys($loadarray) + )); + @endphp + + @endif + + + @if(setting('simbrief.callsign', false)) + + @endif + + + + + + + + + + + + {{-- For more info about form fields and their details check SimBrief Forum / API Support --}} +
 Planning Options
- +
@@ -255,8 +282,8 @@
-
 @lang('stisla.briefingoptions')
-
Cont Fuel:
+
 Briefing Options
+
Units: @@ -373,7 +400,7 @@ } depm = ("0" + depm).slice(-2); - dept = deph + depm; + dept = deph + ":" + depm; let dof = ("0" + d.getUTCDate()).slice(-2) + months[d.getUTCMonth()] + d.getUTCFullYear(); document.getElementById("dof").setAttribute('value', dof); @@ -397,20 +424,4 @@ document.getElementById("steh").setAttribute('value', rhours.toString()); // Sent to Simbrief document.getElementById("stem").setAttribute('value', rminutes.toString()); // Sent to Simbrief - @endsection