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
@@ -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 }}