2020-03-23 21:31:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Frontend;
|
|
|
|
|
|
|
|
use App\Exceptions\AssetNotFound;
|
2021-01-18 04:59:32 +08:00
|
|
|
use App\Models\Aircraft;
|
2021-08-10 00:01:27 +08:00
|
|
|
use App\Models\Bid;
|
2021-03-22 23:40:21 +08:00
|
|
|
use App\Models\Enums\AircraftState;
|
|
|
|
use App\Models\Enums\AircraftStatus;
|
2021-03-03 01:29:04 +08:00
|
|
|
use App\Models\Enums\FareType;
|
2021-01-18 04:59:32 +08:00
|
|
|
use App\Models\Enums\FlightType;
|
2021-03-03 01:29:04 +08:00
|
|
|
use App\Models\Fare;
|
|
|
|
use App\Models\Flight;
|
2020-03-23 21:31:35 +08:00
|
|
|
use App\Models\SimBrief;
|
2021-03-03 01:29:04 +08:00
|
|
|
use App\Models\User;
|
2020-03-23 21:31:35 +08:00
|
|
|
use App\Repositories\FlightRepository;
|
2021-01-18 04:59:32 +08:00
|
|
|
use App\Services\FareService;
|
2021-08-10 00:01:27 +08:00
|
|
|
use App\Services\ModuleService;
|
2020-03-23 21:31:35 +08:00
|
|
|
use App\Services\SimBriefService;
|
2021-01-18 04:59:32 +08:00
|
|
|
use App\Services\UserService;
|
2020-03-23 21:31:35 +08:00
|
|
|
use Exception;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
class SimBriefController
|
|
|
|
{
|
2021-01-18 04:59:32 +08:00
|
|
|
private $fareSvc;
|
2020-03-23 21:31:35 +08:00
|
|
|
private $flightRepo;
|
2021-08-10 00:01:27 +08:00
|
|
|
private $moduleSvc;
|
2020-03-23 21:31:35 +08:00
|
|
|
private $simBriefSvc;
|
2021-01-18 04:59:32 +08:00
|
|
|
private $userSvc;
|
2020-03-23 21:31:35 +08:00
|
|
|
|
2021-01-18 04:59:32 +08:00
|
|
|
public function __construct(
|
|
|
|
FareService $fareSvc,
|
|
|
|
FlightRepository $flightRepo,
|
2021-08-10 00:01:27 +08:00
|
|
|
ModuleService $moduleSvc,
|
2021-01-18 04:59:32 +08:00
|
|
|
SimBriefService $simBriefSvc,
|
|
|
|
UserService $userSvc
|
|
|
|
) {
|
|
|
|
$this->fareSvc = $fareSvc;
|
2020-03-23 21:31:35 +08:00
|
|
|
$this->flightRepo = $flightRepo;
|
2021-08-10 00:01:27 +08:00
|
|
|
$this->moduleSvc = $moduleSvc;
|
2020-03-23 21:31:35 +08:00
|
|
|
$this->simBriefSvc = $simBriefSvc;
|
2021-01-18 04:59:32 +08:00
|
|
|
$this->userSvc = $userSvc;
|
2020-03-23 21:31:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the main OFP form
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function generate(Request $request)
|
|
|
|
{
|
2021-01-18 04:59:32 +08:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = Auth::user();
|
|
|
|
|
2020-03-23 21:31:35 +08:00
|
|
|
$flight_id = $request->input('flight_id');
|
2021-01-18 04:59:32 +08:00
|
|
|
$aircraft_id = $request->input('aircraft_id');
|
2021-03-03 01:29:04 +08:00
|
|
|
|
|
|
|
/** @var Flight $flight */
|
2021-11-17 05:26:43 +08:00
|
|
|
$flight = $this->flightRepo->with(['airline', 'arr_airport', 'dpt_airport', 'fares', 'subfleets'])->find($flight_id);
|
2021-01-18 04:59:32 +08:00
|
|
|
|
2020-03-23 21:31:35 +08:00
|
|
|
if (!$flight) {
|
|
|
|
flash()->error('Unknown flight');
|
|
|
|
return redirect(route('frontend.flights.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$apiKey = setting('simbrief.api_key');
|
|
|
|
if (empty($apiKey)) {
|
|
|
|
flash()->error('Invalid SimBrief API key!');
|
|
|
|
return redirect(route('frontend.flights.index'));
|
|
|
|
}
|
|
|
|
|
2021-06-09 23:38:14 +08:00
|
|
|
// Generate SimBrief Static ID
|
|
|
|
$static_id = $user->ident.'_'.$flight->id;
|
|
|
|
|
2021-02-24 22:32:29 +08:00
|
|
|
// No aircraft selected, show selection form
|
|
|
|
if (!$aircraft_id) {
|
2021-03-03 01:29:04 +08:00
|
|
|
|
2021-12-01 03:36:17 +08:00
|
|
|
// Get user's allowed subfleets and intersect it with flight subfleets
|
|
|
|
// so we will have a proper list which the user is allowed to fly
|
|
|
|
$user_subfleets = $this->userSvc->getAllowableSubfleets($user)->pluck('id')->toArray();
|
|
|
|
$flight_subfleets = $flight->subfleets->pluck('id')->toArray();
|
|
|
|
|
|
|
|
$subfleet_ids = filled($flight_subfleets) ? array_intersect($user_subfleets, $flight_subfleets) : $user_subfleets;
|
|
|
|
|
|
|
|
// Prepare variables for single aircraft query
|
|
|
|
$where = [];
|
|
|
|
$where['state'] = AircraftState::PARKED;
|
|
|
|
$where['status'] = AircraftStatus::ACTIVE;
|
2021-03-22 22:55:33 +08:00
|
|
|
|
|
|
|
if (setting('pireps.only_aircraft_at_dpt_airport')) {
|
2021-12-01 03:36:17 +08:00
|
|
|
$where['airport_id'] = $flight->dpt_airport_id;
|
2021-03-22 22:55:33 +08:00
|
|
|
}
|
|
|
|
|
2021-12-01 03:36:17 +08:00
|
|
|
$withCount = ['simbriefs' => function ($query) {
|
|
|
|
$query->whereNull('pirep_id');
|
|
|
|
}];
|
2021-08-10 00:01:27 +08:00
|
|
|
|
2021-12-01 03:36:17 +08:00
|
|
|
// Build proper aircraft collection considering all possible settings
|
|
|
|
// Flight subfleets, user subfleet restrictions, pirep restrictions, simbrief blocking etc
|
|
|
|
$aircraft = Aircraft::withCount($withCount)->where($where)
|
|
|
|
->when(setting('simbrief.block_aircraft'), function ($query) {
|
|
|
|
return $query->having('simbriefs_count', 0);
|
|
|
|
})->whereIn('subfleet_id', $subfleet_ids)
|
|
|
|
->orderby('icao')->orderby('registration')
|
|
|
|
->get();
|
2021-06-04 04:17:16 +08:00
|
|
|
|
2021-02-24 22:32:29 +08:00
|
|
|
return view('flights.simbrief_aircraft', [
|
|
|
|
'flight' => $flight,
|
2021-12-01 03:36:17 +08:00
|
|
|
'aircrafts' => $aircraft,
|
2021-02-24 22:32:29 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-01-18 10:52:22 +08:00
|
|
|
// Check if a Simbrief profile already exists
|
2020-03-23 21:31:35 +08:00
|
|
|
$simbrief = SimBrief::select('id')->where([
|
|
|
|
'flight_id' => $flight_id,
|
|
|
|
'user_id' => $user->id,
|
|
|
|
])->first();
|
|
|
|
|
|
|
|
if ($simbrief) {
|
|
|
|
return redirect(route('frontend.simbrief.briefing', [$simbrief->id]));
|
|
|
|
}
|
|
|
|
|
2021-02-24 22:32:29 +08:00
|
|
|
// SimBrief profile does not exists and everything else is ok
|
|
|
|
// Select aircraft which will be used for calculations and details
|
2021-03-03 01:29:04 +08:00
|
|
|
/** @var Aircraft $aircraft */
|
Eager loading update for frontend controllers and widgets (#1348)
* Update AirportController.php
Eager load `files`
* Update DashboardController.php
Eager load `journal` for user , and `aircraft, arr_airport, comments, dpt_airport` for last_pirep.
* Update FlightController.php
Eager load + `alt_airport, subfleets` (with their airlines) for flights and `current_airport` for user
(though current_airport can be removed and we can base the in blade checks on `$user->curr_airport_id` to reduce db reads and model loading)
* Update HomeController.php
Eager load `home_airport` for users
* Update PirepController.php
Eager load `airline, aircraft, fares, transactions, dpt_airport, arr_airport, comments, simbrief, user with rank` for pirep details
* Update ProfileController.php
Eager load `airline, awards, current_airport, fields.field, home_airport, last_pirep, rank` for user
* Update UserController.php
Eager load `airline, current_airport, fields.field, home_airport, rank` for users and count `awards`
* Update AirportController.php
* Update DashboardController.php
* Update PirepController.php
* Update ProfileController.php
* Update LatestNews.php
Eager load `user` for news
* Update LatestPilots.php
Eager load `home_airport` for latest users
* StyleFix 1
* StlyeFix 1.5
* Update SimBriefController.php
Eager load airline with flight
* Update SimBriefController.php
* Update SimBriefController.php
2021-11-09 22:51:02 +08:00
|
|
|
$aircraft = Aircraft::with(['airline'])->where('id', $aircraft_id)->first();
|
2021-01-18 04:59:32 +08:00
|
|
|
|
2021-03-03 01:29:04 +08:00
|
|
|
// Figure out the proper fares to use for this flight/aircraft
|
|
|
|
$all_fares = $this->fareSvc->getFareWithOverrides($aircraft->subfleet->fares, $flight->fares);
|
|
|
|
|
|
|
|
// TODO: Reconcile the fares for this aircraft w/ proper for the flight/subfleet
|
|
|
|
|
2021-02-24 22:32:29 +08:00
|
|
|
// Get passenger and baggage weights with failsafe defaults
|
2021-01-18 04:59:32 +08:00
|
|
|
if ($flight->flight_type === FlightType::CHARTER_PAX_ONLY) {
|
2021-02-24 22:32:29 +08:00
|
|
|
$pax_weight = setting('simbrief.charter_pax_weight', 168);
|
|
|
|
$bag_weight = setting('simbrief.charter_baggage_weight', 28);
|
2021-01-18 04:59:32 +08:00
|
|
|
} else {
|
2021-02-24 22:32:29 +08:00
|
|
|
$pax_weight = setting('simbrief.noncharter_pax_weight', 185);
|
|
|
|
$bag_weight = setting('simbrief.noncharter_baggage_weight', 35);
|
2021-01-18 10:52:22 +08:00
|
|
|
}
|
|
|
|
|
2021-02-24 22:32:29 +08:00
|
|
|
// Get the load factors with failsafe for loadmax if nothing is defined
|
2021-01-22 22:02:15 +08:00
|
|
|
$lfactor = $flight->load_factor ?? setting('flights.default_load_factor');
|
|
|
|
$lfactorv = $flight->load_factor_variance ?? setting('flights.load_factor_variance');
|
|
|
|
|
|
|
|
$loadmin = $lfactor - $lfactorv;
|
|
|
|
$loadmin = $loadmin < 0 ? 0 : $loadmin;
|
|
|
|
|
|
|
|
$loadmax = $lfactor + $lfactorv;
|
|
|
|
$loadmax = $loadmax > 100 ? 100 : $loadmax;
|
2021-02-18 07:54:18 +08:00
|
|
|
|
2021-02-02 04:27:22 +08:00
|
|
|
if ($loadmax === 0) {
|
|
|
|
$loadmax = 100;
|
|
|
|
}
|
2021-01-22 22:02:15 +08:00
|
|
|
|
2021-03-03 01:29:04 +08:00
|
|
|
// Load fares for passengers
|
|
|
|
|
|
|
|
$loaddist = []; // The load distribution string
|
|
|
|
|
|
|
|
$pax_load_sheet = [];
|
|
|
|
$tpaxfig = 0;
|
|
|
|
|
|
|
|
/** @var Fare $fare */
|
|
|
|
foreach ($all_fares as $fare) {
|
|
|
|
if ($fare->type !== FareType::PASSENGER || empty($fare->capacity)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$count = floor(($fare->capacity * rand($loadmin, $loadmax)) / 100);
|
|
|
|
$tpaxfig += $count;
|
|
|
|
$pax_load_sheet[] = [
|
|
|
|
'id' => $fare->id,
|
|
|
|
'code' => $fare->code,
|
|
|
|
'name' => $fare->name,
|
|
|
|
'type' => $fare->type,
|
|
|
|
'capacity' => (int) $fare->capacity,
|
|
|
|
'count' => $count,
|
|
|
|
];
|
|
|
|
|
|
|
|
$loaddist[] = $fare->code.' '.$count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate total weights
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load up fares for cargo
|
|
|
|
|
|
|
|
$tcargoload = 0;
|
|
|
|
$cargo_load_sheet = [];
|
|
|
|
foreach ($all_fares as $fare) {
|
|
|
|
if ($fare->type !== FareType::CARGO || empty($fare->capacity)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$count = ceil((($fare->capacity - $tbagload) * rand($loadmin, $loadmax)) / 100);
|
|
|
|
$tcargoload += $count;
|
|
|
|
$cargo_load_sheet[] = [
|
|
|
|
'id' => $fare->id,
|
|
|
|
'code' => $fare->code,
|
|
|
|
'name' => $fare->name,
|
|
|
|
'type' => $fare->type,
|
|
|
|
'capacity' => $fare->capacity,
|
|
|
|
'count' => $count,
|
|
|
|
];
|
|
|
|
|
|
|
|
$loaddist[] = $fare->code.' '.$count;
|
|
|
|
}
|
|
|
|
|
|
|
|
$tpayload = $tpaxload + $tbagload + $tcargoload;
|
|
|
|
|
|
|
|
$request->session()->put('simbrief_fares', array_merge($pax_load_sheet, $cargo_load_sheet));
|
|
|
|
|
2021-01-18 10:52:22 +08:00
|
|
|
// Show the main simbrief form
|
2020-03-23 21:31:35 +08:00
|
|
|
return view('flights.simbrief_form', [
|
2021-08-10 00:01:27 +08:00
|
|
|
'user' => $user,
|
2021-03-03 01:29:04 +08:00
|
|
|
'flight' => $flight,
|
|
|
|
'aircraft' => $aircraft,
|
|
|
|
'pax_weight' => $pax_weight,
|
|
|
|
'bag_weight' => $bag_weight,
|
|
|
|
'loadmin' => $loadmin,
|
|
|
|
'loadmax' => $loadmax,
|
|
|
|
'pax_load_sheet' => $pax_load_sheet,
|
|
|
|
'cargo_load_sheet' => $cargo_load_sheet,
|
|
|
|
'tpaxfig' => $tpaxfig,
|
|
|
|
'tpaxload' => $tpaxload,
|
|
|
|
'tbagload' => $tbagload,
|
|
|
|
'tpayload' => $tpayload,
|
|
|
|
'tcargoload' => $tcargoload,
|
|
|
|
'loaddist' => implode(' ', $loaddist),
|
2021-06-09 23:38:14 +08:00
|
|
|
'static_id' => $static_id,
|
2020-03-23 21:31:35 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the briefing
|
|
|
|
*
|
|
|
|
* @param string $id The OFP ID
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function briefing($id)
|
|
|
|
{
|
2021-08-10 00:01:27 +08:00
|
|
|
/** @var User $user */
|
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
/** @var SimBrief $simbrief */
|
Eager loading update for frontend controllers and widgets (#1348)
* Update AirportController.php
Eager load `files`
* Update DashboardController.php
Eager load `journal` for user , and `aircraft, arr_airport, comments, dpt_airport` for last_pirep.
* Update FlightController.php
Eager load + `alt_airport, subfleets` (with their airlines) for flights and `current_airport` for user
(though current_airport can be removed and we can base the in blade checks on `$user->curr_airport_id` to reduce db reads and model loading)
* Update HomeController.php
Eager load `home_airport` for users
* Update PirepController.php
Eager load `airline, aircraft, fares, transactions, dpt_airport, arr_airport, comments, simbrief, user with rank` for pirep details
* Update ProfileController.php
Eager load `airline, awards, current_airport, fields.field, home_airport, last_pirep, rank` for user
* Update UserController.php
Eager load `airline, current_airport, fields.field, home_airport, rank` for users and count `awards`
* Update AirportController.php
* Update DashboardController.php
* Update PirepController.php
* Update ProfileController.php
* Update LatestNews.php
Eager load `user` for news
* Update LatestPilots.php
Eager load `home_airport` for latest users
* StyleFix 1
* StlyeFix 1.5
* Update SimBriefController.php
Eager load airline with flight
* Update SimBriefController.php
* Update SimBriefController.php
2021-11-09 22:51:02 +08:00
|
|
|
$simbrief = SimBrief::with(['flight.airline', 'pirep.airline'])->find($id);
|
2020-03-23 21:31:35 +08:00
|
|
|
if (!$simbrief) {
|
|
|
|
flash()->error('SimBrief briefing not found');
|
|
|
|
return redirect(route('frontend.flights.index'));
|
|
|
|
}
|
|
|
|
|
2021-01-18 04:59:32 +08:00
|
|
|
$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);
|
|
|
|
|
2021-08-10 00:01:27 +08:00
|
|
|
// See if a bid exists for this flight
|
|
|
|
$bid = Bid::where(['user_id' => $user->id, 'flight_id' => $simbrief->flight_id])->first();
|
|
|
|
|
2020-03-23 21:31:35 +08:00
|
|
|
return view('flights.simbrief_briefing', [
|
2021-08-10 00:01:27 +08:00
|
|
|
'user' => $user,
|
|
|
|
'simbrief' => $simbrief,
|
|
|
|
'wakecat' => $wakecat,
|
|
|
|
'equipment' => $equipment,
|
|
|
|
'transponder' => $transponder,
|
|
|
|
'bid' => $bid,
|
|
|
|
'flight' => $simbrief->flight,
|
|
|
|
'acars_plugin' => $this->moduleSvc->isModuleActive('VMSAcars'),
|
2020-03-23 21:31:35 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-01-16 06:36:46 +08:00
|
|
|
/**
|
|
|
|
* Remove the flight_id from the SimBrief Briefing (to a create a new one)
|
|
|
|
* or if no pirep_id is attached to the briefing delete it completely
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
2021-01-18 10:52:22 +08:00
|
|
|
* @throws \Exception
|
|
|
|
*
|
2021-01-16 06:36:46 +08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
2021-01-18 10:52:22 +08:00
|
|
|
public function generate_new(Request $request)
|
2021-01-16 06:36:46 +08:00
|
|
|
{
|
2021-01-18 10:52:22 +08:00
|
|
|
$simbrief = SimBrief::find($request->id);
|
|
|
|
|
|
|
|
// Invalid Simbrief ID/profile, go back to the main flight index
|
|
|
|
if (!$simbrief) {
|
|
|
|
return redirect(route('frontend.flights.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup the current Simbrief entry and redirect to the new generation form
|
|
|
|
// If there isn't a PIREP ID, then delete the entry, otherwise, remove the flight
|
|
|
|
$flight_id = $simbrief->flight_id;
|
|
|
|
if (!$simbrief->pirep_id) {
|
|
|
|
$simbrief->delete();
|
|
|
|
} else {
|
|
|
|
$simbrief->flight_id = null;
|
|
|
|
$simbrief->save();
|
2021-01-16 06:36:46 +08:00
|
|
|
}
|
|
|
|
|
2021-01-18 10:52:22 +08:00
|
|
|
return redirect(route('frontend.simbrief.generate').'?flight_id='.$flight_id);
|
2021-01-16 06:36:46 +08:00
|
|
|
}
|
|
|
|
|
2020-03-23 21:31:35 +08:00
|
|
|
/**
|
|
|
|
* Create a prefile of this PIREP with a given OFP. Then redirect the
|
|
|
|
* user to the newly prefiled PIREP
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function prefile(Request $request)
|
|
|
|
{
|
|
|
|
$sb = SimBrief::find($request->id);
|
|
|
|
if (!$sb) {
|
|
|
|
return redirect(route('frontend.flights.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect to the prefile page, with the flight_id and a simbrief_id
|
|
|
|
$rd = route('frontend.pireps.create').'?sb_id='.$sb->id;
|
|
|
|
return redirect($rd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancel the SimBrief request
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function cancel(Request $request)
|
|
|
|
{
|
|
|
|
$sb = SimBrief::find($request->id);
|
|
|
|
if (!$sb) {
|
|
|
|
$sb->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect(route('frontend.simbrief.prefile', ['id' => $request->id]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the OFP was generated. Pass in two items, the flight_id and ofp_id
|
2021-03-03 01:29:04 +08:00
|
|
|
* This does the actual "attachment" of the Simbrief to the flight
|
2020-03-23 21:31:35 +08:00
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function check_ofp(Request $request)
|
|
|
|
{
|
2021-03-03 01:29:04 +08:00
|
|
|
/** @var User $user */
|
|
|
|
$user = Auth::user();
|
2020-03-23 21:31:35 +08:00
|
|
|
$ofp_id = $request->input('ofp_id');
|
|
|
|
$flight_id = $request->input('flight_id');
|
2021-03-03 01:29:04 +08:00
|
|
|
$aircraft_id = $request->input('aircraft_id');
|
|
|
|
$fares = $request->session()->get('simbrief_fares', []);
|
2020-03-23 21:31:35 +08:00
|
|
|
|
2021-03-03 01:29:04 +08:00
|
|
|
$simbrief = $this->simBriefSvc->downloadOfp($user->id, $ofp_id, $flight_id, $aircraft_id, $fares);
|
2020-03-23 21:31:35 +08:00
|
|
|
if ($simbrief === null) {
|
|
|
|
$error = new AssetNotFound(new Exception('Simbrief OFP not found'));
|
|
|
|
return $error->getResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'id' => $simbrief->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-06-09 23:38:14 +08:00
|
|
|
/**
|
|
|
|
* Get the latest generated OFP. Pass in two additional items, the Simbrief userid and static_id
|
|
|
|
* This will get the latest edited/regenerated of from Simbrief and update our records
|
|
|
|
* We do not need to send the fares again, so used an empty array
|
|
|
|
*/
|
|
|
|
public function update_ofp(Request $request)
|
|
|
|
{
|
|
|
|
/** @var User $user */
|
|
|
|
$user = Auth::user();
|
|
|
|
$ofp_id = $request->input('ofp_id');
|
|
|
|
$flight_id = $request->input('flight_id');
|
|
|
|
$aircraft_id = $request->input('aircraft_id');
|
|
|
|
$sb_userid = $request->input('sb_userid');
|
|
|
|
$sb_static_id = $request->input('sb_static_id');
|
|
|
|
$fares = [];
|
|
|
|
|
|
|
|
$simbrief = $this->simBriefSvc->downloadOfp($user->id, $ofp_id, $flight_id, $aircraft_id, $fares, $sb_userid, $sb_static_id);
|
|
|
|
if ($simbrief === null) {
|
|
|
|
$error = new AssetNotFound(new Exception('Simbrief OFP not found'));
|
|
|
|
return $error->getResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect(route('frontend.simbrief.briefing', [$ofp_id]));
|
|
|
|
}
|
|
|
|
|
2020-03-23 21:31:35 +08:00
|
|
|
/**
|
|
|
|
* Generate the API code
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @throws \Exception
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function api_code(Request $request)
|
|
|
|
{
|
|
|
|
$apiKey = setting('simbrief.api_key', null);
|
|
|
|
if (empty($apiKey)) {
|
|
|
|
flash()->error('Invalid SimBrief API key!');
|
|
|
|
return redirect(route('frontend.flights.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$api_code = md5($apiKey.$request->input('api_req'));
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'api_code' => $api_code,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|