diff --git a/app/Http/Controllers/Frontend/SimBriefController.php b/app/Http/Controllers/Frontend/SimBriefController.php index 580d29e8..bd51c000 100644 --- a/app/Http/Controllers/Frontend/SimBriefController.php +++ b/app/Http/Controllers/Frontend/SimBriefController.php @@ -3,22 +3,34 @@ namespace App\Http\Controllers\Frontend; use App\Exceptions\AssetNotFound; +use App\Models\Aircraft; +use App\Models\Enums\FlightType; use App\Models\SimBrief; use App\Repositories\FlightRepository; +use App\Services\FareService; use App\Services\SimBriefService; +use App\Services\UserService; use Exception; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class SimBriefController { + private $fareSvc; private $flightRepo; private $simBriefSvc; + private $userSvc; - public function __construct(FlightRepository $flightRepo, SimBriefService $simBriefSvc) - { + public function __construct( + FareService $fareSvc, + FlightRepository $flightRepo, + SimBriefService $simBriefSvc, + UserService $userSvc + ) { + $this->fareSvc = $fareSvc; $this->flightRepo = $flightRepo; $this->simBriefSvc = $simBriefSvc; + $this->userSvc = $userSvc; } /** @@ -32,20 +44,29 @@ class SimBriefController */ public function generate(Request $request) { + /** @var \App\Models\User $user */ + $user = Auth::user(); + $flight_id = $request->input('flight_id'); - $flight = $this->flightRepo->find($flight_id); + $aircraft_id = $request->input('aircraft_id'); + $flight = $this->flightRepo->with(['subfleets'])->find($flight_id); + $flight = $this->fareSvc->getReconciledFaresForFlight($flight); + if (!$flight) { flash()->error('Unknown flight'); return redirect(route('frontend.flights.index')); } + if (!$aircraft_id) { + flash()->error('Aircraft not selected ! Please select an Aircraft to Proceed ...'); + } + $apiKey = setting('simbrief.api_key'); if (empty($apiKey)) { flash()->error('Invalid SimBrief API key!'); return redirect(route('frontend.flights.index')); } - $user = Auth::user(); $simbrief = SimBrief::select('id')->where([ 'flight_id' => $flight_id, 'user_id' => $user->id, @@ -55,8 +76,27 @@ class SimBriefController return redirect(route('frontend.simbrief.briefing', [$simbrief->id])); } + $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); + } + + if ($flight->flight_type === FlightType::CHARTER_PAX_ONLY) { + $pax_weight = 197; + } else { + $pax_weight = 208; + } + return view('flights.simbrief_form', [ - 'flight' => $flight, + 'flight' => $flight, + 'aircraft' => $aircraft, + 'subfleets' => $subfleets, + 'pax_weight' => $pax_weight, // TODO: Replace with a setting ]); } @@ -75,8 +115,18 @@ class SimBriefController return redirect(route('frontend.flights.index')); } + $str = $simbrief->xml->aircraft->equip; + $wc = stripos($str, '-'); + $tr = stripos($str, '/'); + $wakecat = substr($str, 0, $wc); + $equipment = substr($str, $wc + 1, $tr - 2); + $transponder = substr($str, $tr + 1); + return view('flights.simbrief_briefing', [ - 'simbrief' => $simbrief, + 'simbrief' => $simbrief, + 'wakecat' => $wakecat, + 'equipment' => $equipment, + 'transponder' => $transponder, ]); } diff --git a/app/Providers/DirectiveServiceProvider.php b/app/Providers/DirectiveServiceProvider.php index 3f7697f7..188c8201 100644 --- a/app/Providers/DirectiveServiceProvider.php +++ b/app/Providers/DirectiveServiceProvider.php @@ -19,5 +19,9 @@ class DirectiveServiceProvider extends ServiceProvider Blade::directive('minutestohours', function ($expr) { return ""; }); + + Blade::directive('secstohhmm', function ($expr) { + return ""; + }); } } diff --git a/app/helpers.php b/app/helpers.php index d0de5b95..030538f2 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -355,6 +355,20 @@ if (!function_exists('show_datetime_format')) { } } +if (!function_exists('secstohhmm')) { + /** + * Convert seconds to hhmm format + * + * @param $seconds + */ + function secstohhmm($seconds) + { + $seconds = round($seconds); + $hhmm = sprintf('%02d%02d', ($seconds / 3600), ($seconds / 60 % 60)); + echo $hhmm; + } +} + if (!function_exists('_fmt')) { /** * Replace strings diff --git a/resources/views/layouts/default/flights/simbrief_briefing.blade.php b/resources/views/layouts/default/flights/simbrief_briefing.blade.php index 81dbd541..ebc3f415 100644 --- a/resources/views/layouts/default/flights/simbrief_briefing.blade.php +++ b/resources/views/layouts/default/flights/simbrief_briefing.blade.php @@ -15,9 +15,9 @@ @endif
- Generate New OFP + Generate New OFP
@@ -134,24 +134,30 @@

Departure METAR

-

{{ $simbrief->xml->weather->orig_metar }}

+

{{ $simbrief->xml->weather->orig_metar }}

Departure TAF

-

{{ $simbrief->xml->weather->orig_taf }}

+

{{ $simbrief->xml->weather->orig_taf }}


Destination METAR

-

{{ $simbrief->xml->weather->dest_metar }}

+

{{ $simbrief->xml->weather->dest_metar }}

Destination TAF

-

{{ $simbrief->xml->weather->dest_taf }}

+

{{ $simbrief->xml->weather->dest_taf }}

-
-

Alternate METAR

-

{{ $simbrief->xml->weather->altn_metar }}

+
+

Alternate METAR

+

{{ $simbrief->xml->weather->altn_metar }}

Alternate TAF

-

{{ $simbrief->xml->weather->altn_taf }}

+

{{ $simbrief->xml->weather->altn_taf }}

@@ -181,66 +187,55 @@
- +
 Prefile ATC Flight Plan
- @php - $str = $simbrief->xml->aircraft->equip ; - $wc = stripos($str,"-"); - $tr = stripos($str,"/"); - $wakecat = substr($str,0,$wc); - $equipment = substr($str,$wc+1,$tr-2); - $transponder = substr($str,$tr+1); - function secstohhmm($seconds) { - $seconds = round($seconds); - $hhmm = sprintf('%02d%02d', ($seconds/ 3600),($seconds/ 60 % 60)); - echo $hhmm ; - } - @endphp -
- - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
- - - - - -
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + + + +
+
+ +
-
- View Route At SkyVector -
-
- - +
 OFP diff --git a/resources/views/layouts/default/flights/simbrief_form.blade.php b/resources/views/layouts/default/flights/simbrief_form.blade.php index 25fc0e96..372b61f9 100644 --- a/resources/views/layouts/default/flights/simbrief_form.blade.php +++ b/resources/views/layouts/default/flights/simbrief_form.blade.php @@ -1,269 +1,451 @@ @extends('app') -@section('title', 'Generate OFP') +@section('title', 'SimBrief Flight Planning') @section('content') -
+ + @if(empty(request()->get('aircraft_id')))
-

Create Flight Briefing

-
-
-
-
-  @lang('pireps.flightinformations') -
-
-
-
- - +

Aircraft Selection

+
+
+ +
+
+ +
+ +
+ @else + + @php + $loadmin = $flight->load_factor - $flight->load_factor_variance; + $loadmax = $flight->load_factor + $flight->load_factor_variance; + if($loadmin < 1) { $loadmin = 1; } + if($loadmax > 100) { $loadmax = 100; } + @endphp + + @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 + + +
+
+
+

Create Flight Briefing Package

+
+
+
+
+
 Aircraft Details
+
+
+ + + +
+
+ + + +
+
+
-
- - +
+
 @lang('pireps.flightinformations') for + {{ $flight->airline->icao }} {{ $flight->flight_number }}
+
+
+ + + +
+
+ + + +
+
+ + +
+
+
+
+
+ + +
+
+ + +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
-
- - +
+ @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 + @php + $loadcollection = collect($loadarray) ; + $totalgenload = $loadcollection->sum('SeatLoad') ; + @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 + + +
+
+ + @elseif($totalgenload > 900) + + + @endif + @endif + @endforeach +
+
+
+ {{-- + 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) { + if(is_array($v)){ + return implode('&'.' '.':', $v); + }else{ + return $k.':'.$v; + } + }, + $loadarray, array_keys($loadarray) + )); + @endphp + + @endif + + + + + + + + + + + + + + +
+
+
+
 Planning Options
+ + + + + + + + + + + + + + + + + + + + + +
Cont Fuel: + +
Reserve Fuel: + +
SID/STAR Type: + +
Plan Stepclimbs: + +
ETOPS Planning: + +
+
+
+
+
 @lang('stisla.briefingoptions')
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Units: + +
Detailed Navlog: + +
Runway Analysis: + +
Include NOTAMS: + +
FIR NOTAMS: + +
Flight Maps: + +
+
+
+
+
+
+ +
+
-
-
-
-  Briefing Options -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Units:
Cont Fuel:
Reserve Fuel:
Detailed Navlog: -
ETOPS Planning:
Plan Stepclimbs: -
Runway Analysis: -
Include NOTAMS: -
FIR NOTAMS:
Flight Maps:
-
-
-
- - - - - - - - - {{-- - --}} - -
-
-
-
-
-
- -
-
- + + @endif @endsection @section('scripts') + + + + @endsection